akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll n, m, p;
const ll INF = 1e18;
struct edge
{
    ll u, v, c;
};
vector<edge> e;
vector<vector<int>> adj;
vector<ll> d, par;
vector<bool> vis;
void dfs(int s)
{
    for(auto i : adj[s])
    {
        if(!vis[i]) 
        {
            vis[i] = true;
            dfs(i);
        }
    }
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> p;
    F0R(i, m)
    {
        edge x;
        cin >> x.u >> x.v >> x.c;
        x.u--; x.v--; x.c = p - x.c;
        e.pb(x);
    }
    d.assign(n, INF);
    par.assign(n, -1);
    d[0] = 0;
    int x = -1;
    F0R(i, n)
    {
        x = -1;
        F0R(j, m)
        {
            if(d[e[j].u] >= INF) continue;
            if(d[e[j].v] > d[e[j].u] + e[j].c)
            {
                d[e[j].v] = d[e[j].u] + e[j].c;
                x = e[j].v;
                par[e[j].v] = e[j].u;
            }
        }
    }
    if(x != -1) F0R(i, n) x = par[x];
    adj.assign(n, vector<int>());
    F0R(i, m) adj[e[i].v].pb(e[i].u);
    vis.assign(n, false);
    vis[n - 1] = true;
    dfs(n - 1);
    if(d[n - 1] >= 1e11) cout << -1;
    else cout << ((x == -1 || !vis[x]) ? max(-d[n - 1], 0LL) : -1);
    return 0;
}

Measured memory_bytes: 576
#include <cstdio>
#include<stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)b - *(int*)a;
} 

int main() {

    int sum = 0;
    int N;
    scanf("%d", &N);

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

    qsort(a, N, sizeof(int), compare_int );

    for (i = 0; i < N;i++){
        if (i % 2 == 0)
           sum += a[i];
        else
           sum -= a[i];
    }
    printf("%d", sum);

    return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] l = new Integer[n];
		for ( int i = 0; i < n; i++ ) {
			l[i] = in.nextInt();
		}
		Arrays.sort(l, Comparator.reverseOrder());

		int cnt = 0;
		for ( int p = 0; p < n; p++ ) {
			for ( int c = p + 1; c < n; c++ ) {
				int d = l[p] - l[c];
				for ( int i = c + 1; i < n; i++ ) {
					if ( l[i] > d ) cnt++;
					else break;
				}
			}
		}
		System.out.println(cnt);
		in.close();
	}
}

Measured memory_bytes: 25928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {
  int x;
  cin >> x;
  if(x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
}

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

int L[210];

int main(){
  int N; scanf("%d", &N);
  for(int i = 0; i < 2 * N; i++) scanf("%d", &L[i]);

  sort(L, L + 2 * N);

  int ans = 0;
  for(int i = 0; i < N; i++) ans += L[2 * i];

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

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

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

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,sa[3010],sb[3010],ta=0,tb=0,pos[6010];
char s[6010];
string f[3010];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<=2*n;i++)
	{
		if(s[i]=='a') sa[++ta]=i,pos[i]=ta;
		else sb[++tb]=i,pos[i]=tb;
	}
	string ans;
	for(int i=n;i>=1;i--)
	{
		if(sa[i]<sb[i])
		{
			int k=i;
			for(int j=sa[i]+1;j<sb[i];j++) k=max(k,pos[j]);
			f[i]="ab"+f[k+1];
		}
		else
		{
			int k=i;
			while(k<n&&sb[k+1]<sa[k]) k++;
			for(int j=sb[i];j<=2*n;j++) if(pos[j]>=i&&pos[j]<=k) f[i]+=s[j];
			f[i]+=f[k+1];
		}
		f[i]=max(f[i],f[i+1]);
		ans=max(ans,f[i]);
	}
	printf("%s",ans.c_str());
}

Measured memory_bytes: 14592
import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

if __name__=='__main__':
    n = I()
    a = list(IL())
    count = 0
    ans = 1000
    for i in range(len(a)-1):
        if a[i]<a[i+1]:
            tmp = ans//a[i]
            count += tmp
            ans -= tmp*a[i]
        elif a[i]>a[i+1]:
            ans += a[i]*count
            count = 0
    ans += count*a[-1]
    print(ans)
    exit()

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string N;
    ll sum = 0;
    cin >> N;
    reverse(N.begin(), N.end());
    for(ll i = 0;i < N.size() - 1;i++) {
        if(N[i] != '9') {
            N[i + 1] -= 1;
            N[i] = '9';
        }
    }
    for(auto &c: N) sum += c - '0';
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
int main()
{
    long n, ans = INT_MAX;
    cin >> n;
    for (long i = 1; i <= n / i; i++)
    {
        if (n % i == 0)
        {
            long a = (i < (n / i) ? (n / i) : (i));
            int digit = 0;
            while (a != 0)
            {
                digit++;
                a /= 10;
            }
            if (digit < ans)
            {
                ans = digit;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
typedef long long ll;
using namespace std;

ll max(ll a, ll b) {
  return a > b ? a : b;
}

int main(void) {
  ll i, j, k, n, c, ans = 0, now;
  scanf("%lld%lld", &n, &c);
  pair<ll, ll> s[2 * n];
  ll max1[2 * n], max2[2 * n];
  ll dp[2 * n];
  for(i = 0; i < n; ++i) scanf("%lld%lld", &s[i].first, &s[i].second);
  sort(s, s + n);
  for(i = 0; i < n; ++i) s[i + n] = s[i];
  max1[n] = 0, max2[n] = 0;
  for(i = n; i < 2 * n; ++i) {
    now += s[i].second;
    ll tmp = now - s[i].first;
    if(i != n) max1[i] = max1[i - 1], max2[i] = max2[i - 1];
    if(max1[i] < tmp) max1[i] = tmp;
    if(max2[i] < tmp - s[i].first) max2[i] = tmp - s[i].first;
  }
  now = 0, max1[n - 1] = 0, max2[n - 1] = 0;
  for(i = n - 1; i >= 0; --i) {
    now += s[i].second;
    ll tmp = now + s[i].first - c;
    if(i != n - 1) max1[i] = max1[i + 1], max2[i] = max2[i + 1];
    if(max1[i] < tmp) max1[i] = tmp;
    if(max2[i] < tmp + s[i].first - c) max2[i] = tmp + s[i].first - c;
  }
  //for(i = 0; i < 2 * n; ++i) printf("%lld %lld\n", max1[i], max2[i]);
  for(i = 1; i < n; ++i) if(ans < max1[i] + max2[i + n - 1]) ans = max1[i] + max2[i + n - 1];
  for(i = 1; i < n; ++i) if(ans < max1[i + n - 1] + max2[i]) ans = max1[i + n - 1] + max2[i];
  for(i = 0; i < 2 * n; ++i) if(ans < max1[i]) ans = max1[i];
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 6408
#include <iostream>
#include <string>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int U = (S[0] - '0') * 10 + (S[1] - '0');
  int L = (S[2] - '0') * 10 + (S[3] - '0');
  bool u, l;
  u = (U >= 1) && (U <= 12);
  l = (L >= 1) && (L <= 12);
  if (u && l) cout << "AMBIGUOUS" << endl;
  else if (!u && l) cout << "YYMM" << endl;
  else if (u && !l) cout << "MMYY" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    long int n, min, max, sum;
    cin >> n;
    long int a[n];
    cin >> a[0];
    min = a[0];
    max = a[0];
    sum = a[0];

    for(int i=1;i<n; i++){
        cin >> a[i];

        if(min > a[i]){
            min = a[i];
        }
        if(max < a[i]){
            max = a[i];
        }
        sum += a[i];
    }
    cout << min << ' ' << max << ' ' << sum << endl;

}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	int m;
	int b, c;
	cin >> n >> m;
	int h[n];
	bool a[n];

	for(int i=0; i<n; i++){
		cin >> h[i];
		a[i]=true;
	}
	for(int i=0; i<m; i++){
		cin >> b >> c;
		if(h[b-1]<=h[c-1]) a[b-1]=false;
		if(h[c-1]<=h[b-1]) a[c-1]=false;
	}
	
	int count=0;
	for(int i=0; i<n; i++){
		if(a[i]==true) count++;
	}
	cout << count;
    return 0;
}

Measured memory_bytes: 4144
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int x; cin >> x;

	for (int a = 0; a <= 6000; ++a)
	{
		int a5 = a * a * a * a * a;
		int b5 = a5 - x;

		if (b5 == 0)
		{
			cout << a << ' ' << 0 << '\n';
			return 0;
		}

		int b = 1;

		for (b = 1; b * b * b * b * b < abs(b5); ++b);

		if (b * b * b * b * b == abs(b5))
		{
			if (b * b5 < 0)
				b = -b;

			cout << a << ' ' << b << '\n';
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int main()
{
	ll n, k;
	cin >> n >> k;
	ll ans = 0;

	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}

	// (a,b) pair that (a mod b) >= k
	for (int b = k + 1;b <= n;b++) { 
		ans = ans + ( (n+1) / b) * (b - k);
		if (( (n+1) % b) > k) {
			ans = ans + ( (n+1) % b) - k;
		}

		//cout << b << "-" << ans << endl;
	}

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


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

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

typedef long long ll;
using namespace std;

int main(){
    string N;
    cin >> N;
    if(N[0] < N[1]){
        rep(i,N.size()) cout << N[0]-'0'+1;
    }
    else if(N[0] == N[1]){
        if(N[1] < N[2]) rep(i,N.size()) cout << N[0]-'0'+1;
        else rep(i,N.size()) cout << N[0];
    }
    else rep(i,N.size()) cout << N[0];
    return 0;
}

Measured memory_bytes: 256
//ABC078D
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n, z, w;
	cin >> n >> z >> w;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	int ans;
	if(n == 1){
		ans = abs(w-a.at(0));
	}else{
		ans = max(abs(w-a.at(n-1)),abs(a.at(n-1)-a.at(n-2)));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)
N = int(input())
E = [[] for _ in range(N+1)]
for _ in range(N-1):
    x, y = map(int, input().split())
    E[x].append(y)
    E[y].append(x)

def dfs(v, p):
    res = 0
    for u in E[v]:
        if u != p:
            res ^= dfs(u, v) + 1
    return res

print("Alice" if dfs(1, 0) else "Bob")


Measured memory_bytes: 109488
#include <iostream>

using namespace std;
typedef unsigned long long ll;


ll gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
ll lcm(ll a, ll b)
{
  return (a*b)/gcd(a,b);
}

ll f(ll x, ll c, ll d)
{
  return x-(x/c)-(x/d)+(x/lcm(c,d));
}

int main()
{
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  cout << f(B, C, D)-f(A-1, C, D) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a;
	scanf("%d",&a);
	if(a==25) printf("Christmas\n");
	if(a==24) printf("Christmas Eve\n");
	if(a==23) printf("Christmas Eve Eve\n");
	if(a==22) printf("Christmas Eve Eve Eve\n");
	return 0;
}


Measured memory_bytes: 1612
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//

//===========================================================================//
int main(void)
{
  // Scan begin.
  int a, b;
  cin >> a >> b;
  // Scan done.

  // Code begin.
  if (a%2==1 && b%2==1) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  // Code done.

  return 0;
}

//=functions=================================================================//

//===========================================================================//

Measured memory_bytes: 256
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()

    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
rrmm = lambda n: [rrm() for _ in xrange(n)]

####
MOD = 10**9 + 7
YES, NO, IMP = "YES", "NO", "IMPOSSIBLE"
from collections import defaultdict as ddic

a,b,c,d = rrm()
cand = [a*c,a*d,b*c,b*d]
print max(cand)


Measured memory_bytes: 86476
#include <bits/stdc++.h>
using namespace std;
int main(void){
   vector<int> L(3, 0);
   for (int i=0; i<3; i++){
       cin >> L[i];
   }
   sort(L.begin(), L.end()); //ソート
   cout << L[2]*10 + L[1]+ L[0];
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

signed main() {
  int n;
  cin >> n;

  vector<int> a(n), b(n), c(n);

  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  for (auto &i : c) cin >> i;

  sort(all(a));
  sort(all(c));

  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    long long s = lower_bound(all(a), b[i]) - a.begin();
    long long t = c.end() - upper_bound(all(c), b[i]);

    ans += s * t;
  }

  cout << ans << endl;
}


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

int main() {
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			cout << i << "x" << j << "=" << i*j<< endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3048
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long


class ABuyingSweets {
public:
	void solve(std::istream& in, std::ostream& out) {
    int x, a, b;
    in >> x >> a >> b;
    out << x - a - b * ((x - a) / b) << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	ABuyingSweets solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3612
r, D, x = map(int, input().split())
ansLst = [0] * 10

ansLst[0] = int((r * x) - D)
for i in range(1, 10):
    ansLst[i] = int((ansLst[i - 1] * r) - D)
for i in ansLst:
    print(i)

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

using namespace std;
int main() {
  int n;
     cin>>n;
     int counterAC = 0;
     int counterWA = 0;
     int counterTLE = 0;
     int counterRE = 0;
     for(int i=0;i<n;i++){
        string s ;
        cin>>s;
        if (s=="AC")
            counterAC++;
        else if(s=="WA")
            counterWA++;
        else if(s=="TLE")
            counterTLE++;
        else if(s=="RE")
            counterRE++;
     }
     cout<<"AC x "<<counterAC<<"\n";
     cout<<"WA x "<<counterWA<<"\n";
     cout<<"TLE x "<<counterTLE<<"\n";
     cout<<"RE x "<<counterRE<<"\n";


}


Measured memory_bytes: 3628
a,b,c,x,y=map(int,input().split())
lo=0 
hi=10**19
def check(mi): 
    m=max(x,y)
    if m*2*c<=mi:
        #print('sdfu')
        return 1 
    if a<c and b<c: 
        cost=a*x+b*y 
        #print('hf')
        return cost<=mi 
    if a>c and b>c:
        cost=0 
        mini=min(x,y)
        #print('hsdfiu')
        return mini*c*2+(-mini+x)*a+(-mini+y)*b<=mi 

    if a*x+b*y<=mi:
        return 1 
    mini=min(x,y)
    if mini*c*2+(x-mini)*a+(y-mini)*b<=mi:
      #  print('sf')
        return 1 
    return 0 
#print(check(1700))
#print(check(4700))
#print(check(100000000))
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1 
    else:
        lo=mi+1 
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, K;
    cin >> N >> K;

    //入力
    priority_queue<pi > que;
    for(ll i = 0; i < N; i++){
        ll t, d;
        cin >> t >> d;
        que.push(make_pair(d, t));
    }
    //選んだネタとその個数を記録
    //mapで管理するのはよくないほんとよくない
    //map<ll, ll > mp;
    set<ll > st;
    //美味しいさが大きい順に選ぶ
    ll sum = 0;
    priority_queue<pi , vector<pi >, greater<pi > > kouho;
    for(ll i = 0; i < K; i++){
        ll t = que.top().second;
        ll d = que.top().first;
        que.pop();
        sum += d;

        if(st.find(t) != st.end()) kouho.push(make_pair(d, t));
        st.insert(t);
    }

    //選び直し，食べる寿司の種類を増やしてみた時，ポイントが増えますか？
    ll ans = sum + st.size() * st.size();
    for(ll i = 0; i < N; i++){
        if(kouho.empty() || que.empty()) break;

        ll t = que.top().second;
        ll d = que.top().first;
        que.pop();
        //cout << ans - (type * type) - kouho.top().first.first + d + (type+1) * (type+1) << endl;
        if(st.find(t) != st.end()) continue;
        
        sum = sum - kouho.top().first + d;
        st.insert(t);
        kouho.pop();

        ans = max(ans, (ll)(sum + st.size() * st.size()));
        //cout << ans << endl;
    }

    cout << ans << endl;

}

Measured memory_bytes: 5744
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5 &&b==5 && c==7||a==5 && b==7&& c==5||a==7 && b==5&&c==5)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");

    }
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,m; cin >> n >> m;
  Graph g(n);
  REP(i,m) {
    int a,b; cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> hist(n, -1);
  queue<int> que;
  hist[0] = 0;
  for(auto v: g[0]) {
    que.push(v);
    hist[v] = 0;
  }
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for (int nv : g[v]) {
      if (hist[nv] != -1) continue;
      hist[nv] = v;
      que.push(nv);
    }
  }
  REP(i,n) {
    if (hist[i] == -1) { COUT("No"); return 0; }
  }
  COUT("Yes");
  for (int i = 1; i < n; ++i) cout << hist[i]+1 << endl;
  return 0;
}


Measured memory_bytes: 10136
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int mod = 1e9 + 7;

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

    int n;
    cin>>n;
    vector<ll> input(n);
    vector<ll> pref(n);

    for(int i = 0; i<n; i++){
        cin>>input[i];
        pref[i] = input[i];

        if(i != 0){
            pref[i] += pref[i-1];
            pref[i] %= mod;
        }
    }

    ll ans = 0;

    for(int i = 1; i<n; i++){
        ans += pref[i-1]*input[i];
        ans %= mod;
    }

    cout<<ans<<"\n";

    return 0;
}


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

int N, M, dp[100009];
vector<int> G[100009];

int solve(int u) {
    if(dp[u] == -1) {
        dp[u] = 0;
        for(int v : G[u])
            dp[u] = max(dp[u], solve(v) + 1);
    }
    return dp[u];
}

int main() {
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--; // 0-indexed にする
        G[x].push_back(y);
    }

    for(int i = 0; i < N; i++)
        dp[i] = -1;

    int res = -1;
    for(int i = 0; i < N; i++)
        res = max(res, solve(i));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
using namespace std;

using ll=long long int;

int main() {

	string s;
	cin >> s;

	int maxi = 0;

	for (int i = 0; i < s.size(); i++) {
		int cnt = 0;
		for (int j = i; j < s.size(); j++) {

			if (s[j] != 'A' && s[j] != 'T' && s[j] != 'G' && s[j] != 'C') {
				break;
			}

			cnt++;
		}
		maxi = max(maxi, cnt);

	}

	cout << maxi << endl;

	return 0;
}





Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	static Scanner s = new Scanner(System.in);
	static int n,a[];
	public static void main(String[] args) {
		n = s.nextInt();
		a = new int[n];
		for(int i=0;i<n;i++) a[i]=s.nextInt();
		Arrays.sort(a);

		/*
		long[] ruisekiwa = new long[n];
		ruisekiwa[0]=a[0];
		for(int i=1;i<n;i++) ruisekiwa[i]=a[i]+a[i-1];
		System.out.println(Arrays.toString(ruisekiwa));
		*/

		int last=a[n-1],count=1;

		long sum=a[0],result=1;
		for(int i=1;i<n;i++) {
			if(sum*2>=a[i]) {
				count++;
			}else {
				count=1;
			}
			sum+=a[i];
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 51792
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <sstream>
#include <cassert>
#include <queue>
#include <bitset>
#include <ctime>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define sz(x) ((int)x.size())
#define fst first
#define snd second
#define ok(x) ((0<=(x).fst&&(x).fst<n)&&(0<=(x).snd&&(x).snd<m))
typedef long long ll;
typedef pair<int, int> ii;
const int MAXN = 405;

int n, m;
ll ans;
string grid[MAXN];
char ss[MAXN];
bitset<MAXN> used[MAXN];
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};

void readstring(string &s){
	scanf(" %s", ss);
	s = ss;
}

void bfs(ii src){
	int white = 0;
	int black = 0;
	queue<ii> q; q.push(src);
	used[src.fst][src.snd] = 1;
	while(sz(q)){
		ii v = q.front(); q.pop();
		//~ printf("(%d, %d)\n", v.fst, v.snd);
		if(grid[v.fst][v.snd] == '#') black++;
		else 						  white++;
		forn(i, 4){
			ii w = {v.fst + dr[i], v.snd + dc[i]};
			if(ok(w) && !used[w.fst][w.snd] && grid[v.fst][v.snd] != grid[w.fst][w.snd]){
				used[w.fst][w.snd] = true;
				q.push(w);
			}
		}
	}
	ans += (ll)white*black;
}

int main(){
	//~ freopen("input.in", "r", stdin);
	while(scanf("%d %d", &n, &m) >= 1){
		forn(i, MAXN) used[i] = 0;
		ans = 0;
		
		forn(i, n){
			readstring(grid[i]);
			//~ printf("%s\n", grid[i].c_str());
		}
		forn(i, n){
			forn(j, m){
				if(grid[i][j] == '#' && !used[i][j]){
					bfs({i, j});
				}
			}
		}
		
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 460
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
B = [[] for i in range(H)]
k = 0

for i, a in enumerate(A):
    for j in range(a):
        B[k].append(i + 1)
        if len(B[k]) == W:
            k += 1

for i, row in enumerate(B):
    if i % 2 == 0:
        print(*row)
    else:
        print(*row[::-1])


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

N=int(input())
a = [int(input()) for _ in range(N)]
max_a=[0]*N
tmp_max=0
for i in reversed(range(N)):
    tmp_max=max(tmp_max,a[i])
    max_a[i]=tmp_max
ans=-1e+9
for i in range(N-1):
    ans=max(ans,max_a[i+1]-a[i])
print(ans)



Measured memory_bytes: 15192
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include<algorithm>
int main() {

    int n;
    int k;
    int sum=0;

    cin>>n;
    cin>>k;
    vector <int> data(n);
    
    for(int i = 0;i<n;i++){
        cin>>data[i];
    }
    
    sort(data.begin(),data.end());
    reverse(data.begin(),data.end());
    
    for(int i = 0;i<k;i++){
        sum = sum + data[i];
      }
      
      cout <<sum<<endl;
    

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, a, b;
	cin >> n >> a >> b;
	if (abs(a - b) % 2 == 1) {
		cout << "Borys\n";
	} else {
		cout << "Alice\n";
	}
}

Measured memory_bytes: 3604
n = int(input())
s = input()
l = 0
r = s[1:].count('E')
result = l + r
for i in range(1, n):
  if s[i - 1] == "W":
    l += 1
  if s[i] == "E":
    r -= 1
  result = min(result, l + r)
print(result)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define mod 1000000007
#define N 500043
#define mp(a,b) make_pair(a,b)
#define loop(a,b) for(int i=a;i<b;i++)
#define test int t; cin >> t; while(t--)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string x,y;
    cin >> x >> y;
    int n=x.length(),m=y.length();
    vector<vector<int>>dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(x[i-1]==y[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int len=dp[n][m];
    string ans="";
    int i=n,j=m;
    while(len>0){
        if(x[i-1]==y[j-1]){
            //cout << x[i-1] << " " << y[j-1] << endl;
            ans+=x[i-1];
            i--;j--;
            len--;
        }
        else if(dp[i][j]==dp[i-1][j])
            i--;
        else
            j--;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 38544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll k;
    cin >> k;
    vector<vector<ll>> dp(10, vector<ll>(10, 0));
    for (ll i = 0; i <10; ++i) {
        dp[0][i] = 1;
    }
    for (ll i = 1; i < 10; ++i) {
        for (ll j = 0; j < 10; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j > 0) {
                dp[i][j] += dp[i-1][j-1];
            }
            if (j < 9) {
                dp[i][j] += dp[i-1][j+1];
            }
        }
    }
    //for (ll i = 0; i < 10; ++i) {
    //    for (ll j = 0; j < 10; ++j) {
    //        cerr << dp[j][i] << ",";
    //    }
    //    cerr << endl;
    //}
    ll i = 0;
    ll j = 1;
    ll cur = 0;
    for (i = 0; i < 10; ++i) {
        j = 1;
        for (; j < 10; ++j) {
            if (cur + dp[i][j] >= k) break;
            cur += dp[i][j];
        }
        if (cur + dp[i][j] >= k) {
            break;
        }
    }
    cout << j;
    while (i > 0) {
        --i;
        --j;
        if (j < 0) j = 0;
        while (cur + dp[i][j] < k) {
            cur += dp[i][j];
            ++j;
        }
        cout << j;
    }
    cout << endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let _ = read::<usize>();
    let mut a = read_vec::<usize>();

    let mut iterates = vec![];
    for y in 0..h {
        if y % 2 == 0 {
            for x in 0..w {
                iterates.push((x, y));
            }
        } else {
            for x in (0..w).rev() {
                iterates.push((x, y));
            }
        }
    }
    // debug!(iterates);
    // debug!(a);
    let mut pointer = 0usize;
    let mut c = vec![vec![0; w]; h]; // c[y][x]
    for (x, y) in iterates {
        c[y][x] = pointer + 1;
        if a[pointer] >= 1 {
            a[pointer] -= 1;
        }
        if a[pointer] == 0 {
            pointer += 1;
        }
    }
    assert!(pointer == a.len());
    for i in 0..h {
        print_array(&c[i]);
    }
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    )
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(10**7)
from collections import defaultdict

def init(n):
    return list(range(n+1))

def find(lis, x):
    if lis[x] == x:
        return x
    else:
        lis[x] = find(lis, lis[x])
        return lis[x]

def sameset(lis, x, y):
    return find(lis, x) == find(lis, y)

def union(lis, x, y):
    x = find(lis, x)
    y = find(lis, y)
    if x != y:
        lis[x] = y

N = int(input())
union_find_tree = init(N)

town = []

for i in range(N):
    x, y = map(int, input().split())
    town.append((i, x, y))

x_sorted_town = sorted(town, key=lambda x: x[1])
y_sorted_town = sorted(town, key=lambda x: x[2])

graph = []

pre_tx = x_sorted_town[0]
pre_ty = y_sorted_town[0]
pre_nx = town[pre_tx[0]]
pre_ny = town[pre_ty[0]]
for tx, ty in zip(x_sorted_town[1:], y_sorted_town[1:]):
    nx = town[tx[0]]
    ny = town[ty[0]]
    wx = min(abs(tx[1] - pre_tx[1]), abs(nx[2] - pre_nx[2]))
    wy = min(abs(ty[2] - pre_ty[2]), abs(ny[1] - pre_ny[1]))
    graph.append((nx[0], pre_nx[0], wx))
    graph.append((ny[0], pre_ny[0], wy))
    pre_tx = tx
    pre_ty = ty
    pre_nx = nx
    pre_ny = ny

cost = 0
for (s,t,w) in sorted(graph, key=lambda x: x[2]):
    if not sameset(union_find_tree,s,t):
        union(union_find_tree,s,t)
        cost += w
print(cost)


Measured memory_bytes: 75648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Super Metropolis
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int W, H, N;

		words = br.readLine().split(" ");
		W = parseInt(words[0]);
		H = parseInt(words[1]);
		N = parseInt(words[2]);


		int sX, sY, tX, tY;
		int ans = 0;

		line = br.readLine();
		sX = parseInt(line.substring(0, line.indexOf(' ')));
		sY = parseInt(line.substring(line.indexOf(' ') + 1));

		for (int i = 0; i < N - 1; i++) {
			line = br.readLine();
			tX = parseInt(line.substring(0, line.indexOf(' ')));
			tY = parseInt(line.substring(line.indexOf(' ') + 1));

			if ((sX < tX && sY < tY) || (sX > tX && sY > tY)) {
				ans += Math.min(Math.abs(sX - tX), Math.abs(sY - tY))
						+ Math.abs(Math.abs(sX - tX) - Math.abs(sY - tY));
			} else {
				ans += Math.abs(Math.abs(sX - tX) + Math.abs(sY - tY));
			}
			
			sX = tX;
			sY = tY;
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 25416
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}]


int main(){
	ll n ; cin >> n ;
	vvll a(n,vll(n)) ;
	for(auto &i:a) for(auto &j:i) cin >> j ;
	vvll b = a ;
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				b.at(i).at(j) = min(b.at(i).at(j),b.at(i).at(k)+b.at(k).at(j)) ;
			}
		}
	}
	if(a!=b) cout << -1 << endl ;
	else{
		ll sum = 0 ;
		for(int i=0;i<n;i++) for(int j=i;j<n;j++) sum += a.at(i).at(j) ;
//		cout << sum << endl ;
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				if(i==j) continue ;
				for(int k=0;k<n;k++){
					if(i==k||j==k) continue ;
					if(a.at(i).at(k)+a.at(k).at(j)==a.at(i).at(j)){
						sum -= a.at(i).at(j) ;
						break ;
					}
				}
			}
		}
		cout << sum << endl ;
	}
}


Measured memory_bytes: 5064
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int[] n = new int[26];
		while(scan.hasNext()) {
			String S = scan.nextLine();
			String s = S.toUpperCase();
			for(int i = 0; i < s.length(); i++) {
				char c = s.charAt(i);
				int k = (int)c - 65;
				if(k >= 0 && k <= 25) {
					n[k]++;
				}
			}
		}
		scan.close();

		for(int i = 0; i < 26; i++) {
			int ch = i + 97;
			char c = (char)ch;
			System.out.println(c + " : " + n[i]);
		}
	}
}


Measured memory_bytes: 26256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    ll k;
    cin >> k;

    queue<ll> que;
    REP(i, 1, 10) que.push(i);

    rep(i, k - 1) {
        ll x = que.front();
        que.pop();
        if (x % 10 != 0) que.push(10 * x + x % 10 - 1);
        que.push(10 * x + x % 10);
        if (x % 10 != 9) que.push(10 * x + x % 10 + 1);
    }

    cout << que.front() << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int K, X;
  cin >> K >> X;

  int S = K - 1;

  rep(i, 2 * K - 1) { cout << X - S + i << endl; }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll modp = 1000000007;
random_device rnd;
mt19937 mt(rnd());
uniform_real_distribution<long double> RAND(0.0, 2.00);
ll N;
long double x[105];
long double y[105];
int near[105];
int sum = 3e6;
int main() {
    cout.precision(10);
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> x[i] >> y[i];
    }
    for(int i = 1; i <= sum; i++) {
        ll now = 0;
        //long double theta = RAND(mt);
        long double theta = 2.0 * PI * ((long double)i / (long double)sum);
        long double now_x = 1e11 * cos(theta);
        long double now_y = 1e11 * sin(theta);
        //cout << theta << " " << now_x << " " << now_y << endl;
        //cout << theta << endl;
        //cout << now_x << " " << now_y << endl;
        long double now_dist = 1e38;
        for(int j = 1; j <= N; j++) {
           long double new_dist = (x[j]-now_x)*(x[j]-now_x)+(y[j]-now_y)*(y[j]-now_y);
           if(now_dist > new_dist) {
               now_dist = new_dist;
               now = j;
           } 
        }
        near[now]++;
    }
    for(int i = 1; i <= N; i++) {
        cout << (double)near[i] / (double)(sum) << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
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, char) => {
        read_value!($next, String).chars().collect::<Vec<char>>()[0]
     };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
    ($next:expr, isize1) => {
        read_value!($next, isize) - 1
    };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}
#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        K: usize, S: usize,
    }
    let mut ans = 0;
    for x in 0..K+1 {
        for y in 0..K+1 {
            if x + y <= S && S - x - y <= K{
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T>
struct WeightedUnionFind{
  T d;
  vector<int> r,p;
  vector<T> ws;

  WeightedUnionFind(){}
  WeightedUnionFind(int n,T d):
    d(d),r(n,1),p(n),ws(n,d){iota(p.begin(),p.end(),0);}

  int find(int x){
    if(x==p[x]) return x;
    int t=find(p[x]);
    ws[x]+=ws[p[x]];
    return p[x]=t;
  }

  T weight(int x){
    find(x);
    return ws[x];
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y,T w){
    w+=weight(x);
    w-=weight(y);
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y),w=-w;
    r[x]+=r[y];
    p[y]=x;
    ws[y]=w;
  }

  T diff(int x,int y){
    return weight(y)-weight(x);
  }
};
//END CUT HERE

signed DSL_1_B(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,q;
  cin>>n>>q;
  WeightedUnionFind<int> wuf(n,0);

  for(int i=0;i<q;i++){
    int t,x,y,z;
    cin>>t>>x>>y;
    if(t){
      if(wuf.same(x,y)) cout<<wuf.diff(x,y)<<"\n";
      else cout<<"?\n";
    }else{
      cin>>z;
      wuf.unite(x,y,z);
    }
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/09/08
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_B&lang=jp
*/

signed main(){
  DSL_1_B();
  return 0;
}


Measured memory_bytes: 4136
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define FILL(a, value) memset(a, value, sizeof(a))
 
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
 
typedef long long LL;
typedef pair<int, int> PII;

unordered_map<LL, LL> mp;

LL a, b, c, d;

LL dp(LL n)
{
	if(n == 0)
		return 0;
	if(n == 1)
		return d;
	if(mp.count(n))
		return mp[n];
	int r2 = n % 2, r3 = n % 3, r5 = n % 5;
	LL& ans = mp[n];
	ans = dp((n - r2) / 2) + r2 * d + a;
	ans = min(ans, dp((n + (2 - r2) % 2) / 2) + ((2 - r2) % 2) * d + a);
	ans = min(ans, dp((n - r3) / 3) + r3 * d + b);
	ans = min(ans, dp((n + (3 - r3) % 3) / 3) + ((3 - r3) % 3) * d + b);
	ans = min(ans, dp((n - r5) / 5) + r5 * d + c);
	ans = min(ans, dp((n + (5 - r5) % 5) / 5) + ((5 - r5) % 5) * d + c);
	if(n <= ans / d)
		ans = min(ans, n * d);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	{
		LL n;
		cin >> n >> a >> b >> c >> d;
		cout << dp(n) << "\n";
		mp.clear();
	}
	return 0;
}


Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  vi X = {A,B,C};
  sort(all(X));
  rep(i,K) X.back() *= 2;
  
  cout << accumulate(all(X),0) << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	char a, b;
	
	scanf("%c %c", &a, &b);
	
	if(a == 'H'){
		if(b == 'H')
			printf("H\n");
		else
			printf("D\n");
	}
	else{
		if(b == 'H')
			printf("D\n");
		else
			printf("H\n");
	}
	
	
	return 0;
}


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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if (B / A > C) {
        printf("%d\n", C);
    } else {
        printf("%d\n", B / A);
    }

    return 0;
}


Measured memory_bytes: 256
#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>;
#define chmax(x,y) x = max(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> is(26);
    rep(i,n) is[s[i]-'a'].insert(i);
    rep(qi,q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            int i; char c;
            cin >> i >> c;
            i--;
            is[s[i]-'a'].erase(i);
            s[i] = c;
            is[s[i]-'a'].insert(i);
        }
        if (ty == 2) {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = 0;
            rep(i,26) {
                auto iter = is[i].lower_bound(l);
                if (iter != is[i].end() && *iter < r) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 27232