akhauriyash/Code-Regression huggingface dataset:
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)

MOD = 10**9 + 7
X, Y = map(int, input().split())
if (X + Y) % 3 != 0: print(0)
else:
    x, y = ((2*X - Y) // 3, (-X + 2*Y) // 3)
    com = Combinatorics(x + y, MOD)
    print(com.binom(x+y, x))

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

int main() {
  double a,b,h,m;cin>>a>>b>>h>>m;
  double angle_h=h*30.0+m*30.0/60.0, angle_m=m*6.0;
  double pi=3.14159265358979323846;
  double angle = angle_h-angle_m;
  if (angle>180.0) angle=360.0-angle;
  double ans=a*a+b*b - 2.0*a*b*(cos(angle*pi/180.0));
  cout << fixed << setprecision(12) <<sqrt(ans) << endl;
}


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

int main() {
  vector<int> v(3);
  for (int i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  cout << v.size() << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		double a = N / 2.0 + 0.5;
		int b = (int)a;
		double ans = (double)b/N;

		System.out.println(ans);
	}

}


Measured memory_bytes: 22740
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
LL dp[2000000+10][2];string s;int t,OK=0;
void SOLL(){
	int len=s.length();
		if(s[0]!=s[len-1]){
//			while(1);
			
			rep(i,len)
		{
			if(i){
			if(s[i]!=s[i-1]){
				dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
				dp[i][1]=dp[i][0]+1;
			}
			else{
				dp[i][0]=dp[i-1][1];
				dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			}
			}
			else{
				dp[i][0]=0;
				dp[i][1]=1;
			}
		}
		cout<<min(dp[len-1][0],dp[len-1][1])*t<<endl;
		}
		else{
		int OK=1;
			rb(i,1,len-1){
				if(s[i]!=s[i-1]) OK=0;
			}
			if(OK){
				cout<<((LL)(len)*t)/2;
				return ;
			}
//			if(t&1) while(1);
//		if(s[0]==s[1]&&s[len-1]==s[len-2]) while(1);
			int tmp;
			rep(i,len)
		{
			if(i){
			if(s[i]!=s[i-1]){
				dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
				dp[i][1]=dp[i][0]+1;
			}
			else{
				dp[i][0]=dp[i-1][1];
				dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			}
			}
			else{
				dp[i][0]=0;
				dp[i][1]=1;
			}
		}
		tmp=min(dp[len-1][0],dp[len-1][1]);
		LL M,N;
		string ss=s;
		s[0]='&';
		rep(i,len)
		{
			if(i){
			if(s[i]!=s[i-1]){
				dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
				dp[i][1]=dp[i][0]+1;
			}
			else{
				dp[i][0]=dp[i-1][1];
				dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			}
			}
			else{
				dp[i][0]=0;
				dp[i][1]=1;
			}
		}
		M=min(dp[len-1][0],dp[len-1][1]);
		M*=(t-1);
		s=ss;
		s[len-1]='&';
		rep(i,len)
		{
			if(i){
			if(s[i]!=s[i-1]){
				dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
				dp[i][1]=dp[i][0]+1;
			}
			else{
				dp[i][0]=dp[i-1][1];
				dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			}
			}
			else{
				dp[i][0]=0;
				dp[i][1]=1;
			}
		}
		N=min(dp[len-1][0],dp[len-1][1]);
		N*=(t-1);
		M=min(N,M);
		M+=t-1;
		M+=tmp;
//		M=min()
		cout<<M<<endl;}
}
void sol(){
	string tmp="";
		rb(i,1,t){
			tmp+=s;
		}
		s=tmp;
		int len=s.length();
		rep(i,len)
		{
			if(i){
			if(s[i]!=s[i-1]){
				dp[i][0]=min(dp[i-1][0],dp[i-1][1]);
				dp[i][1]=dp[i][0]+1;
			}
			else{
				dp[i][0]=dp[i-1][1];
				dp[i][1]=min(dp[i-1][0],dp[i-1][1])+1;
			}
			}
			else{
				dp[i][0]=0;
				dp[i][1]=1;
			}
		}
		cout<<min(dp[len-1][0],dp[len-1][1])<<endl;
}
int main(){
//	freopen("rand.out","r",stdin);
//	freopen("ok.out","w",stdout);
	cin>>s;
	cin>>t;
	if(t<=10000){sol();
	}
	else{
		if(s.length()==1){
			cout<<t;
			return 0;
		}
		if(s.length()==2){
			while(1);
		}
		SOLL();
	}
	return 0;
	
}


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

int main(){
    int N;
    long long mod= 1000000007;
    long long a, b;
    cin >> N;
    a = 2;
    b = 8;
    vector<long long> vec(N + 1);
    vec[0] = 0;
    for (int i = 0; i < N ; i++){
        vec[i + 1] = vec[i] * 10 + a;
        /*cout << vec[i] << " " << a  << " " << b << endl;*/
        vec[i + 1] %= mod;
        a = a * 9 + b * 2;
        a %= mod;
        b *= 8;
        b %= mod;
    }
    cout << vec[N - 1] << endl;
}

Measured memory_bytes: 11012
#include <bits/stdc++.h>
using namespace std;
#define lli long long int


int main () {
	string s;
	lli a,z;
	cin >> s;

	for(lli i=0;i<s.size();i++){
		if(s[i]=='A'){
			a=i;
			break;
		}
		
	}

	for(lli i=s.size()-1;i>-1;i--){
		if(s[i]=='Z'){
			z=i;
			break;
		}
	}

	cout << z-a+1 << endl;

    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    ll K;
    cin >> K;
    ll X = K%50;
    ll Y = K/50;
    cout << 50 << endl;
    REP(i, X){
        cout << 50 + Y << " ";
    }
    REP(i, 50-X){
        cout << (50-X-1) + Y << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
T = [int(i) for i in input().split()]
M = int(input())
PX = [[int(i) for i in input().split()] for i in range(M)]

for i in range(M):
    ans = sum(T) - T[PX[i][0] - 1] + PX[i][1]
    print(ans)


Measured memory_bytes: 3060
MAX = 510000
MOD = 1000000007
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX


def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


def COM(n, k):
    if (n < k):
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


COMinit()

S = int(input())
ans = 0
d = 3

while (d <= S):
    box = d // 3
    ans = (ans + COM(S - d + box - 1, box - 1)) % MOD
    d += 3

print(ans)


Measured memory_bytes: 75788
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll k;
    cin>>k;
    queue<ll> que;
    rep(i,9) que.push(i+1);
    ll cnt=1;
    ll ans;
    while(cnt<=k){
        ll v=que.front();
        que.pop();
        if(cnt==k){
            ans=v;
            //break;
        }
        ll z=v%10;
        if(v%10!=0) que.push(10*v-1+z);
        que.push(10*v+z);
        if(v%10!=9) que.push(10*v+1+z);
        cnt++;
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
*/

Measured memory_bytes: 1792
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int kenCount = sc.nextInt();
			int shiCount = sc.nextInt();
			int i = 0;
			// Shi[] list = new Shi[shiCount];
			List<Shi> list = new ArrayList<>();
			while (i < shiCount) {
				Shi shi = new Shi();
				shi.idx = i;
				shi.ken = sc.nextInt();
				shi.year = sc.nextInt();
				list.add(shi);
				i++;
			}
			Collections.sort(list, (o1, o2) -> {
				if (o1.ken == o2.ken) {
					return o1.year - o2.year;
				}
				return o1.ken - o2.ken;
			});

			String[] answers = new String[shiCount];

			int[] seq = new int[kenCount + 1];
			for (Shi shi : list) {
				int ken = shi.ken;
				seq[ken]++;
				shi.birthNum = seq[ken];
				answers[shi.idx] = shi.getNumberStr();
			}

			for (String ans : answers) {
				System.out.println(ans);
			}
		}
	}

	private static class Shi {
		private int idx = 0;
		private int ken = 0;
		private int year = 0;
		private int birthNum = -1;

		private String getNumberStr() {
			return zero(ken) + zero(birthNum);
		}

		private String zero(int num) {
			String str = String.valueOf(num);
			switch (str.length()) {
			case 1:
				return "00000" + str;
			case 2:
				return "0000" + str;
			case 3:
				return "000" + str;
			case 4:
				return "00" + str;
			case 5:
				return "0" + str;
			case 6:
				return str;
			}
			return str;
		}
	}
}

Measured memory_bytes: 105004
/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "text.out"
#define FILE_OUT "result.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define bi BigInt
#define pi 3.1415926535897
typedef long long ll;
//------------xúc xích normie tám muoi tám phan tram não----------//
ll n,m,k,c[1001],t,t1,i,j,minn,maxx,cur,lu,lv;
ll dist[100001];
vector<pll> gt[100001];
void dfs(ll x, ll d)
{
	dist[x]=d;
	for (pll pp: gt[x])
	if (dist[pp.fi]==1e10) dfs(pp.fi,d+pp.se);
	else 
	if (dist[pp.fi]!=d+pp.se) {
		cout<<"No";
		exit(0);
	}
}
int main() {
//	ofile;
	fio;
	cin>>n>>m;
	for (i=1;i<=m;i++)
	{
		cin>>lu>>lv>>t;
		gt[lu].push_back({lv,t});
		gt[lv].push_back({lu,-t});
	}
	for (i=1;i<=n;i++) dist[i]=1e10;
	for (i=1;i<=n;i++) if (dist[i]==1e10)
	dfs(i,0);
	cout<<"Yes";
}


Measured memory_bytes: 19676
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    double h,a;
    cin >> h >> a;
    cout << ceil(h/a) << endl;
    return 0;

}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v;
  int input;
  int ttl = 0;
  rep (i, N) {
    cin >> input;
    if (input < abs(input - K)) {
      ttl += input * 2;
    } else {
      ttl += abs(input - K) * 2;
    }
  }
  cout << ttl << endl;
}


Measured memory_bytes: 3624
k, x = map(int, input().split())

L = - (10 ** 6)
H = 10 ** 6

ans_L = max(L, x - k + 1)
ans_H = min(H, x + k - 1)

ans = []
for i in range(ans_L, ans_H + 1):
    ans.append(str(i))

print(' '.join(ans))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
	string S;
	cin >> S;

	int N = S.size();
	
	int cnt = 0;
	int tmp[26];
	memset(tmp, 0, sizeof tmp);
	rep(i, N) {
		tmp[S[i] - 'a']++;
		cnt += tmp[S[i] - 'a'];
	}

	int ret = 0;
	rep(i, N) {
		ret += N - i;
	}
	ret -= cnt;
	ret++;

	cout << ret << endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<long> a(n+1);
  rep(i, n+1) cin >> a[i];
  vector<long> b(n+1);
  rep(i, n) cin >> b[i];
  b[n] = 0;
  
  long c;
  c=0;
  rep(i, n+1) {
    long l = min(a[i], b[i]);
   	c += l;
    long r = min(a[i+1], b[i]-l);
    c += r;
    a[i+1] -= r;
    b[i] -= r;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.*;
public class Main {
     public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer s = new StringTokenizer(br.readLine()," ");
	int input1 = Integer.parseInt(s.nextToken());
	int input2 = Integer.parseInt(s.nextToken());

	if(input1<input2){
	System.out.println("a < b");
	}else if (input1 == input2){
	System.out.println("a == b");
	}else{
	System.out.println("a > b");
	}
    }
}

Measured memory_bytes: 24292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 2e5 + 55;

int k, n;
ll a[maxN + maxN];

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

    cin >> k >> n;

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

    for(int i = n; i < n + n; i++) {
        a[i] = a[i - n] + k;
    }

    ll ans = 1e18;

    for(int i = 0; i + n - 1 < n + n; i++) {
        ans = min(ans, a[i + n - 1] - a[i]);
    }

    cout << ans << '\n';

    return 0;
}


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}


struct UnionFind{
    vector<int> par;

    UnionFind(int n): par(n){
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int root(int i){
        if(par[i] == i) return i;
        else return par[i] = root(par[i]);
    }

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx != ry){
            par[rx] = ry;
        }
    }

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

// 二つの球の最短距離
// 中心の距離 - 半径の和
// すなわち、負数も取りうる
double dis_two_sphere(double x1, double y1, double z1, double r1, double x2, double y2, double z2, double r2){
    double d_sq = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2);
    return sqrt(d_sq) - (r1+r2);
}
signed main(){
    cout << fixed << setprecision(3) << flush;

    int n;
    cin >> n;
    vector<double> ans;
    while(n != 0){
        vector<double> x(n), y(n), z(n), r(n);
        for(int i=0; i<n; i++){
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }

        UnionFind uf(n);
        // 距離を求めて小さい順に並べる
        vector<tuple<double, int, int>> dis; // 距離, i, j (i < j)
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                double d = dis_two_sphere(x[i], y[i], z[i], r[i], x[j], y[j], z[j], r[j]);
                // くっついてるやつをつなげる
                if(d < 0.0){
                    uf.unite(i, j);
                }
                else{
                    dis.push_back(make_tuple(d, i, j));
                }
            }
        }
        sort(dis.begin(), dis.end());

        // Kruskal
        double res = 0.0;
        for(int i=0; i<dis.size(); i++){
            double d = get<0>(dis[i]);
            int a = get<1>(dis[i]);
            int b = get<2>(dis[i]);
            if(!uf.same(a, b)){
                uf.unite(a, b);
                res += d;
            }
        }

        ans.push_back(res);
        cin >> n;
    }

    for(int i=0; i<ans.size(); i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3404
#include <cstdio>
#include <cmath>

char memo[2*123456+1] = { 2, 1, 1, };

bool is_prime(int n) {
  if (!memo[n]) {
    if (n%2 == 0) memo[n] = 2;
    else {
      for (int x=3;x<=(int)sqrt(n);x+=2) {
        if (n%x == 0) {
          memo[n] = 2;
          break;
        }
      }
      if (!memo[n]) memo[n] = 1;
    }
  }
  return (memo[n] == 1);
}

int main() {
  while (true) {
    int n;
    scanf("%d", &n);
    if (n == 0) break;
    int cnt = 0;
    for (int x=n+1;x<=2*n;x++) {
      if (is_prime(x)) cnt++;
    }
    printf("%d\n", cnt);
  }
  return 0;
}

Measured memory_bytes: 2956
#include <cstdio> 
#define MAXN 2005
#define ll long long
#define INF -999999999999999999
struct edge {
	int from, to, cost;
}a[MAXN];

ll dist[MAXN];

int main() {
	ll n, m, cnt = 0, ans = 0;
	bool flag;
	scanf("%lld%lld", &n, &m);
	for(int i = 1; i <= m; i++) 
		scanf("%lld%lld%lld", &a[i].from, &a[i].to, &a[i].cost);
	
	for(int i = 1; i <= n; i++)	dist[i] = INF;
	dist[1] = 0;
	while(1) {
		flag = false;
		for(int i = 1; i <= m; i++) {
			if(dist[a[i].from] != INF && dist[a[i].to] < dist[a[i].from] + a[i].cost) {
				dist[a[i].to] = dist[a[i].from] + a[i].cost;
				flag = true;
			}	
		}
		if(!flag || cnt > m)
			break;
		cnt++;
	}
	ans = dist[n];
	while(1) {
		flag = false;
		for(int i = 1; i <= m; i++) {
			if(dist[a[i].from] != INF && dist[a[i].to] < dist[a[i].from] + a[i].cost) {
				dist[a[i].to] = dist[a[i].from] + a[i].cost;
				flag = true;
			}	
		}
		if(!flag || cnt > m)
			break;
		cnt++;
	}
	if(dist[n]==ans)
		printf("%lld", dist[n]);
	else
		printf("inf\n");
	return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> X(N), Y(N);
  for(int i = 0; i < N; ++i){
    cin >> X[i] >> Y[i];
  }
  long long ans = 4e18;
  for(int i = 0; i < N; ++i){
    for(int j = 0; j <= i; ++j){
      for(int k = 0; k <= j; ++k){
        for(int l = 0; l <= k; ++l){
          long long Mx = max({X[i],X[j],X[k],X[l]}), mx = min({X[i],X[j],X[k],X[l]}), My = max({Y[i],Y[j],Y[k],Y[l]}), my = min({Y[i],Y[j],Y[k],Y[l]});
          if(ans <= (Mx-mx)*(My-my)) continue;
          int c = 0;
          for(int m = 0; m < N; ++m){
            int x = X[m], y = Y[m];
            if(x >= mx and x <= Mx and y >= my and y <= My) ++c;
            if(c >= K) break;
          }
          if(c >= K) ans = (Mx-mx)*(My-my);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int n,a,b,c,d;
string s;

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

int ok(int x)
{
	return s[x]=='.'&&x!=a&&x!=b;
}

void gob();

void goa()
{
	if(ok(a+1))
	{
		a++;
		if(a>c) NO(); 
		return;
	}
	if(ok(a+2)&&a+2<=c)
	{
		a+=2; 
		if(a>c) NO();
		return;
	}
	if(b==a+1||b==a+2) gob();
	if(ok(a+1))
	{
		a++; 
		if(a>c) NO();
		return;
	}
	if(ok(a+2))
	{
		a+=2; 
		if(a>c) NO();
		return;
	}
	NO();
}

void gob()
{
	if(ok(b+1))
	{
		b++; 
		if(b>d) NO();
		return;
	}
	if(ok(b+2)&&b+2<=d)
	{
		b+=2; 
		if(b>d) NO();
		return;
	}
	if(a==b+1||a==b+2) goa();
	if(ok(b+1))
	{
		b++;
		if(b>d) NO();
		return;
	}
	if(ok(b+2))
	{
		b+=2;
		if(b>d) NO();
		return;
	}
	NO();
}


int main()
{
	cin >> n >> a >> b >> c >> d;
	cin >> s;
	a--; b--; c--; d--;
	if(c<d)
	{
		swap(a,b);
		swap(c,d);
	}
	while(a!=c)
	{
		goa();
	}
	while(b!=d)
	{
		gob();
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int n,q,t;
    cin>>n>>q;
    string c="kogakubu10gokan";
    while(n--){
        cin>>t;
        if(t>q){
            cout<<c<<endl;
            return 0;
        }
        cin>>c;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
//#define LOCAL
using namespace std;
typedef long long ll;
const int mx=1e5+10;
ll num[mx];
typedef struct pp{
    ll x, y;
}Point;
Point po[mx];

bool cmp(const Point &a, const Point &b){
    if(a.x==b.x){
        return a.y<b.y;
    }
    return a.x<b.x;
}

int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n;
cin>>n;
for(ll i=0;i<n;i++){
    cin>>po[i].x>>po[i].y;
}
sort(po, po+n, cmp);
for(ll i=0;i<n;i++){
    printf("%lld %lld\n", po[i].x, po[i].y);
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}




Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }//最初は全て-1 :-1なら根なので全て根:木のサイズが増えると-2-3-4となる
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);//両方のルートを出して、それをつなげる
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }

  bool findSet(int x, int y) {//要素xとyが同じ集合か　→　rootを調べれば解決
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);//-1なら根、そうでないなら配列が指す場所へ移動
  }
  int size(int x) {
    return -data[root(x)];
  }
};




int main() {
  ll n, m;
  cin >> n >> m;

  vector<ll> p(n+10);
  for(int i=1;i<n+1;i++){
    cin >> p[i];
  }

  vector<ll> x(m+10);
  vector<ll> y(m+10);

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i];
  }


  ll ans = 0;
  // p は数列

  struct UnionFind uftree1(n+10);//全部で1  -  n


  for (int i = 0; i < m; i++) {
    uftree1.unionSet(p[x[i]], p[ y[i] ]);
  }


  for(auto v: uftree1.data){
    cerr << v << ",";
  }cerr <<endl <<endl;

  for(int i =n;i >0;i--){
    if (  uftree1.findSet(p[p[i]], p[i])  ){
      cerr << p[i] << ",";
      ans++;
    }
  }
  cerr <<endl;






  cout << ans << endl;


}




















Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Life Line
public class Main{

	class R{
		Set<Integer> s, empty;
		public R() {
			s = new HashSet<Integer>();
			empty = new HashSet<Integer>();
		}
	}
	
	int N, C, n, max;
	int[] map, depth;
	boolean[] top, bottom, left, right;
	boolean[] u;

	R bfs(int focus, int i){
		R res = new R();
		List<Integer> list = new ArrayList<Integer>();
		list.add(i);
		u[i] = true;
		while(!list.isEmpty()){
			List<Integer> next = new ArrayList<Integer>();
			for(int j:list){
				if(map[j]==0){
					res.empty.add(j); continue;
				}
				res.s.add(j);
				int d = depth[j];
				if(!top[j]&&!left[j]&&!u[j-d]&&(map[j-d]==0||map[j-d]==focus)){
					if(map[j-d]==focus)u[j-d] = true;
					next.add(j-d);
				}
				if(!top[j]&&!right[j]&&!u[j-d+1]&&(map[j-d+1]==0||map[j-d+1]==focus)){
					if(map[j-d+1]==focus)u[j-d+1] = true;
					next.add(j-d+1);
				}
				if(!left[j]&&!u[j-1]&&(map[j-1]==0||map[j-1]==focus)){
					if(map[j-1]==focus)u[j-1] = true;
					next.add(j-1);
				}
				if(!right[j]&&!u[j+1]&&(map[j+1]==0||map[j+1]==focus)){
					if(map[j+1]==focus)u[j+1] = true;
					next.add(j+1);
				}
				if(!bottom[j]&&!u[j+d]&&(map[j+d]==0||map[j+d]==focus)){
					if(map[j+d]==focus)u[j+d] = true;
					next.add(j+d);
				}
				if(!bottom[j]&&!u[j+d+1]&&(map[j+d+1]==0||map[j+d+1]==focus)){
					if(map[j+d+1]==focus)u[j+d+1] = true;
					next.add(j+d+1);
				}
			}
			list = next;
		}
		return res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			N = sc.nextInt(); C = sc.nextInt();
			if((N|C)==0)break;
			n = N*(N+1)/2;
			map = new int[n]; depth = new int[n];
			top = new boolean[n]; bottom = new boolean[n]; left = new boolean[n]; right = new boolean[n];
			int d = 1, k = 0;
			for(int i=0;i<n;i++){
				map[i] = sc.nextInt();
				depth[i] = d;
				top[i] = d==1; bottom[i] = d==N;
				left[i] = k==0; right[i] = k==d-1;
				k++;
				if(k==d){
					k = 0; d++;
				}
			}
			u = new boolean[n];
			List<R> l = new ArrayList<R>();
			for(int i=0;i<n;i++){
				if(u[i]||map[i]==C||map[i]==0)continue;
				l.add(bfs(map[i], i));
			}
			int max = -n;
			for(int i=0;i<n;i++){
				if(map[i]!=0)continue;
				map[i] = C;
				List<R> mine = new ArrayList<R>();
				u = new boolean[n];
				for(int j=0;j<n;j++){
					if(u[j]||map[j]!=C)continue;
					mine.add(bfs(C, j));
				}
				int p = 0;
				for(R r:l)if(r.empty.size()==1&&r.empty.contains(i))p+=r.s.size();
				for(R r:mine)if(r.empty.isEmpty())p-=r.s.size();
				max = Math.max(max, p);
				map[i] = 0;
			}
			System.out.println(max);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for i in range(N-1):
  dif = H[i+1] - H[i]
  if dif <= -2:
    ans = "No"
  elif dif == -1:
    H[i+1] += 1
print(ans)

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test int t;cin>>t;while(t--)

signed main(){
    fast

    string s;
    cin>>s;int c=0,max=0;
    f0(i,0,s.length())
    {if(s[i]=='R')c++;
    else c=0;
    if(c>max)max=c;
    
        
    }cout<<max;
}

Measured memory_bytes: 3648
#include <cstring>
#include <cstdio>
#include <algorithm>
const int MAXN = 100010;
using namespace std;

int N, A[MAXN];

inline bool greaterInt(int x, int y) { return x > y; }
inline bool out(int x, int y) { return x > N - 1 || y >= A[x]; }
int main() {
	int i;
	scanf("%d", &N);
	for(i = 0; i < N; i++) scanf("%d", &A[i]);
	sort(A, A + N, greaterInt);

	int x = 0, y = 0;
	while(!out(x, y)) x++, y++;
	x--, y--;

	int lx = 0, ly = 0;
	while(!out(x + lx, y)) lx++;
	while(!out(x, y + ly)) ly++;

	bool lose = ((lx & 1) == 1) && ((ly & 1) == 1);
	printf(lose ? "Second" : "First");
	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		char[] cs = sc.next().toCharArray();
		for(char c :cs) {
			switch(c) {
			case '1': sb.append(c);
			break;
			case '0': sb.append(c);
			break;
			case 'B':
				if (sb.length() > 0) {
					sb.deleteCharAt(sb.length() - 1);
				}
			break;
			}
		}
		System.out.println(sb);

	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,y,t,f;
int main(){
    while(1){
        f=0;
        t=0;
        d=0;
        cin>>a;
        if(a==0)return 0;
        for(y=1;y<13;y++){
            cin>>b>>c;
            d+=b-c;
            if(y==12&&d<a){t=13;}
            if(d>=a&&f==0){t=y;f++;}
        }
        if(t==13){cout<<"NA"<<endl;}else
                 {cout<<t<<endl; }
    }




}

Measured memory_bytes: 2992
s = input()

if len(s) != 26:
    se = set([])
    for w in s:
        se.add(w)

    for i in range(26):
        w = chr(ord('a')+i)
        if w not in se:
            print(s + w)
            exit()

if s == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    exit()

se = set([])
for i in reversed(range(26)):
    se.add(s[i])
    for j in range(ord(s[i])-ord('a')+1, 26):
        if chr(ord('a')+j) in se:
            print(s[:i]+chr(ord('a')+j))
            exit()



Measured memory_bytes: 3064
import math
n=int(input(""))
mk=n//3
s=0
kaizyou=1
for i in range(1,mk+1):
    t=1
    
    a=math.factorial(i-1)
    for k in range(i-1):
        t*=(n-2*i-1-k)
        t%=a*(10**9+7)
        
            
    t/=a
    t%=(10**9+7)
    
    s+=t
    s%=(10**9+7)
print(int(s))

    

Measured memory_bytes: 9204
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val s = readString()
    if (s[2] == s[3] && s[4] == s[5]) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 34316
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

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

int main(){
    int h, w, K, sx, sy, gx, gy;
    scanf("%d%d%d%d%d%d%d", &h, &w, &K, &sx, &sy, &gx, &gy);
    --sx; --sy; --gx; --gy;
    char c[h][w];
    rep(i, h)rep(j, w) scanf(" %c", &c[i][j]);

    int d[h][w];
    queue<pii> que;
    rep(i, h)rep(j, w) d[i][j] = mod;
    d[sx][sy] = 0;
    que.emplace(sx, sy);
    while(!que.empty()){
        auto [x, y] = que.front();
        que.pop();
        rep(i, 4){
            For(k, 1, K+1){
                int nx = x + dx[i]*k, ny = y + dy[i]*k;
                if(nx<0 || h<=nx || ny<0 || w<=ny || c[nx][ny] != '.' || d[nx][ny] <= d[x][y]) break;
                if(chmin(d[nx][ny], d[x][y] + 1)) que.emplace(nx, ny);
            }
        }
    }
    printf("%d\n", d[gx][gy] < mod ? d[gx][gy] : -1);
}

Measured memory_bytes: 9224
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

type Point struct {
	x float64
	y float64
}

func (p *Point) print() {
	fmt.Printf("%.8f %.8f\n", p.x, p.y)

}

func koch(d int, start, end Point) {
	if d == 0 {
		return
	}

	s := Point{}
	t := Point{}
	u := Point{}

	s.x = (2.0*start.x + 1.0*end.x) / 3.0
	s.y = (2.0*start.y + 1.0*end.y) / 3.0
	t.x = (1.0*start.x + 2.0*end.x) / 3.0
	t.y = (1.0*start.y + 2.0*end.y) / 3.0
	u.x = (t.x-s.x)*math.Cos(math.Pi*60/180) - (t.y-s.y)*math.Sin(math.Pi*60/180) + s.x
	u.y = (t.x-s.x)*math.Sin(math.Pi*60/180) + (t.y-s.y)*math.Cos(math.Pi*60/180) + s.y

	koch(d-1, start, s)
	s.print()
	koch(d-1, s, u)
	u.print()
	koch(d-1, u, t)
	t.print()
	koch(d-1, t, end)

}

func main() {
	n := scanInt()
	start := Point{x: 0.0, y: 0.0}
	end := Point{x: 100.0, y: 0.0}

	start.print()
	koch(n, start, end)
	end.print()
}



Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n,t;cin>>n>>t;
    vector<P> T(n);
    ll MAX=0;
    rep(i,n){
        cin>>T[i].fi>>T[i].se;
        chmax(MAX,T[i].fi);
    }
    sort(T.begin(),T.end());

    //i-1番目の料理まで選択可能 時間がj分以内　この時のmax
    vector<vector<ll>> dp(3010,vector<ll>(6010,-1));
    dp[0][0]=0;

    rep(i,n){
        rep(j,t){
            if(dp[i][j]==-1) continue;
            
            //i番目を食べるとき
            chmax(dp[i+1][j+T[i].fi],dp[i][j]+T[i].se);
        
            //i番目を食べないとき
            chmax(dp[i+1][j],dp[i][j]);
        }
    }

    ll ans=0;
    rep(i,3010){
        rep(j,6010){
            chmax(ans,dp[i][j]);
        }
    }

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

Measured memory_bytes: 144748
#include<bits/stdc++.h>
using namespace std;
bool b[710][710];
struct EDGE{
	int u, v;
	int Next;
}G[1000010];
int Head[710];
int tot = 0;
inline void Add(int u, int v)
{
	++ tot;
	G[tot].u = u;
	G[tot].v = v;
	G[tot].Next = Head[u];
	Head[u] = tot;
}
int color[710];
int x[710], y[710], top;
inline bool DFS(int u)
{
	for(int i = Head[u]; i; i = G[i].Next)
	{
		int v = G[i].v;
		if(color[v] == color[u])
			return false;
			
		if(color[v] == -1)
		{
			color[v] = 1 - color[u];
			if(color[u] == 1)
				++ y[top];
			else
				++ x[top];
			if(! DFS(v))
				return false;
		}
	}
	return true;
}
bool dp[710][2810];
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		b[u][v] = b[v][u] = true;
	}
	for(int i = 1; i <= n; ++ i)
		for(int j = 1; j <= n; ++ j)
			if(! b[i][j] && i != j)
				Add(i, j);
	memset(color, -1, sizeof(color));
	for(int i = 1; i <= n; ++ i)
		if(color[i] == -1)
		{
			color[i] = 1;
			++ top;
			x[top] = 1;
			if(! DFS(i))
			{
				printf("-1");
				return 0;
			}
		}
	dp[0][1400] = true;
	for(int i = 1; i <= top; ++ i)
		for(int j = - n; j <= n; ++ j)
			if(dp[i - 1][j - (x[i] - y[i]) + 1400] || dp[i - 1][j - (y[i] - x[i]) + 1400])
				dp[i][j + 1400] = true;
	int Min = 2147483647;
	for(int i = - n; i <= n; ++ i)
		if(dp[top][i + 1400])
			Min = min(Min, abs(i));
	int a = (n + Min) / 2;
	int b = (n - Min) / 2;
	if(a == 0 || b == 0)
		printf("-1");
	else
		printf("%d", a * (a - 1) / 2 + b * (b - 1) / 2);
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7') cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

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

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

const int INF = 1001001001;
const double EPS = 1e-10;

int main()
{
    int n;
    while(scanf("%d%*c", &n), n){
        char line[2048];
        map<string, int> dict;
        rep(i, n){
            fgets(line, sizeof(line), stdin);
            stringstream sstr(line);
            for(string word; sstr >> word;)
                dict[word]--;
        }

        vector<pair<int, string> > a;
        scanf("%s", line);
        for(map<string, int>::iterator itr=dict.begin(); itr!=dict.end(); ++itr){
            if(itr->first[0] == line[0])
                a.push_back(make_pair(itr->second, itr->first));
        }
        if(a.empty())
            puts("NA");
        else{
            sort(a.begin(), a.end());
            rep(i, min(5, (int)a.size()))
                printf("%s%s", i ? " " : "", a[i].second.c_str());
            puts("");
        }
    }
    return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

ll amari(ll a){
    if(abs(a) % 2 == 0) return 0;
    else return 1;
}

ll sho(ll a){
    if(a<0 && amari(a)==1) return (a / (-2)) + 1;
    else return a / (-2);
}

stack<char> base_min2(ll a){
    stack<char> res;
    if(a == 0){
        res.push('0');
        return res;
    }
    while(true){
        if(a == 1){
            res.push('1');
            break;
        }
        else{
            if(amari(a) == 1){
                res.push('1');
                a = sho(a);
            }
            else if(amari(a) == 0){
                res.push('0');
                a = sho(a);
            }
        }
    }
    return res;
}

int main(void){
    ll n;
    cin >> n;
    stack<char> ans = base_min2(n);
    while(!ans.empty()){
        cout << ans.top();
        ans.pop();
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int in;
    cin>>in;
    int a,b,c,d;
    a=in/500;
    b=in%500;
    c=b/5;
    a=a*1000;
    c=c*5;
    d=a+c;
    
    cout<<d<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
bc = []
for i in range(M):
  bc.append(list(map(int,input().split())))
 
bc.sort(key=lambda x:x[1],reverse=True)
nbc=[0]*N
inde=0
for i in range(M):
  for j in range(bc[i][0]):
    if inde <= N-1:
      nbc[inde] = bc[i][1]
      inde += 1
      if inde == N:
        break
  if inde == N:
    break
  
ind = N
for i in range(N):
  if A[i] >= nbc[i]:
    ind = i
    break
 
print(sum(nbc[:ind])+sum(A[ind:]))

Measured memory_bytes: 32972
N, K = map(int, input().split())
A = list(map(int, input().split()))

N_0 = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            N_0 += 1
            
N_1 = 0
for i in range(N):
    for j in range(i+1, N):
        if A[i] < A[j]:
            N_1 += 1
            
ans = N_0*(K*(K+1)//2) + N_1*((K-1)*K//2)
print(ans % (10**9+7))

Measured memory_bytes: 9248
# coding: utf-8

#問題文
#12 月 30 日の M 時から次の年になるまでは何時間か、求めてください。
#
#制約
#1≦M≦23
#入力は全て整数
#
#入力は以下の形式で標準入力から与えられる。
#M
#
#出力
#12 月 30 日の M 時から次の年になるまでが x 時間のとき、x を出力せよ。
two_day_hour = 48
current_hour = int(input())
print(two_day_hour - current_hour)

Measured memory_bytes: 2940
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits//stdc++.h>

using namespace std;

long long h[1000001] ;

int main()
{
    long long n, k ;
    long long a ;
    cin >> n >> k ;
    a = 0 ;
    
    for ( int i = 0 ; i < n ; i++ )
    {
        
        cin >> h[i] ;
        
    }
    
    sort ( h, h+n ) ;
    
    for ( int i = 0 ; i < ( n - k ) ; i++ )
    {
        
        a = a + h[i] ;
        
    }
    
    cout << a ;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

inline bool
fail(const int64_t k, const int64_t a, const int64_t b,
     const vector<int64_t> & xs)
{
  const auto d = a - b;

  int64_t s = 0;
  for(const auto i: xs)
    if(b * k < i)
    {
      s += (i - b * k + d - 1) / d;
      if(k < s) break;
    }

  return k < s;
}

int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  size_t n;
  int64_t a, b;
  cin >> n >> a >> b;
  vector<int64_t> xs(n);
  cin >> xs;

  int64_t lb = 0, ub = 1;
  while(fail(ub, a, b, xs))
  {
    lb = ub;
    ub *= 2;
  }

  while(lb + 1 < ub)
  {
    const auto k = (lb + ub) >> 1;
    (fail(k, a, b, xs) ? lb : ub) = k;
  }

  cout << ub;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

long long s[200005], ans = 0;
int a[200005], n, cnt = 0;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        s[i] = s[i - 1] + a[i];
    }
    s[0] = 0;
    sort(s, s + 1 + n);
    int i = 1;
    while (i <= n)
    {
        while (i <= n && s[i] == s[i - 1])
        {
            cnt++;
            ans += cnt;
            i++;
        }
        i++;
        cnt = 0;
    }
    printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 2560
s = input().strip()
k = int(input())

ans = ''
for _s in s[:-1]:
  if _s == 'a':
    ans += 'a'
  elif 26 - ord(_s) + ord('a') <= k:
    ans += 'a'
    k -= 26 - ord(_s) + ord('a')
  else:
    ans += _s

ans += chr(ord('a') + (ord(s[-1]) - ord('a') + k) % 26)

print(ans)


Measured memory_bytes: 3444
#include <stdio.h>
int main()
{
    char ch;
    for(int i = 0; i < 2; i++)
    {
        scanf("%c", &ch);
        if(ch == '9')
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < 21; i++) {
		int sum = 1 + i * (a - 1);
		//cout << sum << endl;
		if (sum >= b) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   string s;
   cin >> s;
   if (s[0] == '9' || s[1] == '9') cout << "Yes" << endl;
   else cout << "No" << endl;

   return 0;
}


Measured memory_bytes: 256