akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// input a letter
	template <class I>
	inline void get (I &x) {
		for (c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		x = c;
	}
	// input a string
	inline void read (char *s){
		for(c = gc(); c < 'A' || c > 'Z'; c = gc()) ;
		for(; c >= 'A' && c <= 'Z'; c = gc()) *++s = c;
		*++s = '\0';
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: gi;
using io :: get;
using io :: read;
using io :: putc;
using io :: print;
const int N=2e5+5;
int n,a[N],s[N],b[N],p[N],top,c[N];
inline bool check(ri mid){
	ri i,now;
	while(top) c[p[top--]]=0;
	for(i=2;i<=n;++i){
		if(s[i-1]<s[i]) continue;
		if(mid==1) return false;
		while(top&&p[top]>s[i]) c[p[top--]]=0;
		now=s[i];
		while(top&&p[top]==now&&c[p[top]]==mid-1)
			c[p[top--]]=0,--now;
		if(!now) return false;
		if(p[top]!=now) p[++top]=now;
		++c[now];
	}
	return true;
}
int main(){
	ri i,l,r,mid,lst;
	gi(n);
	for(i=1;i<=n;++i) gi(s[i]);
	for(i=1;i<=n;++i) a[i]=s[i];
	sort(a+1,a+1+n); 
	lst=0;
	for(i=1;i<=n;++i)
		if(a[i]!=a[i-1])
			b[i]=min(a[i],b[lst]+i-lst),
			lst=i;
	for(i=1;i<=n;++i) s[i]=b[lower_bound(a+1,a+1+n,s[i])-a];
	l=1;r=n;
	while(l<=r){
		mid=l+r>>1;
		if(check(mid))
			r=mid-1;
		else
			l=mid+1;
	}
	printf("%d\n",r+1);
	return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<algorithm>

using namespace std;

struct Node {
	int value;
	vector<int> son;
};

int N;
string S;
Node ar[10000];

int getnumber(int start, int end) {
	int ans = 0;
	for (int i = start + 1; i <= end - 1; i++) {
		if (S[i] == '[' || S[i] == ']')return -1;
	}
	ans = S[start + 1] - '0';
	for (int i = start + 2; i <= end - 1; i++) {
		ans *= 10;
		ans += (S[i] - '0');
	}
	return ans;
}

int calc(int start) {
	if (ar[start].son.size() == 0) {
		//最下層のノード
		return (ar[start].value + 1) / 2;
	}
	else {
		vector<int> A;
		for (int i = 0; i < ar[start].son.size(); i++) {
			A.push_back(calc(ar[start].son[i]));
		}
		sort(A.begin(), A.end());
		int ans = 0;
		for (int i = 0; i < (A.size() + 1) / 2; i++) {
			ans += A[i];
		}
		return ans;
	}
}

int main() {
	cin >> N;
	for (int cnt = 0; cnt < N; cnt++) {
		cin >> S;
		stack<int> Before;
		
		for (int j = 0; j < S.size(); j++) {
			if (S[j] == '[') {
				Before.push(j);
				
			}
			else if(S[j] == ']'){
				int startpos = Before.top(); Before.pop();
				int tmp = getnumber(startpos, j);
				if (tmp == -1) {
					//最下層ではない
					if (Before.size() != 0) {
						ar[Before.top()].son.push_back(startpos);
					}
				}
				else {
					//最下層である。
					ar[Before.top()].son.push_back(startpos);
					ar[startpos].value = tmp;
				}
			}
		}
		cout << calc(0) << endl;
		for (int i = 0; i < 10000; i++) {
			ar[i].son.clear(), ar[i].value = 0;
		}
	}

	return 0;
}


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

const ll mod = 1000000007;

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

ll kaijou(ll n)
{
    if (n <= 1)
        return 1;
    else
        return (n * kaijou(n - 1)%mod) % mod;
}

int main(){
    int n;
    cin >> n;
    ll x[n];
    ll y[n];
    ll kai = 1;
    for (int i = 1; i < n; i++)
        kai = kai * i % mod;
    rep(i, n) cin >> x[i];
    y[0] = 0;
    for(int i=1; i<n; i++) {
        y[i] = kai * modpow(i, mod - 2) % mod;
        y[i] = (y[i-1] + y[i]) % mod;
    }
    ll sum = 0;

    rep(i, n-1) {
        sum += y[i+1] * (x[i+1]-x[i]);
        sum %= mod;
    }

    cout << sum << endl;
    
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	long long arr[n];
	long long sum=0;
	for (int i=0; i<n; i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	long long diff = 100000000000;
	long long sum1=0;
	for (int i=0; i<n-1; i++){
		sum1+=arr[i];
		diff = min(diff, abs(sum1-(sum-sum1)));
	}
	cout << diff << endl;

}

Measured memory_bytes: 1792
#include <functional>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <sstream>  
#include <iomanip>  
#include <numeric>  
#include <cstring>  
#include <cassert>  
#include <cstdio>  
#include <string>  
#include <vector>  
#include <bitset>  
#include <queue>  
#include <stack>  
#include <cmath>  
#include <ctime>  
#include <list>  
#include <set>  
#include <map>  

using namespace std;

#define PB push_back  
#define MP(A, B) make_pair(A, B)  
#define fi first  
#define se second  

#define gcd(a,b) __gcd(a,b)
#define pi acos(-1.0)
#define pii pair<int,int>
#define ll long long  
#define MAX 1000005  
#define MOD 1000000007  
#define INF 0x3f3f3f3f  
#define EXP 1e-8  
#define lowbit(x) (x&-x)  
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

int snu[105] = {0};
int main()
{
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int a; cin >> a;
            snu[a] = 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; ++i){
        if(snu[i] == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  string a,b,c;
  string s[3];
  cin >> a >> b >> c;
  s[0] = a.at(0);
  s[1] = b.at(0);
  s[2] = c.at(0);
  
  for(int i=0;i < 3;i++){
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, a, b, c, d;
#define read(x) cin>>x
unordered_map<ll, ll> mp;

ll sove(ll n){
    if(n == 0) return 0;
    if(n == 1) return d;
    if(mp.count(n)) return mp[n];

    ll res = 1e18, temp;
    if(n < res / d) res = n * d;

    temp = n / 2 * 2; res = min(res, abs(n - temp) * d + a + sove(temp / 2));
    temp = (n + 1) / 2 * 2; res = min(res, abs(n - temp) * d + a + sove(temp / 2));
    temp = n / 3 * 3; res = min(res, abs(n - temp)* d + b + sove(temp / 3));
    temp = (n + 2) / 3 * 3; res = min(res, abs(n - temp) * d + b + sove(temp / 3));
    temp = n / 5 * 5; res = min(res, abs(n - temp) * d + c + sove(temp / 5));
    temp = (n + 4) / 5 * 5; res = min(res, abs(n -  temp) * d + c + sove(temp / 5));
    return mp[n] = res;
}

int main(){
//    Fast;
    int t; read(t); while(t--){
        read(n); read(a); read(b); read(c); read(d);
        printf("%lld\n", sove(n));
        mp.clear();
    }
    return 0;
}


Measured memory_bytes: 4244
#include<bits/stdc++.h>
#define ll long long
#define MAX 1e9+7
#define MIN -MAX
#define i(a) cin>>a
#define in(a,b) cin>>a>>b
#define o(a) cout<<a
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loop1(i,a,b) for(ll i=a;i<=b;i++)
#define v(a) vector<ll>a
#define mp(a,b) make_pair(a,b)
#define NO_OF_CHARS 256
using namespace std;
int countDivisors(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int main(){
ll n;
float sum=0.0f,ans;
//double sum=0;
cin >> n;
ll a[n];
for(ll i=0;i<n;i++){cin>>a[i];
sum+= (float)1/a[i];}
ans = 1/sum;
cout<<fixed;
cout<<setprecision(6)<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

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

    s64 n, k;
    cin >> n >> k;

    s64 ans = 0;
    vs64 num(k + 1);
    for (int i = k; i >= 1; --i)
    {
        s64 temp = 0;
        for (int j = i + i; j <= k; j += i)
        {
            temp = (temp + num[j]) % MOD;
        }
        num[i] = (mypow(k / i, n) + (MOD - temp)) % MOD;
        ans = (ans + (i * num[i]) % MOD) % MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3988
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n;
        int ans = 0;
        int[] a;
        int[] front_gcd;
        int[] back_gcd;

        n = Integer.parseInt(sc.next());
        a = new int[n + 5];
        front_gcd = new int[n + 5];
        back_gcd = new int[n + 5];

        for (int i = 1; i <= n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }

        for (int i = 1; i <= n; i++) {
            front_gcd[i] = gcd(front_gcd[i - 1], a[i]);

        }

        for (int i = n; i >= 1; i--) {
            back_gcd[i] = gcd(back_gcd[i + 1], a[i]);

        }

        for (int i = 1; i <= n; i++) {
            ans = Math.max(ans, gcd(front_gcd[i - 1], back_gcd[i + 1]));
        }

        System.out.println(ans);
    }

    public static int gcd(int x, int y) {
        int n = Math.min(x, y);
        int m = Math.max(x, y);

        while (n > 0) {
            int r = m % n;
            m = n;
            n = r;
        }

        return m;
    }

}


Measured memory_bytes: 52288
#include <stdio.h>
#include <stdlib.h>
int gcd(int x, int y){
  if(x < y){
    int s = x;
    x = y;
    y = s;
  }
  while(x % y != 0){
    int t = x % y;
    x = y;
    y = t;
  }
  return y;
}
int main(){
  int N, X;
  scanf("%d %d", &N, &X);
  int x[N];
  for(int i = 0; i < N; i++) {
    scanf("%d", &x[i]);
    x[i] = abs(x[i] - X);
  }
  int g = x[0];
  for(int i = 0; i < N; i++) g = gcd(g, x[i]);
  printf("%d\n", g);
}
  

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#define N 10005
using namespace std;

int n, s;
string a;
int main()
{
	int i;
	cin >> a;
	if (a[0] == a[1] && a[1] == a[2] || a[1] == a[2] && a[2] == a[3]) cout << "Yes";
	else cout << "No";
    return 0;
}


Measured memory_bytes: 256
program ABC167_B
  integer(8)::A,B,C,K
  read(*,*)A,B,C,K
  if(K<=A) then
     write(*,*)K
  else if(A<K .and. K<=A+B) then
     write(*,*)A
  else
     write(*,*)A-(K-A-B)
  end if
end program ABC167_B

Measured memory_bytes: 2800
#include<stdio.h>
#include<algorithm>
using namespace std;
int d[11];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<11;i++)d[i]=0;
		int v=0;
		for(int i=0;i<a;i++){
			int c;
			scanf("%d",&c);
			v=max(v,c/b);
			d[c/b]++;
		}
		int p=0;
		for(int i=0;i<11;i++)p=max(p,d[i]);
		double ret=0.01;
		for(int i=0;i<v;i++){
			ret+=(double)(v-i)/v*d[i]/p;
		}
		printf("%f\n",ret);
	}
}

Measured memory_bytes: 1064
n = int(input())
list_T = list(map(int, input().split()))
m = int(input())
list_PX = [ list(map(int,input().split(" "))) for i in range(m)]
sum_value = sum(list_T)
for i in range(m):
    l = list_PX[i]
    print(sum_value-(list_T[l[0]-1]-l[1]))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
    #include<ext/pb_ds/assoc_container.hpp>
    #include<ext/pb_ds/tree_policy.hpp>
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define MOD 1000000007
    #define MOD2 998244353
    #define pb emplace_back
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define sz(x) (ll)x.size()
    #define F first
    #define S second
    #define FOR(i,a,b) for(ll i=a;i<=b;++i)
    #define ROF(i,a,b) for(ll i=a;i>=b;--i)
    #define trace(x) cerr<<#x<<": "<<x<<'\n';
    typedef long long ll;
    using namespace std;
    using namespace __gnu_pbds;
    #define T int
    #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
    auto clk=clock();
     
    ll mexp(ll a, ll b, ll m){
        ll ans=1;
        a%=m;
        while(b){
            if(b&1) ans=ans*a%m;
            b>>=1;
            a=a*a%m;
        }
        return ans;
    }

    int main(){
        IOS
        srand(chrono::high_resolution_clock::now().time_since_epoch().count());


        string s;
        cin >> s;
        int n = s.length();
        FOR(i,0,n-2){
            if(s[i] == s[i+1]){
                cout << i + 1 << " "  << i + 2;
                return 0;
            }
        }
        FOR(i,0,n-3){
            if(s[i] == s[i+2]){
                cout << i + 1 << " "  << i + 3;
                return 0;
            }
        }
        cout << -1 << " "  <<  -1;

        cerr<<endl<<endl<<"Time: "<<fixed<<setprecision(12)<<(long double)(clock()-clk)/CLOCKS_PER_SEC<<" ms"<<endl<<endl;
     
        return 0;
    }

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n, m;
	cin >> n >> m;
	priority_queue<int> que;
	REP(i, n) {
		int a;
		cin >> a;
		que.push(a);
	}

	REP(i, m) {
		int a = que.top();
		que.pop();
		que.push(a / 2);
	}

	LL ans = 0;
	while (!que.empty()) {
		int a = que.top();
		que.pop();
		ans += a;
	}
	col(ans);
	return 0;
}

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

using namespace std;

int main()
{
  int m, g;
  while(cin >> m, m){
    int a[7], b[7];
    for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
    int comb[1001] = {0};
    comb[0] = 1;
    for(int i = 0; i < m; i++){
      for(int j = 1000; j >= 0; j--){
	for(int k = 1; k <= b[i]; k++){
	  if(j + k*a[i] <= 1000) comb[j + k*a[i]] += comb[j];
	}
      }
    }
    cin >> g;
    while(g--){
      int n;
      cin >> n;
      cout << comb[n] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll n;
  cin >>n;
  cout <<fixed<<setprecision(5)<<n*2*3.141592<<endl;
}


Measured memory_bytes: 3800
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		Array.Sort(nums);
    bool answer = true;

    for(int i = 0; i < n-1; i++)
    {
      if(nums[i] == nums[i+1]) answer = false;
    }

		if(answer) Console.WriteLine("YES");
    else Console.WriteLine("NO");
	}
}


Measured memory_bytes: 34140
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <math.h>
using namespace std;
using ll = long long;
int main()
{
	ll a, b = 0, c = 0, d = 0;
	ll l;
	ll memo[2][100];
	cin >> l;
	while (1)
	{
		a = 1;
		b = 0;
		if (c==l)
		{
			break;
		}
		while (l - c > a * 2&&b<18)
		{
			a *= 2;
			b++;
		}

		if (l - c == 1)
		{
			memo[0][d] = 20;
			memo[1][d] = c;
			
			//cout << 1 << " " << 20 << " " << c << endl;
		}
		else
		{
			memo[0][d] = 20-b;
			memo[1][d] = c;
			//cout << 1 << " " << 20 - b << " " << c << endl;
		}
		c += a;
		d++;
	}
	cout << 20 <<" " <<d+36<< endl;
	for (int i = 2; i < 20; i++)
	{
		cout << i << " " << i + 1 << " " << 0 << endl;
	}
	for (int i = 2; i < 20; i++)
	{
		cout << i << " " << i + 1 << " " << pow(2, 19 - i) << endl;
	}
	for (int i = 0; i < d; i++)
	{
		cout << 1 << " " << memo[0][i] << " " << memo[1][i] << endl;
	}

	//cout << c + d << endl;

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(void)
{
	char s[30][30][9];
	int h, w,i,j;
	scanf("%d %d", &h, &w);
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			scanf("%s", s[i][j]);
		}
	}
	
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (strcmp(s[i][j], "snuke") == 0) {
				printf("%c%d\n", 'A' + j, i + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))

#Sorted by first element
X.sort(key=lambda x: x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	total += X[i][1]
	ans += X[i][0] * X[i][1]
	if total > M:
		ans -= X[i][0] * (total-M)
		break
	i += 1
print(ans)

Measured memory_bytes: 29024
a, b, m = map(int, input().split())
listA = list(map(int, input().split()))
listB = list(map(int, input().split()))
minAB = min(listA) + min(listB)
for i in range(m):
    x, y, c = map(int, input().split())
    minAB = min(minAB, listA[x - 1] + listB[y - 1] - c)
print(minAB)


Measured memory_bytes: 18736
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i=0;i<n;i++){
			double xa = stdIn.nextDouble();
			double ya = stdIn.nextDouble();
			double ra = stdIn.nextDouble();
			double xb = stdIn.nextDouble();
			double yb = stdIn.nextDouble();
			double rb = stdIn.nextDouble();
			
			double distance = Math.sqrt(Math.pow(xa-xb,2)+Math.pow(ya-yb,2));
			
			if((ra+rb)<distance){
				System.out.println(0);
			}
			else if(Math.max(ra,rb)-Math.min(ra,rb)<=distance){
				System.out.println(1);
			}
			else if(ra<rb){
				System.out.println(-2);
			}
			else{
				System.out.println(2);
			}
		}
	}
}

Measured memory_bytes: 20520
import sys

n, m, v, p, *a = map(int, sys.stdin.read().split())
a.sort(reverse=True)

def possible(i):
    score = a[i] + m
    if i < p:
        return True
    else:
        every_ok = p - 1 + n - i 
        if every_ok >= v:
            if score >= a[p-1]:
                return True
            else:
                return False
        else:
            s = m * (v - every_ok)
            limit = 0
            for j in range(p-1, i):
                if a[j] > score:
                    return False
                limit += score - a[j]
            if s > limit:
                return False
            return True

def main():
    lo = -1
    hi = n
    while lo + 1 < hi:
        i = (lo + hi) // 2
        if possible(i):
            lo = i
        else:
            hi = i
        
    return lo + 1

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14436
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const int inf = 1145141919;
typedef pair<int, int> P;
typedef pair<P, int>PP;
typedef pair<int, char>PC;
struct edge { int to, cost; };
int a[114514], b[114514];
int npr[114514];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	vector<P>V;
	rep(i, n) {
		V.push_back(P(a[i], 0));
		V.push_back(P(b[i], 1));
	}
	sort(V.begin(), V.end());
	npr[0] = 1;
	rep(i, 112000) {
		npr[i + 1] = npr[i] * (i + 1);
		npr[i + 1] %= mod;
	}

	int ans = 1;
	int na = 0, nb = 0;
	rep(i, n + n) {
		if (V[i].second) {
			nb++;
			if(na)ans *= na*nb;
			if (na) {
				na--; nb--;
			}
		}
		else {
			na++;
			if(nb)ans *= na*nb;
			if (nb) {
				na--; nb--;
			}
		}
		ans %= mod;
	}
	cout << ans << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll A,B,C,D;
ll i,ans;

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

int main(){
    scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
    ans = B-A+1;
    ans -= B / C - (A-1) / C;
    ans -= B / D - (A-1) / D;
    ll gcdcd = gcd(C, D);
    ans += B / (D * C / gcdcd) - (A-1) / (D * C / gcdcd);
    printf("%lld", ans);

    return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

ll gcd(ll a, ll b) { return (a % b == 0 ? min(a, b) : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); }

void Main()
{
    int n = in();
    vll t = in(n);

    ll tmp = t[0];
    rep(i, n - 1)
    {
        tmp = lcm(tmp, t[i + 1]);
    }
    cout << tmp << endl;
}

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


Measured memory_bytes: 256
/*
 KUNAL RAUT (ZUKONIT14)  :- "DO WHAT YOU LIKE!"
 -PICT,PUNE! :)
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define mod9 1000000009
#define pi 3.1415926535
#define MAXN 1000001
#define N 1000001
#define MAX2N 1*1000 + 10
#define all(v) v.begin(), v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define forci(p,n) for(ll i=p;i<(ll)n;i++)
#define forcj(p,n) for(ll j=p;j<(ll)n;j++)
#define bolt ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define bits(a) __builtin_popcount(a)
#define test ll t;cin>>t;for(ll testi=1;testi<=t;testi++)
ll zero=0;
ll one=1;
ll gcd(ll a,ll b){    if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) {    return (a/gcd(a,b)*b);}
ll expo(ll x, ll y) {ll res=1;x=x%mod;while(y>0){if(y&1)res=(1ll*res*x)%mod;
    y=y>>1;x=(1ll*x*x)%mod;} return res;}
ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b)
{   if(a.second == b.second)
    return a.first < b.first;
    return (a.second < b.second);}
//https://www.youtube.com/watch?v=WTJSt4wP2ME

ll rr[]={0,1,1,1,0,-1,-1,-1,};
ll cc[]={1,1,0,-1,-1,-1,0,1};
#define MOD 998244353

signed main()
{
    bolt;
    ll x;cin>>x;
    while(1)
    {
        if(prime(x))
            return cout<<x,0;
        x++;
    }
}



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;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    vector<vector<vector<int>>> data(4, vector<vector<int>>(3, vector<int>(10)));

    int n, m;
    cin >> n >> m;
    
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> b(m);

    for(int i = 0; i < n; i++){
        for(int k = 0; k < m; k++){
            cin >> a[i][k];
        }
    }

    for(int j = 0; j < m; j++){
        cin >> b[j];
    }

    vector<int> c(n);
    for(int h = 0; h < n; h++){
        for(int v = 0; v < m; v++){
            c[h] += a[h][v] * b[v];
        }
    }

    rep(i, n) cout << c[i] << endl;
}



Measured memory_bytes: 3224
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

ll const MAX = 505;
ll x[MAX][MAX];

int main() {
	ll n, m, q;
	cin >> n >> m >> q;
	REP(i, 1, n) {
		REP(j, 1, n) {
			x[i][j] = 0;
		}
	}
	REP(i, 1, m) {
		ll l, r;
		cin >> l >> r;
		x[l][r]++;
	}
	REP(i, 1, n) {
		REP(j, 2, n) {
			x[i][j] += x[i][j - 1];
		}
	}
	REP(iii, 1, q) {
		ll a, b, ans;
		cin >> a >> b;
		ans = 0;
		REP(i, a, b + 1) {
			ans += x[i][b];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 2944
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 2e5 + 5;

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));
	
	int a, b; cin >> a >> b;
	if (a <= 0 && 0 <= b) die("Zero");
	b = min(b, -1);
	if (a > 0 || (abs(b - a + 1) % 2 == 0))  die("Positive");
	cout << "Negative" << endl;

	return 0;
}


Measured memory_bytes: 3616
using System;
using System.Linq;

namespace B0or1Swap
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var differences = Enumerable.Range(1, n)
                .Count(num => num != inputs[num - 1]);
            var answer = differences <= 2 ? "YES" : "NO";

            Console.WriteLine(answer);
        }
    }
}


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

int N, Q;
vector<int> graph[200200];
vector<ll> ans, cnt;

void dfs(int cur, int now = 0) {
    now += cnt[cur];
    ans[cur] += now;
    for (auto &nxt : graph[cur]) {
        dfs(nxt, now);
    }
}

int main() {

    cin >> N >> Q;
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
    }

    cnt.assign(N, 0);
    ans.assign(N, 0);

    REP(i, Q) {
        int p, x;
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }

    dfs(0);
    for (auto &e : ans) {
        cout << e << endl;
    }

}

Measured memory_bytes: 22656
from operator import itemgetter, attrgetter

n, m = list(map(int, input().split(' ')))
abn = [None] * n
for i in range(n):
    abn[i] = list(map(int, input().split(' ')))

abn = sorted(abn, key=itemgetter(0))

cost = 0
num = 0
for ab in abn:
    temp = 0
    while num < m and temp < ab[1]:
        cost += ab[0]
        temp += 1
        num += 1
    if num == m:
        break

print(cost)


Measured memory_bytes: 60376
#include <iostream>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n, h, m;
	char c;
	cin >> n;
	rep(i,n) {
		cin >> h >> c >> m;
		double x = 30.0*(h+m/60.0);
		double ret = abs(x-6*m) < 180 ? abs(x-6*m) : 360-abs(x-6*m);
		if(0 <= ret && ret < 30) cout << "alert" << endl;
		else if(90 <= ret && ret <= 180) cout << "safe" << endl;
		else cout << "warning" << endl;
	}
	return 0;
}

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

using namespace std;


#define MAXN 100001
typedef long long ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, c, x[MAXN], v[MAXN];
  cin >> n >> c;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> v[i];
  }
  ll ans = 0, pos = 0, cur = 0;
  ll mxr[MAXN] = {};
  ll mxl[MAXN] = {};
  for (int i = 0; i < n; ++i) {
    cur += v[i]-(x[i]-pos);
    pos = x[i];
    mxr[i] = max(i ? mxr[i-1] : (ll)-1e18, cur);
    ans = max(ans, cur);
  }
  cur = 0;
  pos = c;
  for (int i = n-1; i >= 0; --i) {
    cur += v[i]-(pos-x[i]);
    pos = x[i];
    mxl[n-i-1] = max(n-i-2>=0 ? mxl[n-i-2] : (ll)-1e18, cur);
    ans = max(ans, cur);
  }
  cur = 0;
  pos = 0;
  for (int i = 0; i < n; ++i) {
    cur += v[i]-2*(x[i]-pos);
    pos = x[i];
    ans = max(ans, cur+((n-i-2>=0) ? mxl[n-i-2] : 0));
  }
  cur = 0;
  pos = c;
  for (int i = n-1; i >= 0; --i) {
    cur += v[i]-2*(pos-x[i]);
    pos = x[i];
    ans = max(ans, cur+((i-1>=0) ? mxr[i-1] : 0));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int ary[22][22];

int main(){ _;
  int n,m,x,y,l;
  char d;
  while(cin>>n,n!=0){
    REP(i,22)REP(j,22) ary[i][j]=0;
    REP(i,n){
      cin>>x>>y;
      ary[x][y]=1;
    }
    cin>>m;
    int count=0;
    int posX=10,posY=10;
    REP(i,m){
      cin>>d>>l;
      REP(j,l){
	if(d=='N'){
	  posY++;
        }else if(d=='E'){
	  posX++;
        }else if(d=='S'){
	  posY--;
        }else{
	  posX--;
        }
	if(ary[posX][posY]==1){
	  ary[posX][posY]--;
	  count++;
	}
      }
    }
    cout<<(count==n?"Yes":"No")<<endl;
  }
}

Measured memory_bytes: 1188
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;
const double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	L = K;
	R = K + N - 1;
	int sum = 0;
	for (int i = L; i <= R; i++)sum += i;
	if (L > 0) {
		sum -= L;
	}
	else if (R < 0)sum -= R;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n;
  bool tf = true;
  
  rep(i,10){
    rep(j,10){
      if(n==i*j&&tf){
        cout << "Yes" << endl;
        tf = false;
        break;
      }
    }
  }
  
  if(tf) cout << "No" << endl;
}

Measured memory_bytes: 256
MOD = 1000000007

N, K = map(int, input().split())

if N == 1:
    print(K)
    exit()

uv = {}
for i in range(N-1):
    a, b = map(int, input().split())
    if a in uv:
        uv[a].append(b)
    else:
        uv[a] = [b]

    if b in uv:
        uv[b].append(a)
    else:
        uv[b] = [a]

f = None
for u in uv:
    if len(uv[u]) == 1:
        f = u
        break

ans = 1
b = [False] * (N+1)
ulist = [[f, 0]]
while ulist:
    u, pNum = ulist[-1]
    ulist.pop()
    b[u] = True

    uPtn = K - pNum
    ans = ans*uPtn % MOD

    cnt = 1
    if pNum == 0:
        cnt = 0
    for v in uv[u]:
        if b[v]:
            continue
        ulist.append([v, 1 + cnt])
        cnt += 1

print(ans)



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

int main()
{
    int n,i,x;
    cin >> n;
    int arr[n+1];
    for (i = 1; i <= n; i++){
        arr[i] = 0;
    }
    for (i = 0; i < n - 1; i++){
        cin >> x;
        arr[x]++;
    }
    for (i = 1; i <= n; i++){
        cout << arr[i] << '\n';
    }
}


Measured memory_bytes: 4316
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main (void)
{
      int num = 0;
      scanf("%d",&num);
      if (num%10 == 0 || num%10 == 1|| num%10 == 6||num%10 ==8){
        printf("pon");
      }
      else{
        if (num%10 == 3){
          printf("bon");
        }else{
          printf("hon");
        }
      }
  return 0;
}

Measured memory_bytes: 1712
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
       cin >> A[i];
    }
 
    long long ans = 0;
    int MaxNum = 0;
    for (int i = 0; i < N; i++)
    {
        //Use common MaxNum to reduce the compuation time
        MaxNum = max(MaxNum, A[i]);
        int Bi = MaxNum;
        ans += Bi - A[i];
    }
 
    cout << ans;
}

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

int main(){
    int a,b;
    char c,c1;
    while(cin>>a>>c>>b){
        if(c=='?')return 0;
        if(c=='+'){
            cout << a+b << endl;
            continue;
        }else if(c=='-'){
            cout << a-b << endl;
            continue;
        }else if(c=='*'){
            cout << a*b << endl;
            continue;
        }else if(c=='/'){
            cout << a/b << endl;
            continue;
        }
    }
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] c = new int[n];
        int[][] a = new int[n][m];

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        long ans = Long.MAX_VALUE;

        for (int i = 0; i < Math.pow(2,n); i++) {
            boolean ok = true;
            long res = 0;
            for (int k = 0; k < m; k++) {
                long sum = 0;
                for (int j = 0; j < n; j++) {
                    if ((1&i >> j) == 1) {
                        res += c[j];
                        sum += a[j][k];
                    }
                    // System.out.println(sum);
                }
                if (sum < x) {
                    ok = false;
                    
                }
                // System.out.println();
            }
            // System.out.println(res/m);
            if (ok) {
                ans = Math.min(ans,res/m);
            }
        }

        if (ans == Long.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }
}

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

long long gcd(long long a,long long b){
  if(a<b)
    swap(a,b);
  while(a%b!=0){
    a %= b;
    swap(a,b);
  }
  return b;
}
int main(){
  long long a,b; cin >>a>>b;
  
  cout << (a/gcd(a,b)) * b << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		long[] a = new long[N + 1];
		long[] b = new long[M + 1];
		for (int i = 1; i <= N; i++) {
			a[i] = a[i - 1] + sc.nextInt();
		}
		for (int i = 1; i <= M; i++) {
			b[i] = b[i - 1] + sc.nextInt();
		}
		int max = 0;
		for (int i = 0, j = M; i <= N; i++) {
			while (j >= 0 && K < a[i] + b[j]) j--;
			if (j < 0) break;
			max = Math.max(max, i + j);
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 62500
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

const int lg = 20;

struct tree {
	int n;
	vector<vi> gr;
	vi par, h;
	vector<vi> hopp;
	void dfs(int v){
		trav(u, gr[v]) if(u != par[v]){
			par[u] = v;
			h[u] = h[v] + 1;
			dfs(u);
		}
	}
	tree(vector<vi> gr) : gr(gr) {
		n = sz(gr);
		par.resize(n), h.resize(n);
		hopp.resize(lg, vi(n));

		dfs(0);

		hopp[0] = par;
		rep(t,1,lg) rep(i,0,n)
			hopp[t][i] = hopp[t-1][hopp[t-1][i]];
	}
	int jump(int a, int steps){
		for(int i = 0; steps; ++i){
			if(steps&1) a = hopp[i][a];
			steps /= 2;
		}
		return a;
	}
	int lca(int a, int b){
		if(h[a] > h[b]) swap(a,b);
		b = jump(b, h[b] - h[a]);
		if(a == b) return a;
		rrep(i,0,lg){
			int aa = hopp[i][a], bb = hopp[i][b];
			if(aa != bb){
				a = aa, b = bb;
			}
		}
		return par[b];
	}
	int dist(int a, int b){
		int c = lca(a,b);
		return h[a] + h[b] - 2*h[c];
	}
	int closer(int v, int y){
		if(v == y) return v;
		int r = lca(v, y);
		if(y != r) return par[y];
		return jump(v, h[v]-h[y]-1);
	}
};

void noend(){
	cout << -1 << endl;
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n, x, y;
	cin >> n >> x >> y;
	--x, --y;
	vector<vi> gred(n), gblue(n);

	rep(_,0,n-1){
		int a,b;
		cin >> a >> b;
		--a,--b;
		gred[a].push_back(b);
		gred[b].push_back(a);
	}
	rep(_,0,n-1){
		int a,b;
		cin >> a >> b;
		--a,--b;
		gblue[a].push_back(b);
		gblue[b].push_back(a);
	}
	tree blue(gblue);
	int ans = 0;
	vector<bool> vis(n);
	queue<pii> ko;
	ko.push(pii(x, y));
	vis[x] = 1;
	while(!ko.empty()){
		pii pa = ko.front();
		ko.pop();
		ans = max(ans, 2 * blue.dist(pa.first, y));
	//	cout << pa.first+1 << ' ' << pa.second+1 << endl;
		if(pa.first == pa.second) continue;
		trav(x1, gred[pa.first]) if(!vis[x1]){
			if(blue.dist(x1, pa.first) > 2)
				noend();
			vis[x1] = 1;
			ko.push(pii(x1, blue.closer(x1, pa.second)));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 67060
D, G = gets.split.map(&:to_i)
PC = D.times.map { gets.split.map(&:to_i) }

ans = Float::INFINITY

digits = D
max = 2 ** digits - 1
0.upto(max) do |i|
  resolve = 0
  score = 0
  digits.times do |d|
    next if i[d] == 0

    resolve += PC[d][0]
    score += (d + 1) * 100 * PC[d][0] + PC[d][1]
  end

  if score < G
    (digits-1).downto(0) do |d|
      if i[d] == 0
        one_score = (d + 1) * 100
        div, mod = (G - score).divmod(one_score)
        frac_resolve = [div + (mod == 0 ? 0 : 1), PC[d][0] - 1].min

        resolve += frac_resolve
        score += frac_resolve * one_score
        break
      end
    end
  end

  ans = resolve if score >= G && ans > resolve
end

puts ans

Measured memory_bytes: 1788
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAXN 30
#define LL long long int 
using namespace std;
int a[MAXN];
int b[MAXN];
int c[MAXN];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<n;i++)cin>>c[i];
	LL ans=0;
	int cur=-1;
	for(int i=1;i<=n;i++)
	{
		int x=a[i];
		ans+=b[x];
		if(cur==x-1)
			ans+=c[x-1];
		cur=x;
	}
	cout<<ans<<endl;
	return 0;
}

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

long long N, X[1009], Y[1009], H[1009]; vector<tuple<long long, long long, long long>>vec;
 
int main() {
	cin >> N; tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);
	for (int i = 1; i <= N; i++) {
		cin >> X[i] >> Y[i] >> H[i];
		if (H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j); V = max(V, 0LL); bool flag = true;
			for (int k = 1; k <= N; k++) {
				long long VV = V - abs(X[k] - i) - abs(Y[k] - j); VV = max(VV, 0LL);
				if (H[k] != VV) flag = false;
			}
			if (flag == true) vec.push_back(make_tuple(i, j, V));
		}
	}
	if (vec.size() == 1) {
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
	}
	return 0;
} 

Measured memory_bytes: 256
module Main where

import Data.Functor
import Data.List

main :: IO ()
main = do
  { xs <- getInts
  ; putInts (sort xs)
  }
  
getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n, k;
    cin >> n >> k;
    int s = 0;
    for(int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        s += min(abs(k - x), x) * 2;

    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a,b,c;

  scanf("%d",&a); scanf("%d",&b); scanf("%d",&c);
  
  if(a < b) {
    if(b < c)
      printf("Yes\n");
    else
      printf("No\n");
  }
  else
    printf("No\n");

  return(0);
}

Measured memory_bytes: 2680
#include<iostream>
#include<unordered_map>

using namespace std;

int main(){
   long int N;
   unordered_map<string,int> frecsJudge;
   frecsJudge["AC"]=0;
   frecsJudge["WA"]=0;
   frecsJudge["TLE"]=0;
   frecsJudge["RE"]=0;
   cin>>N;
   string judge;
   while(N!=0){  
      cin>>judge;
      frecsJudge[judge] = frecsJudge[judge] + 1;
      N--;
   }
   cout<<"AC x "<<frecsJudge["AC"]<<endl;
   cout<<"WA x "<<frecsJudge["WA"]<<endl;
   cout<<"TLE x "<<frecsJudge["TLE"]<<endl;
   cout<<"RE x "<<frecsJudge["RE"]<<endl;
   return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>

using namespace std;

int main(){
  int N;
  cin >> N;
  for(int i=0; i*4<=N; i++){
    for(int j=0; j*7+i*4<=N; j++){
      if(4*i+j*7==N){
          cout << "Yes" << endl;
          return 0;
      }
    }
  }cout << "No" << endl;
}

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

int main() {
	string a, b; cin >> a >> b;

	int num = stoi(a + b);
	string ans = "No";
	rep(k, 0, num/2) {
		if (k * k == num) {
			ans = "Yes";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    string s; std::cin >> s;
    int slen = s.size();
    if (slen == 2 && s[0] == s[1]) {
        std::cout << "1 2" << "\n";
        return 0;
    }
    rep(i, slen-2) {
        map<int, int> cnt;
        rep(j, 3) cnt[s[i+j]-'a']++;
        if (cnt.size() <= 2) {
            std::cout << i+1 << ' ' << i+3 << "\n";
            return 0;
        }
    }
    std::cout << "-1 -1" << "\n";
}


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

int main()
{
    int n, a;
    cin >> n >> a;
    vector<int> d(n);
    int ans = 0;
    rep(i, n) cin >> d[i];
    rep(i, n)
    {
        if (a <= d[i])
            ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640