akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

ll N, K;
vector<ll> a, f;

bool pos(ll t) {
	ll sets = 0;
	// cout << "t: " << t << "\n";
	
	for (int i = 0; i < N; i++) {
		sets += max(0ll, (ll)ceil((double)(a[i] * f[i] - t) / (double)f[i]));
	}
	
	// cout << "sets: " << sets << "\n";
	// cout << "\n";
	return (sets <= K);
}

ll bsearch(ll l, ll r) {
	if (l == r) return l;
	if (l + 1 == r) {
		if (pos(l)) return l;
		return r;
	}
	ll m = (l + r) / 2;
	if (pos(m)) return bsearch(l, m);
	else return bsearch(m + 1, r);
}

void solve() {
    cin >> N >> K;
    a.resize(N), f.resize(N);
    for (auto& i : a) cin >> i;
    for (auto& i : f) cin >> i;
    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());
	cout << bsearch(0, 1e18);
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
#define int ll
const int N = 2e5 + 10, INF = 1e9 + 10, M = 1e9 + 7;

int n;
struct ModInt {
	int x;
	ModInt () {
		x = 0;
	}
	ModInt (int x) {
		this->x = x % M;
	}
};

ModInt operator*(ModInt a, ModInt b) {
	return ModInt((a.x * b.x) % M);
}

ModInt operator+(ModInt a, ModInt b) {
	return ModInt((a.x + b.x) % M);
}

ModInt operator-(ModInt a, ModInt b) {
	return ModInt((a.x - b.x + M) % M);
}

ModInt binpow(ModInt a, int p) {
	if (p == 0) {
		return 1;
	}
	if (p == 1) {
		return a;
	}
	if (p & 1) {
		return a * binpow(a, p ^ 1);
	} else {
		ModInt x = binpow(a, p >> 1);
		return x * x;
	}
}

ModInt inv(ModInt a) {
	return binpow(a, M - 2);
}

ModInt operator/(ModInt a, ModInt b) {
	return a * inv(b);
}

ModInt fact[N * 2];

void precalc() {
	fact[0] = 1;
	for (int i = 1; i < N * 2; ++i) {
		fact[i] = fact[i - 1] * i;
	}
}
ModInt C(int n, int k) {
	return fact[n] / (fact[n - k] * fact[k]);
}

ModInt C_(int n, int k) {
	return C(n + k - 1, k);
}


struct Kek {
	int sz;
	ModInt cnt;
	Kek () {
		cnt.x = sz = 0;
	}
	Kek(int sz, ModInt cnt) {
		this->sz = sz;
		this->cnt = cnt;
	}
};

Kek merge(Kek a, Kek b) {
	return Kek(a.sz + b.sz, C_(a.sz + 1, b.sz) * a.cnt * b.cnt);
}

Kek dp[N];
vector <int> g[N];

void dfs(int v, int p = -1) {
	bool b = false;
	dp[v] = Kek();
	for (auto to : g[v]) {
		if (to == p) continue;
		dfs(to, v);
		if (b) {
			dp[v] = merge(dp[v], dp[to]);
		} else {
			b = true;
			dp[v] = dp[to];
		}
	}
	if (!b) {
		dp[v] = Kek(1, 1);
	} else {
		++dp[v].sz;
	}
}

void lol(int v, int p = -1) {
	if (p != -1) {
		Kek y;
		if (SZ(g[p]) == 1) {
			y = Kek(1, 1);
		} else {
			int sz = n - dp[v].sz;
			ModInt cnt = dp[p].cnt / (C_(dp[v].sz + 1, sz - 1) * dp[v].cnt);
			y = Kek(sz, cnt);
		}
		--dp[v].sz;
		dp[v] = merge(dp[v], y);
		++dp[v].sz;
	}
	for (auto to : g[v]) {
		if (to == p) continue;
		lol(to, v);
	}
}

void solve() {
	cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1);
	lol(1);
	for (int i = 1; i <= n; ++i) {
		cout << dp[i].cnt.x << endl;
	}
}
 
signed main () {
	precalc();
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
  	while (t--) solve();
    return 0;
}

Measured memory_bytes: 20976
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int N, M;
int a[100000], b[100000];
pair<int, int> c[100000];

int main() {
  cin >> N >> M;
  rep(i, N) {
    cin >> c[i].second >> c[i].first;
    c[i].second = M - c[i].second;
  }

  sort(c,c+N);
  vector<int> v;
  rep(i, M) {
    v.push_back(i);
  }
  int ans = 0;
  for(int i = N-1; i >= 0; i--) {
    int temp = c[i].first;
    int key = c[i].second;
    int r = upper_bound(v.begin(), v.end(), key) - v.begin();
    if(r == 0) continue;
    v.erase(upper_bound(v.begin(), v.end(), key)-1);
    ans += temp;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4632
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;

bool lessX(const P &left,const P &right){
        return (left.first-left.second)<(right.first-right.second);
    }
    
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> plus,minus; 
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int minv=0,total=0;
        for(int j=0;j<(int)s.size();j++){
            if(s[j]=='('){
                total++;
            }
            else{
                total--;
            }
            minv=min(minv,total);
        }
        if(total>0){
            plus.emplace_back(minv,total);
        }
        else{
            minus.emplace_back(minv,total);
        }
    }

    

    sort(plus.begin(),plus.end());
    reverse(plus.begin(),plus.end());

    sort(minus.begin(),minus.end(),lessX);

    bool judge=true;
    int sum=0;
    for(int i=0;i<(int)plus.size();i++){
        int x=sum+plus[i].first;
        if(x<0){
            judge=false;
        }
        sum+=plus[i].second;
    }
    for(int i=0;i<(int)minus.size();i++){
        int x=sum+minus[i].first;
        if(x<0){
            judge=false;
        }
        sum+=minus[i].second;
    }

    if(sum!=0){
        judge=false;
    }

    cout<<(judge?"Yes":"No")<<endl;
}

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

int main(void)
{
  int h, w, i, j;
  while(1) {
    cin >> h >> w;
    if(h == 0 && w ==0) break;
    for(i = 0; i < h; i++){
      for(j = 0; j < w; j++) cout << "#";
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)


void solve(int n) {
  vector<int> v;
  for(int s = 1; s <= n-1; s++) {
    v.push_back(s*s%n);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());

  int cnt[10001];
  fill(cnt, cnt+(n-1)/2+1, 0);
  rep(b, v.size()) {
    rep(a, v.size()) {
      if(a == b) continue;
      int k = v[b] - v[a];
      if(k < 0) k += n;
      if(k > (n-1)/2) k = n - k;
      cnt[k]++;
    }
  }
  for(int i = 1; i <= (n-1)/2; i++) cout << cnt[i] << endl;
}

main() {
  int n;
  while((cin >> n) && n) solve(n);
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define f first
#define s second
#define x real()
#define y imag()
using namespace std;
typedef complex <double> point;
int n,m,w,h,S;
point L[30001][2];
point A[30001];
int arm[30001];
 
bool ccw(point a,point b,point c){
  b-=a,c-=a;
  c*=conj(b); 
   return (c.y>0);
}
 
void mk_arm(){
  memset(arm,0,sizeof(arm));
  for(int i=0;i<n;i++){
    int low=0,mid,up=m+1;
    while(low<up){
      mid=(low+up)/2;
      if(!ccw(L[mid][0],L[mid][1],A[i])) up=mid;
      else low=mid+1;
    }
    arm[low]++;
  }
  for(int i=1;i<=m;i++)arm[i]+=arm[i-1];
}
 
int solve(){
  int res=0;
  for(int i=0;i<m;i++){
    int low=i,mid,up=m+1;
    while(low<up){
      mid=(low+up)/2;
      double sss=((L[mid][0].y-L[i][0].y)+(L[mid][1].y-L[i][1].y))*w/2.0;
      if(w*h-(sss)<S) up=mid;
      else low=mid+1; 
    }
    res=max(res,(arm[low-1]-arm[i]));
  }
  return n-res;
}
 
int main(){
  while(1){
    cin>>n>>m>>w>>h>>S;
    if(!n&&!m&&!w&&!h&&!S)break;
    L[0][0]=point(0,0);
    L[0][1]=point(w,0);
    for(int i=1,a,b;i<=m;i++){
      cin>>a>>b;
      L[i][0]=point(0,a);
      L[i][1]=point(w,b);
    }
 
    double a,b;
    for(int i=0;i<n;i++)cin>>a>>b,A[i]=point(a,b);
    mk_arm();
    cout << solve()<<endl;
  }
   
  return 0;
}

Measured memory_bytes: 2772
from itertools import accumulate

N, M = map(int, input().split())
nums = [0] * (N+1)
for _ in range(M):
    L, R = map(int, input().split())
    L, R = L-1, R-1
    nums[L] += 1
    nums[R+1] -= 1

accNums = list(accumulate(nums))
#print('accNums:', accNums)

ans = accNums.count(M)
print(ans)


Measured memory_bytes: 8116
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    int N, H;
    cin >> N >> H;
    vector<int>a(N), b(N);
    int a_max = 0, ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        a_max = max(a_max, a[i]);
    }

    //a_maxよりダメージが大きいのを全部投げて
    //倒せなかったらa_maxで殴るとよい
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());

    for (int i = 0; i < N; i++) {
        if (b[i] >= a_max) {
            H -= b[i];
            ans++;
            if (H <= 0)break;
        }
        else break;
    }
    if(H>0)ans += (H + a_max - 1) / a_max;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 2001
ll dp[MAXN];

void solve()
{
    s(dp, 0);
    ll n;
    cin >> n;
    dp[0] = dp[1] = dp[2] = 0;
    dp[3] = 1;
    dp[4] = 1;
    dp[5] = 1;
    for (int i = 6; i <= n; i++)
    {
        dp[i] = 1;
        for (int j = 3; i - j >= 3; j++)
            dp[i] += dp[i - j] % mod;
        dp[i] %= mod;
    }
    cout << dp[n] % mod << "\n";
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3716
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long 
ll int N,M,K;
ll int mod=1000000000+7;

#include <iostream>
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;


// 二項係数をmodしたものを求められるクラス　計算量はnCrについてn
struct Combination{
    ll int MAX_N;
    ll int MOD;
    ll int *fac, *finv, *inv;
    Combination(ll int max_n,ll int mod): MAX_N(max_n+1),MOD(mod){ //make table
        fac = new ll int[MAX_N];finv = new ll int[MAX_N];inv = new ll int[MAX_N];
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for (ll int i = 2; i < MAX_N; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    ll int COM(ll int n,ll int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    void free_COM(){
        delete[] fac;
        delete[] finv;
        delete[] inv;
    }
    
};


int main(void){
    scanf("%lld %lld %lld",&N,&M,&K);
    ll int ans=0;
    
    //N
    Combination CB(N*M,mod);
    ll int com=CB.COM(N*M-2,K-2);
    CB.free_COM();
    for(ll int i=1;i<N;i++){
        ll int msum=((N-i)*(M*M%mod))%mod;
        ans+=(com*msum%mod)*i%mod;
        ans%=mod;
    }
    //M
    for(ll int i=1;i<M;i++){
        ll int msum=((M-i)*(N*N%mod))%mod;
        ans+=(com*msum%mod)*i%mod;
        ans%=mod;
    }
    printf("%lld\n",ans%mod);
}


Measured memory_bytes: 4992
a, b = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    g = gcd(a, b)
    g_a = a // g
    g_b = b // g
    return g_a * g_b * g

print(lcm(a, b))

Measured memory_bytes: 3060
s = input()
win = 0
lose = 0
for i in range(len(s)):
    if i % 2 == 0:
        my = "g"
    else:
        my = "p"
    if my == "g" and s[i] == "p":
        lose += 1
    elif my == 'p' and s[i] == 'g':
        win += 1
print(win -lose)

Measured memory_bytes: 3316
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
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[] pc = new int[n];
        int[] p = new int[n];
        ArrayList<Integer>[] a = new ArrayList[n];
        Queue<Integer> q = new LinkedList<>();

        for(int i=0; i<n+m-1; i++) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            pc[r] ++;
            if(a[l] == null) {
                a[l] = new ArrayList<Integer>();
            }
            ((ArrayList<Integer>)a[l]).add(r);
        }

        for(int i=0; i<n; i++) {
            if(pc[i] == 0 ) {
                p[i] = -1;
                q.add(i);
                break;
            }
        }

        while(!q.isEmpty()) {
            int x = q.poll();
            ArrayList<Integer> children = a[x];
            if(children == null) {
                continue;
            }
            for(int y : children) {
                pc[y]--;
                if(pc[y] == 0) {
                    p[y] = x;
                    q.offer(y);
                }
            }
        }

        for(int i=0; i<n; i++) {
            System.out.println(p[i]+1);
        }

    }


}


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

int main()
{
	int A[100][100];
	int b[100];
	int c[100];
	int n, m;

	cin >> n >> m;


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

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

	for (int i = 0; i < n; i++) {
		c[i] = 0;
		for (int j = 0; j < m; j++) {
			c[i] += A[i][j] * b[j];
		}
	}

	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a<=b)
{
   if(b<=c)
   {  
    printf("%d %d %d\n",a,b,c);
   }
   if(c<=a)
   {
    printf("%d %d %d\n",c,a,b);
   }
}
else if(c<=b)
{
   if(b<=a)
   {  
    printf("%d %d %d\n",c,b,a);
   }
   if(a<=c)
   {
    printf("%d %d %d\n",a,c,b);
   }
}
else if(c<=a)
{
   if(a<=b)
   {  
    printf("%d %d %d\n",c,a,b);
   }
   if(b<=c)
   {
    printf("%d %d %d\n",b,c,a);
   }
}
return 0;
}



Measured memory_bytes: 2040
import std.stdio, std.string, std.conv, std.range, std.algorithm;
void main() {
    string[] n = [];
    foreach (string l; lines(stdin)) n ~= l.chomp;
    foreach (s; ["S", "H", "C", "D"])
        foreach (i; 1..14) {
            auto t = "%s %d".format(s, i);
            if (!n[1..$].canFind(t)) t.writeln;
        }
}

Measured memory_bytes: 2472
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <math.h>
#include <map>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

// ユークリッドの互除法
li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

// 素数判定
bool isPrime(li n) {
    for(li i = 0; i * i < n ; i++) {
        if (n % i == 0) return false;
    }
    return n != 1; // 1は例外
}

// 素因数分解
map<li, li> prime_factor(li n) {
    map<li, li> res;
    FOR(i, 0, sqrt(n)) {
        while(n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}
 
int main(void) {
        li N, M;
    cin >> N >> M;

    li X[M];
    FOR(i, 0, M) {
        cin >> X[i];
    }

    sort(X, X + M);
    
    // 例外処理 N >= M の場合初期配置で全て埋められる
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    // 以下では N < M が保証されるため、全ての点がうまることはない

    // 座標の移動は一方向に絞られる
    // 移動幅が大きい所の両端に点を置く
    // 点が置かれた幅部分はチェックを打っていき、残った幅部分を全てたすと解
    li diffs[M - 1];
    FOR(i, 0, M - 1) {
        diffs[i] = X[i + 1] - X[i];
    }
    
    sort(diffs, diffs + (M - 1));
    li sum = 0;
    FOR(i, 0, M - N) {
        sum += diffs[i];
    }

    cout << sum;

    return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

ostream& operator<<(ostream& os, vi const& v){
  rep(i,v.size()){
    os << v[i] << " ";
  }
  return os;
}

int main(){
  int n;
  while(cin >> n,n){

    vector<set<int>> vs(n);
    rep(i,n){
      int k; cin>>k;
      rep(j,k){
	int t;
	cin >> t; t--;
	vs[i].insert(t);
      }
      // cout << vs[i] << endl;
    }

    int k; cin >> k;
    vi s(k);
    rep(i,k){
      int x; cin >> x;
      x--;
      s[i] = x;
    }
  
    vi ans;
    rep(i,n){
      bool ok = true;
      rep(j,k){
	if(vs[i].count(s[j])==1) continue;
	ok = false;
	break;
      }
      if(ok) ans.push_back(i);
    }

    if(ans.size()==1){
      cout << ans[0]+1 << endl;
    } else {
      cout << -1 << endl;
    }
  }
  
}

Measured memory_bytes: 1648
max = 999999
hurui = Array.new(max+1, 0)

hurui[0] = 1
hurui[1] = 1
(max+1-2).times do |i|
  index = i + 2
  if hurui[index] == 0
    (max/index-1).times do |j|
      hurui[index + index*(j+1)] = 1
    end
  end
end

while n = gets do
  n = n.to_i
  count = 0
  for i in 0..n
    count += 1 if hurui[i] == 0
  end
  puts count
end

Measured memory_bytes: 13904
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は log(N);
 */
const int mod = 1e9 + 7;

//ここから書き始める
int main(){
	string s; 
	cin >> s;
	char a ='A';
	char z = 'Z';
	int geta = 0;
	int getz = 0;
	rep(i,s.size()){
		if(s[i] == a){
			geta = i;
			break;
		}
	}
	int n = s.size();
	for (int i = n-1 ;i >= 0; i--){
		if(s[i] == z){
			getz = i;
			break;
		}
	}
	int ans = getz - geta + 1;
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;


template< typename T >
struct Dinic{
    const T inf;

    struct edge{
        int to;
        T cap;
        int rev;
        bool isrev;
    };

    vector<vector<edge>> g;
    vector<int> min_cost, iter;

    Dinic(int V) : inf(numeric_limits<T>::max()), g(V){}

    void add_edge(int from, int to, T cap){
        g[from].emplace_back((edge){to, cap, (int)g[to].size(), false});
        g[to].emplace_back((edge){from, 0, (int)g[from].size() - 1, true});
    }

    bool bfs(int s, int t) {
        min_cost.assign(g.size(), -1);
        queue<int> que;
        min_cost[s] = 0;
        que.push(s);
        while(!que.empty() && min_cost[t] == -1){
            int p = que.front();
            que.pop();
            for(auto &e : g[p]) {
                if(e.cap > 0 && min_cost[e.to] == -1){
                    min_cost[e.to] = min_cost[p] + 1;
                    que.push(e.to);
                }
            }
        }
        return min_cost[t] != -1;
    }
    T dfs(int idx, const int t, T flow){
        if(idx == t) return flow;
        for(int &i = iter[idx]; i < g[idx].size(); i++){
            edge &e = g[idx][i];
            if(e.cap > 0 && min_cost[idx] < min_cost[e.to]){
                T d = dfs(e.to, t, min(flow, e.cap));
                if(d > 0){
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
    return 0;
  }
    
    T max_flow(int s, int t){
        T flow = 0;
        while(bfs(s, t)){
            iter.assign(g.size(), 0);
            T f = 0;
            while((f = dfs(s, t, inf)) > 0) flow += f;
        }

        return flow;
    }
};

signed main(){
    
    int n, m; cin >> n >> m;
    Dinic<int> g(n);
    for(int i = 0; i < m; i++){
        int a, b, c; cin >> a >> b >> c;
        g.add_edge(a, b, c);
    }
    cout << g.max_flow(0, n - 1) << endl;
    return 0;
}



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

int main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=1;i<10;i++){
		if(n%i==0&&n/i<10){
			ans++;
		}
	}
	if(ans>0)cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int n;
	static int[] A;

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

		n  = Integer.parseInt(br.readLine());
		String[] AStr = br.readLine().split(" ");
		A = new int[n];
		for(int i = 0; i < n ; i++){
			A[i] = Integer.parseInt(AStr[i]);
		}

		int mLength = Integer.parseInt(br.readLine());
		String[] Mstr = br.readLine().split(" ");
		int[] M = new int[mLength];
		for(int i = 0; i < mLength ; i++){
			M[i] = Integer.parseInt(Mstr[i]);
		}

		for(int i = 0 ; i < mLength ; i++){
			if(solve(0,M[i])){
				System.out.println("yes");
			}else{
				System.out.println("no");
			}
		}

	}

	private static boolean solve(int i,int M){
		if(M == 0) return true;
		if(i == n) return false;

		return solve(i + 1, M) || solve(i + 1, M - A[i]);
	}

}

Measured memory_bytes: 24788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin>>N;
  int min_count=pow(10,9);
  
  for(int i;i<N;i++){
    int a;
    cin>>a;
    int count=0;
    while(true){
      if(a%2==0 && count<min_count){
        count++; a/=2;
      }
      else{
        break;
      }
    }
    if(count<min_count){
      min_count = count;
    }
  }
  cout << min_count << endl;
}

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

int main() {
  int n;
  cin >> n;
  int m = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (; a % 2 == 0; a /= 2) {
      m++;
    }
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
i = int(input())
seen = set()
seen.add(i)
temp = i
for x in range(2,1000000):
    if(temp%2 == 0):
        temp = temp/2
    else:
        temp = 3*temp+1
    if(temp in seen):
        print(x)
        break
    else:
        seen.add(temp)


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main()
{
	char s[101],s_copy[101],p[101];
	
	scanf("%s",&s);
	scanf("%s",&p);
	
	strcpy(s_copy,s);
	strcat(s,s_copy);

	if(strstr(s,p) != 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 540
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Long k = sc.nextLong();
		long[] a = new long[n]; for(int i = 0; i < n; i++) a[i] = Long.parseLong(sc.next());
		long[] f = new long[n]; for(int i = 0; i < n; i++) f[i] = Long.parseLong(sc.next());
		long l = 0;
		long r = 1000000000000l;

		Arrays.parallelSort(a);
		Arrays.parallelSort(f);

		while(r > l) {
			long use = 0;
			long c = (l+r)/2;
			for(int i = 0; i < n; i++) {
				long X = c/f[n-i-1];
				if(X < a[i]) use += (a[i] - X);
			}
			if(use > k) l = c + 1;
			else r = c;
		}


		System.out.println(l);
		sc.close();
	}
}

Measured memory_bytes: 68380
#include "bits/stdc++.h"
using namespace std;
#define r(i,a,n) for(int i=a;i<(int)(n);i++)
typedef long long ll;
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(N);
    r(i,0,A.size())cin>>A[i];
    map<int,int>m;
    vector<int> SUM(N+1);
    SUM[0]=0;
    r(i,0,N)SUM[i+1]=(SUM[i]+A[i])%M;
    ll ans=0;
    r(i,0,SUM.size()){
        ans+=m[SUM[i]];
        m[SUM[i]]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3968
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                String s = in.nextString();
                if (s.equals("Y"))
                    cnt++;
            }
            if (cnt == 0)
                out.println("Three");
            else out.println("Four");
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>

int main(){
	int n;
	int x;
	while(true){
		std::cin>>n>>x;
		if(n==0&&x==0){
			break;
		}
		int count=0;
		for(int i=1;i<=n-2;i++){
			if(i>x){
				break;
			}
			for(int j=i+1;j<=n-1;j++){
				if(i+j>x){
					break;
				}
				for(int k=j+1;k<=n;k++){
					if(i+j+k==x){
						count++;
					}
					if(i+j+k>x){
						break;
					}
				}

			}
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=b[a[0]-1]
for i in range(1,n):
    ans+=b[a[i]-1]
    if a[i]==a[i-1]+1: ans+=c[a[i]-2]
print(ans)

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

int main() {
  int K, N;
  cin >> N >> K;
  
  vector<int> p(N);
  for (int i=0; i<N; i++) {
    int ibuff;
    cin >> p.at(i);
    p.push_back(ibuff);
  }
  
  sort(p.begin(), p.end());

  int cost=0;
  for (int j=0; j<K; j++) {
    cost += p.at(j);
  }
  
  cout << cost << endl;
  
  return 0;
}

Measured memory_bytes: 3604
N=int(input())
A=list(map(int,input().split()))
S=[0 for _ in range(N+1)]
for i in range(N):
    S[i+1]=S[i]+A[i]
cnt={}
for s in S:
    if s in cnt:
        cnt[s]+=1
    else:
        cnt[s]=1
ans=0
for v in cnt.values():
    ans+=v*(v-1)//2
print(ans)

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

int main() {
	string S;
	cin >> S;
	bool finished = false;
	if (S.size() < 3)
		cout << 0 << endl;
	for (int i = S.size() / 2 - 1; i > 0 / 2; i--) {
		for (int j = 0; j < i; j++) {
			if (S.at(j) != S.at(j + i)) {
				finished = true;
				break;
			}
		}
		if (finished == false) {
			cout << 2 * i << endl;
			break;
		}
		else
			finished = false;
	}
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)

B, Ikr, FullBit = {}, [100001]*(1<<N), (1<<N)-1
master_key = 0
M.times{
	a, c = gets.to_i, gets.split.map(&:to_i)
	tkrbit = c.inject(0){|bit, tkr|
		bit | (1<<(tkr-1))
	}
	next if Ikr[tkrbit] < a
	master_key |= tkrbit
	Ikr[tkrbit] = a
	B[(a<<N)|tkrbit] = true
}
if master_key != FullBit
	p -1
	exit
end

Q, q, r = B.keys.sort, [], []
while lowest = Q.shift
	low_cost, low_tkrbit = lowest>>N, lowest&FullBit
	next if Ikr[low_tkrbit] < low_cost
	break if low_tkrbit == FullBit
	next unless B.key?(lowest)

	while kg = Q.shift
		cost, tkrbit = kg>>N, kg&FullBit
		next if Ikr[tkrbit] < cost
		cost, tkrbit = low_cost+cost, low_tkrbit|tkrbit
		next if tkrbit == low_tkrbit
		q << kg
		next if Ikr[tkrbit] <= cost
		Ikr[tkrbit] = cost
		r << ((cost<<N)|tkrbit)
	end

	until q.empty?
		unless r.empty?
			l, pv = q[0] < r[0] ? [q, r[0]+FullBit] : [r, q[0]+FullBit]
			Q.concat l.shift(l.bsearch_index{|_| pv <= _ }||l.size)
		else
			Q.concat q
			q.clear
		end
	end
	Q.concat r
	r.clear
end
p Ikr[FullBit]


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

n = int(input())
a = [int(x) for x in input().split()]

from collections import Counter
c = Counter(a)

ans = 0

possible_e = []

for i in c.keys():
    if c[i] >= 4:
        ans = max(ans, i ** 2)
    if c[i] >= 2:
        possible_e.append(i)

possible_e.sort()

if len(possible_e) > 1:
    ans = max(ans, possible_e[-1] * possible_e[-2])

print(ans)

Measured memory_bytes: 64920
<?php

$n = trim(fgets(STDIN));
$v_arr = explode(' ', trim(fgets(STDIN)));
$c_arr = explode(' ', trim(fgets(STDIN)));

$total = 0;

foreach ($v_arr as $i => $v) {
    $diff = $v - $c_arr[$i];
    if ($diff > 0) {
        $total += $diff;
    }
}

echo $total, "\n";


Measured memory_bytes: 4728
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()
 
k, s = na()

count = 0
for x in range(k+1):
  for y in range(k+1):
      if s-x-y >= 0 and s-x-y <= k:
        count += 1
print(count)

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

const int MAX = 1e5 + 100;
int h[MAX], dp[MAX];

int dp_solve(int idx)
{
	if(idx <= 0)
		return 0;

	int &ans = dp[idx];
	if(~ans) return ans;
	if(idx == 1) return ans = abs(h[1] - h[0]);
	return ans = min(dp_solve(idx-1) + abs(h[idx] - h[idx - 1]), dp_solve(idx-2) + abs(h[idx] - h[idx-2]));
}

int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", h + i);

	memset(dp, -1, sizeof dp);
	printf("%d\n", dp_solve(n-1));

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define HotChilliSauce ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
#define pii pair<int,int> 
#define mii map<int,int>
#define vi vector<int>
#define umii unordered_map<int,int>
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

const ll sz = 1e6+1;

int main(){
    HotChilliSauce;
    ll a , b ,c;
    cin >> a >> b >> c;
    ll ans = min(a,c);
    a-=ans;
    c-=ans;
    if(c == 0){
        ans+=b;
    }
    else {
        ll val = min(c,b);
        ans += val*2;
        c-=val;
        b-=val;
        if(c == 0){
            ans += b;
        }
        else{
            ans++;
        }
    }
    cout << ans;
    return 0;
}

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

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

    int n, x;

    cin >> n >> x;
    int m[n];
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> m[i];
        sum += m[i];
    }
    int cnt = n;
    sort(m, m + n);
    cnt += (x - sum) / m[0];

    cout << cnt << '\n';

    return 0;
}


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

int main(){
    int n;
    scanf("%d",&n);
    double a[n];
    for(int i=0;i<n;i++) scanf("%lf",&a[i]);
    double sum=0;
    for(int i=0;i<n;i++){
        sum+=1.0/a[i];
    }
    printf("%lf\n",1.0/sum);
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<iomanip>
#include<string.h>
#include<cstdio>
#include<cstdlib>
#include<stack>

using namespace std;

int sum = 0;

void merge(int a[], int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int l[n1], r[n2];
  for(int i = 0; i < n1; i++){
    l[i] = a[left + i];
  }
  l[n1] = 1000000000;
  for(int i = 0; i < n2; i++){
    r[i] = a[mid + i];
  }
  r[n2] = 1000000000;

  int j = 0, k = 0;
  for(int i = 0; i < n2 + n1; i++){
    if(l[j] <= r[k]){
      a[left + i] = l[j];
      j++;
    }
    else{
      a[left + i] = r[k];
      k++;
    }
    sum++;
  }
}

void mergesort(int a[], int left, int right){
  if(left + 1 < right){
    int mid = (left + right) / 2;
    mergesort(a, left, mid);
    mergesort(a, mid, right);
    merge(a, left, mid, right);
  }
}


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

  mergesort(a, 0, n);


  for(int i = 0; i < n - 1; i++){
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
  cout << sum << endl;


}


Measured memory_bytes: 6980
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=1e5+10;
struct edge{
	int to,next,w;
}a[N<<1];
int head[N],cnt=0;
inline void add(int x,int y,int w){a[++cnt]=(edge){y,head[x],w};head[x]=cnt;}
int ans=0,n;
int bac[20];
void dfs(int u,int fa,int fr){
	int x=fr;
	for(int v,i=head[u];i;i=a[i].next) {v=a[i].to;if(v==fa) continue;x^=a[i].w;dfs(v,u,a[i].w);}
	++bac[x];
}
int dp[1<<16];
inline int DP(int s){
	if(~dp[s]) return dp[s];
	dp[s]=1e9;
	for(int i=1;i<16;++i) {
		if(s&(1<<i)) {
			for(int j=i+1;j<16;++j) {
				if(s&(1<<j)) {
					int t=s^(1<<i)^(1<<j);
					int k=i^j;int f=1;
					if(t&(1<<k)) t^=1<<k,++f;
					else t|=1<<k;
					f+=DP(t);dp[s]=min(dp[s],f);
				}
			}
			break;
		}
	}
	return dp[s];
}
int main()
{
	init(n);Set(dp,-1);
	for(int i=1;i<n;++i) {
		int u,v,w;init(u),init(v),init(w);
		++u,++v;add(u,v,w),add(v,u,w);
	}dfs(1,0,0);
	int ans=0;int s=0;
	dp[0]=0;
	for(int i=1;i<16;++i) {ans+=bac[i]>>1;bac[i]&=1;if(bac[i]) s|=1<<i;}
	ans+=DP(s);cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7680
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string s; cin >> s;
  int a = 0, b = 0;
  a = (s[0] - '0')*10;
  a += (s[1] -'0');

  b = (s[2] - '0')*10;
  b += (s[3] -'0');


  if ( 1 <= a && a <= 12 && 1 <= b && b <= 12 ) {
    cout << "AMBIGUOUS" << endl;
  } else if ( 1 <= a && a <= 12 ) {
    cout << "MMYY" << endl;
  } else if ( 1 <= b && b <= 12 ) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int n,m,sq[720][720],f[1010],vis[1010],n1,n2,g[710];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void dfs(int u,int col)
{
	if (vis[u]!=-1)
	{
		if (vis[u]!=col)
		{
			puts("-1");exit(0);
		}
		return;
	}
	vis[u]=col;
	if (col) n2++;else n1++;
	rep(i,1,n)
		if ((i!=u) && (!sq[u][i])) dfs(i,col^1);
}

int main()
{
	n=read();m=read();
	rep(i,1,m)
	{
		int u=read(),v=read();
		sq[u][v]=sq[v][u]=1;
	}
	memset(vis,-1,sizeof(vis));f[0]=1;
	rep(i,1,n)
	{
		if (vis[i]>=0) continue;
		n1=0;n2=0;
		dfs(i,0);
		memset(g,0,sizeof(g));
		per(j,n,0)
		{
			if (j>=n1) g[j]|=f[j-n1];
			if (j>=n2) g[j]|=f[j-n2];
		}
		rep(j,0,n) f[j]=g[j];
	}
	//rep(i,1,n) cout << f[i] << " ";cout << endl;
	int ans=n*n*2;
	rep(i,0,n) 
		if (f[i]) ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2176
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := map[int]int{}

	for i := 0; i < n; i++ {
		m[nextInt()]++
	}

	// fmt.Println(m)

	answer := 0
	for _, v := range m {
		if v%2 == 1 {
			answer++
		}
	}

	fmt.Println(answer)
}


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

int main() {
	int n;

	cin >> n;

	if (n -n%100 ==700) {
		cout << "Yes";
			return 0;
	}

	if (n%100-n%10 == 70) {
		cout << "Yes";
		return 0;
	}
	if (n%10 == 7) {
		cout << "Yes";
		return 0;
	}

	cout << "No";


}


Measured memory_bytes: 3588
include Math

def root(a,b)
  sqare = a*a + b*b
  squ = Math.sqrt(sqare)
  return squ
end

n, d = gets.chomp.split.map(&:to_i)
point = []
(1..n).each do |i|
  point << gets.split.map(&:to_i)
end

i=0
count = 0
for i in 0..n-1
  if root(point[i][0], point[i][1]) <= d 
    count += 1
  end
end

p count


Measured memory_bytes: 28752
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long int ll;

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

int main() {
  int A, B;
  scanf("%d %d", &A, &B);
  printf("%d\n", (A-1)*(B-1));
}


Measured memory_bytes: 888
import java.io.*;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			try{
				int number = Integer.parseInt(reader.readLine());
				if(number < 3){break;}
				int score[];
				score = new int[number];
				int i;
				for(i=0;i<number;i++){
					score[i] = Integer.parseInt(reader.readLine());
				}
				
				int max = 0;
				int maxJ = 0;
				int min = 1001;
				int minJ = 0;
				
				for(i=0;i<number;i++){
					if(max <= score[i]){
						max = score[i];
						maxJ = i;
					}
					if(score[i] <= min && i != maxJ){
						min = score[i];
						minJ = i;
					}
				}
				
				int sum = 0;
				for(i=0;i<number;i++){
					if(i != minJ && i != maxJ){
						sum += score[i];
					}
				}
				System.out.println(sum/(number-2));
			}
			catch(IOException e){
				System.out.println(e);
			}
		}
		return;
	}
}

Measured memory_bytes: 24484
from collections import deque

N, u, v = map(int, input().split())

neighbors = [[] for i in range(N + 1)]

for _ in range(N - 1):
    A, B = map(int, input().split())
    neighbors[A].append(B)
    neighbors[B].append(A)


def BFS(neighbors, s):
    q = deque([s])
    dist = [-1] * len(neighbors)
    dist[s] = 0
    while q:
        t = q.popleft()
        d = dist[t]
        nodes = neighbors[t]
        for n in nodes:
            if dist[n] < 0:
                dist[n] = d + 1
                q.append(n)
    return dist

u_cost = BFS(neighbors, u)
v_cost = BFS(neighbors, v)

ans = 0
for i in range(1, N + 1):
    if u_cost[i] < v_cost[i]:
        ans = max(ans, v_cost[i])

print(ans - 1)

Measured memory_bytes: 31512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, a, b; cin >> n >> a >> b;
  cout << min(a, b) << ' ' << max(0LL, a + b - n) << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long N,min;
	cin>>N;
	min=N-1;
	for(long long i=1;i*i<=N;i++){
		if(N%i==0){
			if(N/i+i-2<min)min=N/i+i-2;
		}
	}
	cout<<min;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAXN 100010
using namespace std;

int num[MAXN] , N;
long long ans[MAXN] , M , P;

int main(){
    cin >> N >> M >> P;
    for(int i = 1 ; i <= N ; i++){
        cin >> num[i];
        if(i >= 2)
            ans[i] = ans[i - 1] + ((num[i] - num[i - 1]) * M > P ? P : (num[i] - num[i - 1]) * M);
    }
    long long minN = ans[N];
    cout << minN;
    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200000
long long n, kk;
vector<long long>e[N];
vector<long long>ee[N];
bool used[N];
long long ans;
void dfs(long long p,long long k) {
	long long x = ((long long)(ee[p].size()));
	used[k] = true;
	if (k != 0) {
		if (x >= kk) {
			ans = 0;
		}
		else ans = (ans*(kk - x - 1)) % MOD;
		ee[k].push_back(p);
		ee[p].push_back(k);
	}
	f(i, e[k].size()) {
		if (!used[e[k][i]])dfs(k, e[k][i]);
	}
	return;
}




int main() { 

	long long x, y;
	scanf("%lld %lld", &n, &kk);
	f(i, n-1) {
		scanf("%lld %lld", &x, &y);
		x--;
		y--;
		e[x].push_back(y);
		e[y].push_back(x);
	}
	ans = kk;
	dfs(0, 0);
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 18304
def solve(ta, a, b)
    x = a / Math::cos(ta)
    # p Math::sin(ta)
    y = x * Math::sin(ta)
    # p [a, b, x, y]
    if y > b
        # p '!!'
        x = b / Math::sin(ta)
        y = x * Math::cos(ta)
        # p [a, b, x, y]
        # p a * y / 2
        # p a * a / Math::tan(ta) / 2
        
        return b * y / 2
    else
        return a * b - a * y / 2
    end
end
a,b,x=  gets.split.map(&:to_f)
x/=a
low, high = 0, 89.999999999
50.times do
    mid = (low + high) / 2
    if x > solve(mid * Math::PI / 180, a, b)
        high = mid
    else   
        low = mid
    end
end
puts '%.10f' % low

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int a[1000005] ={0};

void solve(){
	a[1] = 1;
	for(int i = 2; i <= sqrt(1000000); i++){
		if(a[i] == 0){
			for(int j =2;;j++){
				if(i * j>1000000) break;
				a[i * j] = 1;
			}
		}
	}
}

int main(){
	solve();
	/*for(int i =1;i < 100;i++){
		if(a[i] == 0) cout<<i<<endl;
	}*/
	while(true){
		int a1=0,d=0,n=0,cnt=1;
		cin >> a1>>d>>n;
		if(a1 == 0&&d==0&&n==0) return 0;
		for(int i=0;;i++){
			int num = a1+ d*i;
			if(a[num] == 0){
				if(cnt == n){
					cout << num << endl;
					break;
				}
				cnt++;
			}
		}
	}
}


Measured memory_bytes: 6984