akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, ll> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 2147483647;
const ll LINF = 1LL<<61;
const ll MOD = 998244353;

struct Trie
{
    Trie *next[26];
    Trie *par;
    int cnt; //終端の個数
    int c; //ノード上の文字
    Trie(int c, Trie* p) : c(c), par(p), cnt(0)
    {
        fill(next, next+26, (Trie *) 0);
    }
    Trie() : Trie(0, NULL) {}
    void insert(const char *s)
    {
        if(*s == '\0')
        {
            this -> cnt += 1;
            return;
        }
        if(this -> next[*s-'a'] == NULL)
            this -> next[*s-'a'] = new Trie(*s-'a', this);
        this -> next[*s-'a'] -> insert(s+1);
    }
    int find(const char *s)
    {
        if(*s == '\0') return this -> cnt;
        if(this -> next[*s-'a'] == NULL)
            return 0;
        return this -> next[*s-'a'] -> find(s+1);
    }
};

ll ans = 0;
struct node
{
    int n; //部分木に存在する終端の個数
    vector<int> cnt; //部分木に'a'+iを含む文字列はcnt[i]個存在する
    node() : n(0), cnt(26) {}
    node& operator+=(const node &rh)
    {
        n += rh.n;
        rep(i,26) cnt[i] += rh.cnt[i];
        return *this;
    }
};
node dfs(Trie* t) 
{
    node v;
    vector<ll> chars(26); //子の終端の文字と個数
    rep(i,26)
    {
        if(t -> next[i] == NULL) continue;
        if(t -> next[i] -> cnt > 0)
        {
            chars[i] = t -> next[i] -> cnt;
        }
        v += dfs(t -> next[i]);
    }
    if(t -> par == NULL)
    {
        rep(i,26) ans += chars[i] * (chars[i] - 1) / 2;
    }
    rep(i,26)
    {
        ans += chars[i] * (v.cnt[i] - chars[i]);
    }
    //このノードの情報を含める
    v.n += (t -> cnt);
    v.cnt[t -> c] = v.n;
    return v;
}

int main()
{
    Trie t;
    int n;
    cin >> n;
    rep(i,n)
    {
        string s;
        cin >> s;
        reverse(s.begin(), s.end());
        t.insert(s.c_str());
    }
    dfs(&t);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 659740
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> diff(n);
	for(int i = 0; i < n; ++i) {
		int v;
		cin >> v;
		diff[i] = v;
	}
	
	for(int i = 0; i < n; ++i) {
		int c;
		cin >> c;
		diff[i] -= c;
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if( diff[i] > 0 ) ans += diff[i];
	}
	
	cout << ans << endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int X, A;
    cin >> X >> A;
    if(X < A){
        cout << 0 << endl;
    }else{
        cout << 10 << endl;
    }


    return 0;
}



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

#define int long long
int dp[6000 + 10][12000 + 20];

int32_t main() {
	int n, MOD;
	cin >> n >> MOD;
	dp[0][3 * n] = 1;
	for (int i = 0; i < 3 * n; i++)
		for (int j = -3 * n; j <= 3 * n; j++) {
			dp[i + 1][j + 1 + 3 * n] = (dp[i + 1][j + 1 + 3 * n] + dp[i][j + 3 * n]) % MOD;
			dp[i + 2][j - 1 + 3 * n] = (dp[i + 2][j - 1 + 3 * n] + dp[i][j + 3 * n] * (i + 1) % MOD) % MOD;
			dp[i + 3][j + 0 + 3 * n] = (dp[i + 3][j + 0 + 3 * n] + dp[i][j + 3 * n] * (i + 1) * (i + 2) % MOD) % MOD;
		}
	int ans = 0;
	for (int i = 0; i <= 3 * n; i++)
		(ans += dp[3 * n][i + 3 * n]) %= MOD;
	cout << ans;
}


Measured memory_bytes: 567224
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		String S = sc.next();
		String[] a = S.split("/");
		int year = Integer.valueOf(a[0]);
		int month = Integer.valueOf(a[1]);
		//int day = Integer.valueOf(a[2]);
		if (year >= 2019 && month >= 5)
			System.out.println("TBD");
		else
			System.out.println("Heisei");

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int main() {
  ios_base::sync_with_stdio(0);
 ll int t, i, j, k, p, q, r, x, y, u, v, n, m;
    t=1;
    //cin>>t;
    while(t--){
        cin>>n>>x>>k;
       double p=(n*k)/(x*1.0);        
        ll int pp=ceil(p);
        double an=pp/(k*1.0);
        int ans=ceil(an);
        cout<<k*ans;

    }



  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;

  return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m) {
  int i, u, v;
  while (m--) {
    cin >> u >> v;
    g[u - 1].pb(v - 1);
    g[v - 1].pb(u - 1);
  }
}

void dfs(int u, int par) {
  for (int v : g[u]) {
    if (v == par) continue;
    dfs(v, u);
  }
}





Measured memory_bytes: 10952
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
	int N, M;
	cin >> N >> M;

	vector<int> divs;
	for(int i=1; i*i<=M; i++){
		if(M%i==0){
			divs.push_back(i);
			if(M/i!=i) divs.push_back(M/i);
		}
	}

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

	int lb = *lower_bound(divs.begin(), divs.end(), N);
	cout << M/lb << endl;

	return 0;
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void){
	int n = 0;
	int count = 0;
	int train_stack[100];
	int out_train[100];
	int train_n;

	while (scanf("%d", &train_n) != EOF){
		if (train_n != 0){
			train_stack[count] = train_n;
			count++;
		}
		else {
			if (count != 0){
				count--;
				out_train[n] = train_stack[count];
				printf("%d\n", out_train[n]);
				n++;
			}
		}
	}

	return (0);
}

Measured memory_bytes: 600
from itertools import combinations


n = int(input())

s = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    a = input()
    if a[0] in s.keys():
        s[a[0]] += 1

c = list(combinations(s.keys(), 3))
ans = 0
for i in c:
    ans += s[i[0]] * s[i[1]] * s[i[2]]

print(ans)


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

using namespace std;

int main(int, char**)
{
	unsigned int n, a, b;
	cin >> n >> a >> b;

	unsigned int x;
	if (n > a + b) x = 0;
	else x = a + b - n;
	cout << min(a, b) << " " << x << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		
		HashMap<String, Integer> map = new HashMap<>();
		
		int n = sc.nextInt();
		for (int i=0; i<n; i++) {
			String s = sc.next();
			map.put(s, map.getOrDefault(s,0)+1);
		}
		
		int m = sc.nextInt();
		for (int i=0; i<m; i++) {
			String s = sc.next();
			map.put(s, map.getOrDefault(s,0)-1);
		}
		
		map = map.entrySet().stream()
				.sorted(Map.Entry.<String,Integer>comparingByValue().reversed())
				.collect(Collectors.
						toMap(Map.Entry::getKey,Map.Entry::getValue,(e1, e2)->e1,LinkedHashMap::new));
		
		System.out.println(Math.max(map.values().stream().findFirst().get(), 0));
		
	}
}

Measured memory_bytes: 27732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> bit(50,0);
    vector<ll> bitk(50,0);
    vector<ll> delta0(50,0);
    vector<ll> delta1(50,0);
    for(int i = 0; i < n; i++){
        ll t = a[i];
        for(int j = 0; j < 50; j++){
            if(t&1){bit[j]++;}
            t = t>>1;
        }
    }
    for(int j = 0; j < 50; j++){
        if(k&1){bitk[j]++;}
        k = k>>1;
    }
    for(int i = 0; i < 50; i++){
        delta0[i] = (bit[i])*(1LL<<i);
        delta1[i] = (n-bit[i])*(1LL<<i);
        if(bit[i] < n-bit[i]){
            bit[i] = 1;
        }else{
            bit[i] = 0;
        }
    }
    reverse(all(bit));
    reverse(all(bitk));
    reverse(all(delta0));
    reverse(all(delta1));
    vector<vector<ll>> dp(51,vector<ll>(2,-1));
    dp[0][0] = 0;
    for(int i = 0; i < 50; i++){
        if(dp[i][1] != -1){
            dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(delta0[i], delta1[i]));
        }
        if(dp[i][0] != -1){
            if(bitk[i]){
                dp[i+1][1] = max(dp[i+1][1],dp[i][0] + delta0[i]);
            }
        }
        if(dp[i][0] != -1){
            if(bitk[i]){
                dp[i+1][0] = max(dp[i+1][0], dp[i][0]+delta1[i]);
            }else{
                dp[i+1][0] = max(dp[i+1][0], dp[i][0]+delta0[i]);
            }
        }

    }
    cout << max(dp[50][0], dp[50][1]) << endl;

    return 0;
}


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

int main() {
	int k;
	string S;
	cin >> k >> S;
	if(S.size()<=k){
		cout << S << endl;
	}
	else{
		for(int i=0;i<k;i++){
			cout << S.at(i);
		}
		cout << "..." << endl;
	}
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <string>
#include <math.h>
#include <map>
#include <climits>
#include <iomanip>


#define forn(i, n) for (int i = 0; i < int(n); i++)

#define ll long long

using namespace std;

void A();
void B();
void C();
void D();
void E();
void F();

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	E();


}

void A() {
	string s;
	cin >> s;

	cout << (s == "ABC" ? "ARC" : "ABC") << '\n';

}

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

	set<int> have;

	forn(k, K) {

		int d;
		cin >> d;

		forn(dd, d) {

			int sn;
			cin >> sn;
			have.insert(sn);

		}
	}

	int c = 0;
	forn(i, N) {
		if (have.find(i+1) == have.end()) c++;
	}

	cout << c;

}

void C() {
	
	int N, M;
	cin >> N >> M;

	vector<int> h;
	forn(i, N) {
		int hh;
		cin >> hh;
		h.push_back(hh);
	}

	vector<vector<int>> adj(N);

	forn(m, M) {

		int a, b;
		cin >> a >> b;

		adj[a - 1].push_back(b - 1);
		adj[b - 1].push_back(a - 1);

	}
	
	int r = 0;
	forn(i, N) {

		bool good = true;
		for (int ind : adj[i]) {
			if (h[ind] >= h[i]) good = false;
		}

		if (good) r++;

	}

	cout << r;

}

void D() {
	int X;
	cin >> X;

	vector<ll> dp(1000);

	ll A, B;

	for (int i = -126; i < 126; i++) {

		if (dp[i + 130] == 0) {
			dp[i + 130] = pow(i, 5);
		}
		A = dp[i + 130];

		for (int j = -126; j < 126; j++) {

			if (dp[j + 130] == 0) {
				dp[j + 130] = pow(j, 5);
			}
			B = dp[j + 130];
			
			if (A - B == X) {
				cout << i << " " << j;
				return;
			}


		}
	}
}

void E() {
	int N;
	cin >> N;

	vector<int> e;
	map<int, int> m;
	//map<int, int> m2;
	forn(i, N) {
		int ee;
		cin >> ee;
		e.push_back(ee);
		int dif1 = (i + 1) - ee;
		//int dif2 = (i + 1) + ee;
		m[dif1]++;
		//m2[dif2]++;

	}


	ll count = 0;
	forn(i, N) {

		int ee = e[i];
		//int dif1 = (i + 1) - ee;
		int dif2 = (i + 1) + ee;

		//count += m2[dif1];
		count += m[dif2];

	}

	cout << count;



}

void F() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {

		int N;
		cin >> N;


		int result = 0;

		cout << "Case #" << t << ": ";

		cout << result << endl;

	}
}



Measured memory_bytes: 21020
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std; 
#define MAXN 50
#define MAXM 50
int main(int argc,char const* argv[])
{
  int ans=0;
  string s;
  cin >> s;
  for(int i=0;i<3;i++)
    {
      if(s[i]=='1')ans++;
    }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<int>>g(n+1, vector<int>(n+1, 0)), gr(n+1, vector<int>(n+1, 0));
  for(int i=0; i<m; i++){
    int l, r;
    cin >> l >> r;
    g[l][r]++;
  }
  for(int i=1; i<=n; i++)for(int j=1; j<=n; j++){
    gr[i][j]=gr[i][j-1]+g[i][j];
  }
  for(int i=0; i<q; i++){
    int ret=0;
    int p, q;
    cin >> p >> q;
   	for(int j=p; j<=q; j++){
      ret+=(gr[j][q]-gr[j][p-1]);
    }
    cout << ret << endl;
  }
  return 0;
}

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ret = []
    for i in range(N - 1):
        tmp = 1
        for j in range(i, N - 1):
            if tmp > S[j]:
                tmp = ((tmp - S[j] - 1) // F[j] + 1) * F[j] + S[j] + C[j]
            else:
                tmp = S[j] + C[j]
        ret.append(tmp)
    ret.append(0)
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5e5 + 15;
int n, m, k, a[N];
vector <int> g[N];
int l[N], r[N], d[N];
int root;

inline bool lie(int l, int x, int r) {
	return l <= x && x <= r;
}

inline void no() {
	cout << "No" << endl;
	exit(0);
}

void dfs(int v, int p = -1) {
	l[v] = -inf, r[v] = inf;
	for(int to : g[v]) {
		if(to != p) {
			d[to] = d[v] + 1;
			dfs(to, v);
			Max(l[v], l[to] - 1);
			Min(r[v], r[to] + 1);
		}
	}
	if(a[v] != -1) {
		Max(l[v], a[v]);
		Min(r[v], a[v]);
	}
}

void build(int v, int p = -1) {
	if(!lie(l[v], a[v], r[v]) || (d[v] ^ abs(a[root] - a[v])) % 2 || l[v] > r[v])
		no();
	for(int to : g[v]) {
		if(to != p) {
			if(lie(l[to], a[v] - 1, r[to]))
				a[to] = a[v] - 1;
			else if(lie(l[to], a[v] + 1, r[to]))
				a[to] = a[v] + 1;
			else
				no();
			build(to, v);
		}
	}
}

main() {
	memset(a, -1, sizeof(a));
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n;
	for(int i = 1; i < n; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	cin >> k;
	while(k--) {
		int v;
		cin >> v;
		cin >> a[v];
	}
	for(int i = 1; i <= n; ++i) {
		if(a[i] != -1) {
			dfs(root = i);
			build(root);
			break;
		}
	}
	cout << "Yes" << endl;
	for(int i = 1; i <= n; ++i)
		cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 28288
import math

n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

def binary_search(a, k):
    ng = 0 # left
    ok = max(a) # right
    while (ok - ng > 1):
        mid = (ng + ok) // 2
        if sum([math.ceil(a[i]/mid)-1 for i in range(n)]) <= k:
            ok = mid
        else:
            ng = mid
    return ok

print(binary_search(a, k))

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
  vector<char> c(9);
  rep(i,9) cin >> c[i];
  cout << c[0] << c[4] << c[8] << endl;

  return 0;
}


Measured memory_bytes: 256
extern crate proconio;
use proconio::input;

fn main() {
    input! {
        a: i32,
        mut b: i32,
        mut c: i32,
        k: i32,
    }
    let mut cnt = 0;
    while a >= b {
        b = b * 2;
        cnt += 1;
    }
    while b >= c {
        c = c * 2;
        cnt += 1;
    }
    println!("{}", if cnt <= k { "Yes" } else { "No" });
}


Measured memory_bytes: 2160
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,r;

int main(){
	cin>>h>>r;
	if(-h==r) cout<<0<<endl;
	else if(h+r>0) cout<<1<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 3088
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = "APPROVED"
    for a in A:
        if a % 2 == 0:
            if not (a % 3 == 0 or a % 5 == 0):
                ans = "DENIED"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
d={(i,j):(i**2+j**2)**(0.5) for i in range(1,151) for j in range(1,151) if i<j}
r=sorted(d.items(),key=lambda x:x[1])

while 1:
    h,w=map(int,input().split())
    if not h and not w:break
    idx=[i for (i,j) in enumerate(r) if j[0]==(h,w)][0]
    H,W=r[idx+1][0]
    print(H,W)



Measured memory_bytes: 8020
import math
n = int(input())
a = list(map(int, input().split()))
a.sort()

maxNum = a[-1]
del a[-1]

median = maxNum / 2

# print(a)
# print('max:', maxNum)
# print('median:', median)

# Find the value closest to median
l = 0
r = n-2
# m = (l + r) // 2

while l <= r:
    m = (l + r) // 2
    # print(l, r, m)

    if a[m] == median:
        break
    if a[m] > median:
        r = m - 1
    else:
        l = m + 1

def fixBorder(median, idx):
    if idx < n-2 and abs(median - a[idx + 1]) < abs(median - a[idx]):
        return idx+1
    if idx > 0 and abs(median - a[idx - 1]) < abs(median - a[idx]):
        return idx-1
    else:
        return idx

# print('before:', m, a[m])
m = fixBorder(median, m)

# print('fixed:', m, a[m])
print(maxNum, a[m])

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

ll n;
ll a[1000000];
ll w[1000000];

ll merge_and_count(ll l, ll r)
{
    if (l + 1 >= r)
        return 0;
    if (l + 2 == r)
    {
        if (a[l] < a[l + 1])
            return 0;
        swap(a[l], a[l + 1]);
        return 1;
    }
    ll m = (l + r) / 2;
    ll cl = merge_and_count(l, m);
    ll cr = merge_and_count(m, r);
    ll c = 0;
    ll i = l, j = m;
    ll k = l;
    while (i < m && j < r)
    {
        if (a[i] <= a[j])
            w[k++] = a[i++];
        else
        {
            w[k++] = a[j++];
            c += m - i;
        }
    }
    while (i < m)
        w[k++] = a[i++];
    while (j < r)
        w[k++] = a[j++];
    assert(k == r);
    copy(w + l, w + r, a + l);
    return cl + cr + c;
}

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    cout << merge_and_count(0, n) << endl;
    return 0;
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
	int N;
	while(cin >> N){
		vector< pair<int, int> > x(N);
		for(int i=0;i<N;i++){
			cin >> x[i].first;
			--x[i].first;
			x[i].second= i;
		}
		sort(x.begin(), x.end());
		queue<int> useF, useE;
		bool ok = true;
		for(int i=0;i<x.size();i++){
			for(int j=0;j<x[i].second;++j){
				useF.push(x[i].second);
			}
		}
		vector<int> A(N*N);
		int checkIdx = 0;
		for(int i=0;i<A.size();i++){
			if(checkIdx < N && i == x[checkIdx].first){
				if(!useF.empty() && useF.front() == x[checkIdx].second){
					ok = false;
					break;
				}
				A[i] = x[checkIdx].second;
				for(int j=A[i]+1;j<N;j++) useE.push(A[i]);
				++checkIdx;
			} else if(!useF.empty()){
				A[i] = useF.front(); useF.pop();
			} else if(!useE.empty()){
				A[i] = useE.front(); useE.pop();
			} else {
				ok = false;
				break;
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
		if(ok){
			cout << A[0]+1;
			for(int i=1;i<A.size();++i) cout << " " << A[i]+1;
			cout << endl;
		}
	}
}



Measured memory_bytes: 2944
import Data.List (intercalate)
showAsHMS :: Int -> String
showAsHMS n = let
    (m',s) = n `divMod` 60
    (h,m) = m' `divMod` 60
    in
        intercalate ":" $ map show [h,m,s]

main = getLine >>= putStrLn . showAsHMS . read

Measured memory_bytes: 3620
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 1000000007
ll n,t,arr[sz],brr[sz],crr[sz];
vector<ll>v;
char c[sz];
int main()
{
    t=1;
   // scanf("%lld",&t);
    while(t--)
    {
     scanf("%s",&c);
     printf("%s",c);
     if(c[strlen(c)-1]=='s')
        printf("es\n");
     else
        printf("s\n");
    }
    return 0;
}


Measured memory_bytes: 3832
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

typedef struct _dice {
    int surface[6];
    int init_surface[6];

    void input(){
        for(int i=0;i<6;i++) {
            cin >> init_surface[i];
        }
        init();
    }

    void init(){
        for(int i=0;i<6;i++) {
            surface[i] = init_surface[i];
        }
    }

    void roll_N(){
        int tmp = surface[5];
        surface[5] = surface[4];
        surface[4] = surface[0];
        surface[0] = surface[1];
        surface[1] = tmp;
    }

    void roll_E(){
        int tmp = surface[5];
        surface[5] = surface[2];
        surface[2] = surface[0];
        surface[0] = surface[3];
        surface[3] = tmp;
    }

    void roll_S(){
        int tmp = surface[5];
        surface[5] = surface[1];
        surface[1] = surface[0];
        surface[0] = surface[4];
        surface[4] = tmp;
    }

    void roll_W(){
        int tmp = surface[5];
        surface[5] = surface[3];
        surface[3] = surface[0];
        surface[0] = surface[2];
        surface[2] = tmp;
    }

    void turn_right(){
        int tmp = surface[1];
        surface[1] = surface[3];
        surface[3] = surface[4];
        surface[4] = surface[2];
        surface[2] = tmp;
    }

} Dice;

bool dice_compare(Dice d1, Dice d2);

int main(){
    Dice d1,d2;
    d1.input();
    d2.input();
    if(dice_compare(d1,d2)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

bool dice_compare(Dice d1, Dice d2){
    int num = -1;
    bool result = true;
    for(int i=0;i<6;i++){
        if(d1.init_surface[0] == d2.init_surface[i]){
            d1.init();
            d2.init();
            num = i;
            if(num == 5){
                d2.roll_N();
                d2.roll_N();
            } else if(num == 1){
                d2.roll_N();
            } else if(num == 4){
                d2.roll_S();
            } else if(num == 2){
                d2.roll_W();
            } else if(num == 3){
                d2.roll_E();
            }

            for(int i=0;i<3;i++){
                if(d1.surface[1] == d2.surface[1]){
                    break;
                } else {
                    d2.turn_right();
                }
            }

            for(int i=0;i<6;i++){
                if(d1.surface[i] != d2.surface[i]){
                    result = false;
                    break;
                }
            }
            if(result) return result;
            else result = true;
        }
    }
    return false;
}


Measured memory_bytes: 3108
n, k = map(int, input().split())
s = input()
if s[k-1] == 'A':
  print(s[:k-1] + 'a' + s[k:])
elif s[k-1] == 'B':
  print(s[:k-1] + 'b' + s[k:])
else :
  print(s[:k-1] + 'c' + s[k:])

Measured memory_bytes: 3060
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()

fun main(args: Array<String>) {
    val n = readInt()
    val a = readListOfInt()
    val average: Double = a.sum().toDouble() / n.toDouble()
    val changeNum: Int = average.toInt().let {if(isDecimal(average) && (average - average.toInt() > 0.5)) it + 1 else it }
    //println("$average, $changeNum")
    val ans = a.fold(0) { acc, v -> acc + (v-changeNum) * (v-changeNum) }
    println(ans)
    pw.flush()
}

/****** Decrared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j] % MOD)
        }
    }
    val rtn = v.map { it.toList() }.toList()
    return rtn 
}

fun gcd(a: Long, b: Long): Long = 
if(b != 0L) a else gcd(b, a % b)

fun lcm(a: Long, b: Long) = 
if(b==0L) a else gcd(b, a % b)

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


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

using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll a, b; cin >> a >> b;
  fin(a * b - (a + b - 1))
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<functional>
#include<numeric>
#include<map>
//#include<>
using namespace std;

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define REPS(i, n) for(int i=1;i<=(int)(n);i++)
#define RREP(i, n) for(int i=(int)n-1;i>=0;i--)
#define RREPS(i, n) for(int i=(int)n;i>0;i--)
#define FOR(it, a) for(auto it = a.begin();it!=a.end();++it)
#define RFOR(it, a) for(auto it = a.rbegin();it!=a.rend();++it)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back

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

int n, m;

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m, n){
		map<int, int> p;
		ll sum = 0;
		REP(i, n){
			int x, y;
			cin >> x >> y;
			p[y] += x;
			sum += (ll)x*y;
		}
		RFOR(it, p){
			ll t = min(it->second, m);
			sum -= t*(it->first);
			m -= t;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
 
typedef struct node * Node;
void insert(int);
void inorder(Node);
void preorder(Node);
 
Node root;
int main()
{
  int n,i,x;
  char com[20];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}
void insert(int k)
{
  Node y = NIL;
  Node x = root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y = x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
 
  z->parent=y;
  if(y == NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;
}
 
void inorder(Node root)
{
 
  if(root != NIL){
    inorder(root->left);
    printf(" %d", root->key);
    inorder(root->right);
  }
 
}
 void preorder(Node root)
{
 if(root != NIL){
    printf(" %d", root->key);
    preorder(root->left);
    preorder(root->right);
  }
}

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

#define int long long
#define ll unsigned long long
#define pb push_back
#define mp make_pair
#define veci vector<int>
#define pii pair<int,int>
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define repi(i,a,b) for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define fi first 
#define se second
#define all(v) v.begin(),v.end()

int mod=1e9+7;

int powerm(int x,int y, int M){ int res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
int  power(int x,int y){ int res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
bool isprime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; }
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
    T=1;
//    cin>>T;
while(T--){
    char alpha;
    cin>>alpha;
    if(alpha>='a' && alpha<='z') cout<<'a';
    else cout<<'A';
}
    
    return 0;
}

Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();

    int target = Integer.parseInt(a.concat(b));
    int onlimit = 0;
    int count = 1;

    do{
      onlimit = (count*count);
      
      if(onlimit == target){
        System.out.println("Yes");
        break;
        
      }else if(onlimit > target){
         System.out.println("No");
         break;

      }else{
        count++;
      }
      
    }while(onlimit < target);
  }
}


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

int main(){
    string a,b;
    cin >> a;
    int i,j;
    for(i=0;i<a.length();i++){
        if(a[i]=='?'){
            if(a[i-1]=='P')
                a[i]='D';
            else if(a[i+1]=='D')
                a[i]='P';
            else if(a[i+1]=='?'){
                a[i]='P';
                a[i+1]='D';
                i++;
            }
            else
                a[i]='D';
        }
    }
    cout << a;
}


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

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(long long int &x){
    int k=gc();x=0;
    for(;k<48||k>57;k=gc());
    for(;k>47&&k<58;k=gc())x=x*10+k-48;
}

typedef priority_queue<long long> P;
long long d[300001], m, i, M, N, O, a[300000];
P q, l;

int main(){
    read(N);
    M = N << 1;
    O = N * 3;
    for(; i < O; ++i){
        read(a[i]);
    }
    for(i = 0; i < M; ++i){
        q.push(-a[i]);
        m += a[i];
        if(N <= i){
            m += q.top();
            q.pop();
        }
        d[i + 1] = m;
    }
    m = 0;
    for(i = O; --i >= N;){
        l.push(a[i]);
        m += a[i];
        if(i < M){
            m -= l.top();
            l.pop();
        }
        d[i] -= m;
    }
    cout << *max_element(d + N, d + M + 1) << endl;
}


Measured memory_bytes: 7156
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    int N,D;
    cin >> N >> D;
    int F = 2 * D + 1;
    if(N % F == 0) cout << N / F << endl;
    else cout << N / F + 1 << endl;
    return 0;
}

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

string num;
char op[3];
bool flg = false;

void dfs(int depth){
    if( depth == 3 ){
        int res = num[0] - '0';
        for(int i=0;i<3;i++){
            if( op[i] == '+' )  res += num[i+1] - '0';
            else                res -= num[i+1] - '0';
        }
        if( res == 7 ){
            for(int i=0;i<3;i++)    cout << num[i] << op[i];
            cout << num[3] << "=7" << endl;
            flg = true;
        }
        return;
    }

    op[depth] = '+';
    if( !flg )  dfs(depth+1);
    op[depth] = '-';
    if( !flg )  dfs(depth+1);
    
    return;
}

int main(){
    cin >> num;

    dfs(0);
}

Measured memory_bytes: 256
import heapq

class Node:
    def __init__(self, k, v):
        self.k = k
        self.v = v
        self.left = None
        self.right = None

def hist(s):
    d = {}
    for c in s:
        if c not in d:
            d[c] = 0
        d[c] += 1
    return d

S = raw_input()
D = hist(S)
pool = []
for k,v in D.items():
    heapq.heappush(pool, (v, Node(k,v)))

while len(pool) >= 2:
    _, x = heapq.heappop(pool)
    _, y = heapq.heappop(pool)
    zv = x.v + y.v
    z = Node("", zv)

    if x.v > y.v and x.k != "":
        x,y = y,x
    z.left = x
    z.right = y
    heapq.heappush(pool, (zv,z))

D = {}
def traverse(node, code):
    if node.k == "":
        traverse(node.right, code+"1")
        traverse(node.left, code+"0")
    else:
        if code == "":
            code += "0"
        D[node.k] = code

traverse(pool[0][1], "")
#print D
ans = sum([len(D[c]) for c in S])
print ans


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

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    priority_queue<int> pq;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        pq.push(a);
    }
    for (int i = 0; i < M; i++) {
        int a = pq.top();
        pq.pop();
        a /= 2;
        pq.push(a);
    }
    ll sumn = 0;
    for (int i = 0; i < N; i++) {
        sumn += 1LL * pq.top();
        pq.pop();
    }
    cout << sumn << '\n';
    return 0;
}


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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int r;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> r;
	cout << 3*r*r << endl;
	
	return 0;
}


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

int main(){
    unsigned long N;
    cin >> N;
    queue<long> q;
    vector<long> d(20, -1);
    unsigned long ans{0};
    for(long l = -1, r = 0, A, k = -1; r < N; ++r){
        cin >> A;
        q.push(A);
        for(unsigned long i = 0; i < 20; ++i)if((A >> i) & 1){
            for(k = max(k, d[i]); l < k; ++l, q.pop())for(long j = 0, a = q.front(); j < 20; ++j)if((a >> j) & 1)d[j] = -1;
            d[i] = r;
        }
        ans += r - l;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
struct node {
	int key;
	node* parent, * left, * right;
};
node* nil, * root;
void insert(int key) {
	node* y = nil;//親
	node* x = root;
	node* z;
	z = (node*)malloc(sizeof(node));
	z->key = key;
	z->left = nil;
	z->right = nil;
	while (x!=nil) {
		y = x;
		if (z->key<x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y==nil) {
		root = z;
	}
	else {
		if (z->key<y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
};
void ino(node* u) {
	if (u == nil) {
		return;
	}
	ino(u->left);
	cout << " " << u->key;
	ino(u->right);
};
void pre(node* u) {
	if (u == nil) {
		return;
	}
	cout << " " << u->key;
	pre(u->left);
	pre(u->right);
}

string find(int key,node* root) {
	node* x = root;
	while (x!=nil) {
		if (key==x->key) {
			return "yes";
		}
		if (key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	return "no";
}
void print(node* root) {
	ino(root);
	cout << endl;
	pre(root);
	cout << endl;
};
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		string order;
		cin >> order;
		if (order == "insert") {
			int key;
			cin >> key;
			insert(key);
		}
		else if (order=="find"){
			int key;
			cin >> key;
			cout<<find(key,root)<<endl;
		}else
		{
			print(root);
		}
	}
};




Measured memory_bytes: 21916
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main()
{
	int n,d,x,count=0;
	cin >> n >> d >> x;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		count+=((d-1)/a[i]+1);
	}
	cout << count+x << endl;
	return 0;
}


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

using namespace std;
int n , z;

pair < int , int > st[4*100000];

int op(int iz , int der)
{
	return st[iz].first + st[der].first;
}
void push(int v , int l , int r)
{
	if(r-l == 1)
		return;
	int m = (r+l)/2;
	st[2*v].second += st[v].second;
	st[2*v].first += st[v].second*(m-l);
	st[2*v+1].second += st[v].second;
	st[2*v+1].first += st[v].second*(r-m);
	st[v].second = 0;
}

void u(int v , int l , int r, int i , int j, int x)
{
	push(v , l , r);
	if(j < l || i >= r)
	{
		return;
	}else if(i <= l && r-1 <= j)
	{
		st[v].second += x;
		st[v].first += (r-l)*x;
	}else
	{
		int m = (r+l)/2;
		u(2*v , l , m , i , j , x);
		u(2*v+1 , m , r , i , j , x );
		st[v].first = op(2*v , 2*v+1);
	}
}



int q(int v , int l , int r , int x)
{
	push(v , l , r);
	if(x < l || x >= r)
	{
		return 0;
	}else
	{
		if(r - l == 1)
		{
			return st[v].first;
		}else
		{
			int m = (r+l)/2;
			return max(q(2*v , l , m , x) , q(2*v+1 , m , r , x ));
		}
	}
}


int main()
{
	cin >> n >> z;
	int a , b , c , d;
	while(z--)
	{
		cin >> a ;
		if(a == 0)
		{
			cin >> b >> c >> d;
			u(1,1,n+1,min(b,c),max(b,c),d);
		}else
		{
			cin >> b;
			cout << q(1,1,n+1,b) << '\n';
		}
	}
	return 0; 
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    char pic[H + 2][W + 2];
    for (int i = 0; i < H + 2; i++)
    {
        for (int j = 0; j < W + 2; j++)
        {
            pic[i][j] = '#';
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cin >> pic[i + 1][j + 1];
        }
    }
    for (int i = 0; i < H + 2; i++)
    {
        for (int j = 0; j < W + 2; j++)
        {
            cout << pic[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256