akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 1e5 + 5;
const int logn = 20;
int P[maxn][logn];
int n , L  , q;
ll x[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> x[i];
//        x[i] = x[i - 1] + x[i];
    }
    cin >> L >> q;
    for(int i = 1 ; i <= n ; ++i){
        P[i][0] = P[i - 1][0];
        while(P[i][0] <= n && x[P[i][0]] - x[i] <= L)++P[i][0];
        --P[i][0];
//        cout << x[P[i][0] + 1] - x[i] << " ";
//        cout << P[i][0] << "\n";
    }
    for(int j = 1 ; j < logn ; ++j){
        for(int i = 1 ; i <= n ; ++i){
            P[i][j] = P[P[i][j - 1]][j - 1];
//            cout << i << " " << j << " " << P[i][j] << endl;
        }
    }
    for(int i = 1 ; i <= q ; ++i){
        int u , v;cin >> u >> v;
        if(u > v)swap(u , v);
        int res = 0;
        for(int j = logn - 1 ; j >= 0 ; --j){
            if(P[u][j] < v)u = P[u][j] , res += (1 << j);
        }
        cout << res + 1 << '\n';
    }
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
int X(int N){
  int sum=0;
  while(N>0){
    sum=sum+N%10;
    N=N/10;
  }
  return sum;
}
    

int main() {
  int N,A,B;
  cin>>N>>A>>B;
  int b=0;
  for(int i=1;i<=N;i++){
    if(X(i)>=A&&X(i)<=B){
      b=b+i;
    }
  }
  cout<<b<< endl;
  
      
      
}


Measured memory_bytes: 256
mod=10**9+7
n,k=map(int,input().split())
ans=1
coef1=n
coef2=n-1
for i in range(1,min(k+1,n)):
  tmp=1
  tmp*=coef1
  tmp%=mod
  tmp*=coef2
  tmp%=mod
  ans+=tmp
  ans%=mod  
  coef1*=n-i
  coef1%=mod
  coef1*=pow(i+1,mod-2,mod)
  coef1%=mod
  coef2*=n-1-i
  coef2%=mod
  coef2*=pow(i+1,mod-2,mod)
  coef2%=mod
print(ans)

Measured memory_bytes: 40812
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define vi vector<ll>

void solve(){
	string str;
	cin >> str;
	ll l = str.length();
	ll ans = 0;
	forn(i,0,l){
		ans += str[i]-'0';
	}
	if(ans%9){
		cout<<"No";
		return ;
	}
	cout<<"Yes";
	return ;
}
 
int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}

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

vector<vector<double>> dp;
double find(int i,vector<double> &v,int rem){
    double ans=0;
    if(dp[i][rem]!=-1)return dp[i][rem];
    if(i==v.size()-1){
        ans+=v[i];
        if(rem>0){
            ans+=(double)1-v[i];
        }
        return dp[i][rem]=ans;
    }
    ans+=find(i+1,v,rem)*v[i];
    if(rem>0)
    ans+=find(i+1,v,rem-1)*((double)1-v[i]);
    return dp[i][rem]=ans;
}

int main(){
    
    int n;
    cin>>n;
    dp.clear();
    dp.resize(n+1,vector<double>(n-(n/2),-1));
    vector<double> v(n,-1);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    //cout<<find(0,v,n-(n/2)-1)<<endl;
    double ans=find(0,v,n-(n/2)-1);
    // printf("%lf\n",ans);
    //std::cout << std::fixed;
    std::cout << std::setprecision(10);
    std::cout << ans<<endl;
    
    return 0;
}

Measured memory_bytes: 38940
def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    to = [0]*(n+1)
    ans = 0
    for _ in range(m):
        a, b = map(int, input().split())
        to[a] = max(to[a], h[b-1])
        to[b] = max(to[b], h[a-1])
    for i, hi in enumerate(h, 1):
        if hi > to[i]:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 84840
from sys import stdin


def main():
    abc = [int(x) for x in stdin.readline().rstrip().split()]
    count = 0
    while True:
        abc.sort()
        if abc[0] == abc[1] == abc[2]:
            print('{}'.format(count))
            return
        if abc[1] == abc[2]:
            abc[0] += 2
        else:
            abc[0] += 1
            abc[1] += 1
        count += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

#define nl cout<<"\n"
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007

//write your function here
void fun()
{

}


int32_t main()
{
    IOS;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    //start code from here
    ll n;
    ll temp=1000;
    cin>>n;
    for(ll i=1;i<=10;i++)
    {
        if(n>temp)
        {
            temp+=1000;
            // deb2(n,temp);
        }
        else
        {
            break;
        }
        
    }
    cout<<temp-n;
} 

Measured memory_bytes: 3608
#include<stdio.h>

int main(){
	char S[101];
	scanf("%s",S);
	long long K;
	scanf("%lld",&K);
	long long i=0;
	while(S[i]=='1'){
		i++;
	}
	
	if(i>=K){
		printf("1\n");
		return 0;
	}
	
	printf("%c\n",S[i]);
	
	return 0;
}

Measured memory_bytes: 128
require 'prime'

n =  10 ** 7
table = Array.new(n+1, false)
Prime.each(n) {|prime| table[prime] = true }
ps = (1..55555).select { |i| i % 5 == 3 && table[i] }

n = gets.to_s.to_i

puts ps[0...n].join(" ")


Measured memory_bytes: 99308
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

import sys
stdin = sys.stdin
def tokens(): return stdin.readline().strip().split()
def ints(): return map(int, tokens())
def int1(): return int( stdin.readline().strip() )

INF = 2147483647


S = tokens()[0]

if 'AC' in S:
    print "Yes"
else:
    print "No"



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

typedef long long ll;

int main() {
	ll n, T, ans = 0;
	string s;
	cin >> n >> T >> s;
	
	for (int i = 0; i < s.size(); i++) {
		if (!isdigit(s[i])) continue;
		ll add = 1;
		for (int j = 0; j < s[i] - '0'; j++) {
			add *= n;
			add = min(add, (ll)INT_MAX);
		}
		ans += add;
		ans = min(ans, (ll)INT_MAX);
	}
	
	ans *= T;
	if (1e+9 < ans) {
		cout << "TLE" << endl;
	} else {
		cout << ans << endl;
	}
}

Measured memory_bytes: 1196
def main():
    n = int(input())
    p = list(map(int, input().split()))

    ans = 0
    for i in range(1, n-1):
        if (p[i-1]<p[i]) & (p[i+1]>p[i]):
            ans += 1
        elif (p[i-1]>p[i]) & (p[i+1]<p[i]):
            ans += 1
    return ans

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

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

int main(){
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int tmp;
	if(x > y)tmp = a;
	else tmp = b;
	cout << min(a * x + b * y, min(c * 2 * max(x, y), c * 2 * min(x, y) + tmp * abs(x - y))) << endl;
}

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

int n,a[N];
void gg(){
	puts("-1"); exit(0);
}
int main(){
	scanf("%d",&n);
	int i;
	for (i=1; i<=n; i++) scanf("%d",&a[i]);
	if (a[n]!=2) gg();
	ll l=2,r=3;
	for (i=n-1; i; i--){
		ll x=(l-1)/a[i]+1,y=r/a[i];
		if (x>y) gg();
		x*=a[i]; y=y*a[i]+a[i]-1;
		l=x; r=y;
	}
	printf("%lld %lld\n",l,r);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll ok=0,ng=200002,mid=(ok+ng)/2;
    while(mid!=ok){
        ll sum=0;
        for(int i=0;i<n;i++){
            sum+=n-(lower_bound(a,a+n,mid-a[i])-a);
        }
        if(sum>=m){
            ok=mid;
        }else{
            ng=mid;
        }
        mid=(ok+ng)/2;
    }
    ll s[n+1];
    s[0]=0;
    for(int i=0;i<n;i++){
        s[i+1]=s[i]+a[i];
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        ll num=(upper_bound(a,a+n,ok-a[i])-a);
        ans+=s[n]-s[num];
        ans+=(n-num)*a[i];
        m-=(n-num);
    }
    cout << ans+(ok*m)<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <string.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <climits>
#include <queue>
#include <bitset>
#include <time.h>
#include <vector>

using namespace std;

const int maxN = 2e5 + 6, MOD = 998244353, lg = 23;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
#define fi first
#define se second
#define th second.second

int n;
ll arr[maxN];
ll ac[maxN];

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    cin >> n;
    
    for(int i= 0; i < n; i++){
        cin >> arr[i];
        arr[i] -= i + 1;
    }
    
    ll bes = LLONG_MAX;
    
    sort(arr, arr + n);
    
    for(int i = n - 1; i >= 0; i--){
        ac[i] = arr[i];
        ac[i] += ac[i + 1];
    }
    
    ll negs = 0;
    
    for(int i = 0; i < n; i++){
        ll cur = abs(arr[i] * i - negs) + ac[i] - (arr[i] * (n - i));
        bes = min(bes, cur);
        negs += arr[i];
    }
    
    cout << bes << '\n';
}



Measured memory_bytes: 3328
#include<stdio.h>
int main(void)
{
	int n,x,i,j,k,flg,sa;
	int a[101],b[100];
	
	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		for(i=0;i<=n;i++)	{
			scanf("%d",&a[i]);
		}
		for(i=0;i<=n;i++)	{
			k=0;
			for(j=0;j<=n;j++)	{
				if(j!=i)	{
					b[k]=a[j];
					k++;
				}
			}
			sa=b[1]-b[0];
			flg=1;
			for(j=1;j<n-1;j++)	{
				if(b[j+1]-b[j]!=sa)	{
					flg=0;
					break;
				}
			}
			if(flg==1)	{
				break;
			}
		}
		printf("%d\n",a[i]);
	}
	return 0;
}


Measured memory_bytes: 600
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=1<<18;


int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    vector<ll> f(n);
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll i=0;i<n;i++) cin>>f[i];
    sort(a.begin(),a.end());
    sort(f.begin(),f.end(),greater<ll>());

    ll ub=100100100100100;
    ll lb=-1;

    while(ub-lb>1){
        ll med=(ub+lb)/2;
        ll cnt=0;
        for(ll i=0;i<n;i++){
            if(med<a[i]*f[i]) cnt+=a[i]-med/f[i];
        }
        if(cnt>k){
            lb=med;
        }else{
            ub=med;
        }
    }
    
    cout<<ub<<endl;
 
}

Measured memory_bytes: 6336
#include<iostream>
using namespace std;
int main() {
    int c500, c100, c50, total;
    int ncours = 0;
    cin >> c500 >> c100 >> c50 >> total;
    for (int i = 0; i <= c500; i++)
    {
        for (int a = 0; a <= c100; a++)
        {
            for (int q = 0; q <= c50; q++)
            {
                if (total == i * 500 + a * 100 + q * 50)
                    ncours++;
            }
        }
    }
    cout << ncours << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
int a,b,c,df;
cin>>a>>b>>c;
if(a==b){
    df=c;
}
if(a==c){
    df=b;
}
if(c==b){
    df=a;
}
cout<<df;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define SZ(x) (long long)x.size()
#define endl '\n'
#define FAST                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define tc                                                                     \
  int tc;                                                                      \
  cin >> tc;                                                                   \
  while (tc--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define REPO(i, b, a) for (int i = b - 1; i >= a; i--)
#define REPI(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
bool comp(pair<int, int> v, int val) { return v.ff < val; }
inline int read() {
  int t = 0;
  char c;
  while ((c = getchar_unlocked()) != '\n' && c != ' ' && c != EOF) {
    t = t * 10 + c - 48;
  }
  return t;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
bool checkValidity(int a, int b, int c) {
  if (a + b <= c || a + c <= b || b + c <= a)
    return false;
  else
    return true;
}

int32_t main() {
  FAST;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("output.txt", "w", stderr);
#endif
  int n = read();
  vector<int> v(n);
  REP(i, 0, n) v[i] = read();
  int ans = 0;
  int mm = v[0];
  REP(i, 1, n) {
    if (v[i] < mm) {
      ans += mm - v[i];
    } else if (v[i] > mm)
      mm = max(v[i], mm);
  }
  cout << ans;
  return 0;
}


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

typedef long long lint;
typedef unsigned long long ulint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 107;

vector<int> e[_];
inline void adde(int a,int b){e[a].emplace_back(b);}
inline void addde(int a,int b){adde(a,b),adde(b,a);}

int n,fa[_]={0},xdep[_];

void dfs(int x,int ff,int dep)
{
	fa[x]=ff;int ch=0;
	for(auto b:e[x])if(b!=ff)ch++,dfs(b,x,dep+1);
	xdep[dep]=max(xdep[dep],ch);
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1,a,b;i<n;i++)a=ty(),b=ty(),addde(a,b);

	ulint ans=-1;int midep=n+1;
	for(int i=1;i<=n;i++)
	{
		for(auto b:e[i])
		{
			memset(xdep,0,sizeof(xdep)),dfs(i,b,1),dfs(b,i,1);
			ulint cnt=2;int nowdep=0;
			while(xdep[nowdep+1])nowdep++,cnt*=xdep[nowdep];
			if(nowdep<midep)midep=nowdep,ans=cnt;
			else if(nowdep==midep)ans=min(ans,cnt);
		}
		memset(xdep,0,sizeof(xdep)),dfs(i,0,1);
		ulint cnt=1;int nowdep=0;
		while(xdep[nowdep+1])nowdep++,cnt*=xdep[nowdep];
		if(nowdep<midep)midep=nowdep,ans=cnt;
		else if(nowdep==midep)ans=min(ans,cnt);
	}
	
	cout<<midep+1<<' '<<ans<<lf;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;
// constexpr int MOD = 1e9+7;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

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

int main(void){
    vector<int> p;
    for(int i = 1; i < 1e5; i += 2){
        if(isPrime(i) && isPrime((i+1)/2)) p.push_back(i);
    }
    Cin(int, q);
    Rep(q){
        Cin(int, a, b);
        Cout(distance(lower_bound(Range(p), a), upper_bound(Range(p), b)));
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>

using namespace std;

void solve()
{
	int H, W;
	cin >> H >> W;
	vector<string> C(H);
	for (int i = 0; i < H; ++i)
	{
		cin >> C[i];
	}
	for (int i = 0; i < H; ++i)
	{
		cout << C[i] << endl;
		cout << C[i] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
template <class X> void print(X x) { cout << x << endl; }
void print(vl x) {
    for(ll i : x) {
        cout << i << " ";
    }
    cout << endl;
}
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*998244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m;
ll codeforces = 1;
string S, T;
vector<PP> A, B;
void input() {
    cin >> n;
    rep(i, n - 1) {
        cin >> x >> y;
        x--;
        y--;
        if(x > y)
            swap(x, y);
        A.pb({x, y});
    }
}
void solve() {
    ans = n * (n + 1) * (n + 2) / 6;
    rep(i, n - 1) { ans -= (A[i].fi + 1) * (n - A[i].se); }
    print(ans);
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    while(codeforces--) {
        solve();
    }
}

Measured memory_bytes: 7360
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int price;
	while ((price = in())) {
		int change = 1000 - price, coins = 0;
		for (int c : {500, 100, 50, 10, 5, 1}) {
			coins += change / c;
			change %= c;
			if (!change)
				break;
		}
		out(coins, '\n');
	}
}


Measured memory_bytes: 2360
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    int h, w; cin >> h >> w;
    vector<string> mat(h+2);
    for(int i=0; i<h; ++i){
        string s; cin >> s;
        s='#'+s+'#';
        mat[i+1]=s;
    }
    mat[0]=string(w+2, '#');
    mat[h+1]=string(w+2, '#');

    vector<vector<array<int, 4>>> adj(h+2, vector<array<int, 4>>(w+2, array<int, 4>()));
    for(int y=1; y<=h; ++y){
        int last=0;
        for(int x=1; x<=w; ++x){
            if(mat[y][x]=='.') adj[y][x][0]=last;
            else last=x;
        }
        last=w+1;
        for(int x=w; x>=1; --x){
            if(mat[y][x]=='.') adj[y][x][1]=last;
            else last=x;
        }
    }
    for(int x=1; x<=w; ++x){
        int last=0;
        for(int y=1; y<=h; ++y){
            if(mat[y][x]=='.') adj[y][x][2]=last;
            else last=y;
        }
        last=h+1;
        for(int y=h; y>=1; --y){
            if(mat[y][x]=='.') adj[y][x][3]=last;
            else last=y;
        }
    }
    int ans=0;
    for(int y=1; y<=h; ++y){
        for(int x=1; x<=w; ++x){
            if(mat[y][x]=='#') continue;
            int t=adj[y][x][1]-adj[y][x][0]-1;
            t+=adj[y][x][3]-adj[y][x][2]-1;
            --t;
            ans=max(ans, t);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70912
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        StringBuilder sb = new StringBuilder();
        while(0 < N) {
            N--;
            sb.append((char)('a' + N%26));
            N /= 26;
        }
        System.out.println(sb.reverse());
    }
}

Measured memory_bytes: 35656
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
	Scanner sc=new Scanner(System.in);
	int S=sc.nextInt();
	int W=sc.nextInt();
	if(W>=S) {
		System.out.println("unsafe");
	}
	else {
		System.out.println("safe");
	}
	}
}


Measured memory_bytes: 35540
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

pnt = 0
for i in range(N):
  if A[i] >= B[i]:
    pnt += B[i]
  elif A[i] + A[i+1] >= B[i]:
    pnt += B[i]
    A[i+1] -= B[i] - A[i]
  else:
    pnt += A[i] + A[i+1]
    A[i+1] = 0
    
print(pnt)

Measured memory_bytes: 19116
import statistics
import math

N = int(input())
X = list(map(int, input().split()))

p = math.ceil(statistics.mean(X))
print(min(
    sum([(x - p) ** 2 for x in X]),
    sum([(x - (p-1)) ** 2 for x in X]),
    sum([(x - (p+1)) ** 2 for x in X]),
    ))

Measured memory_bytes: 5404
#include <stdio.h>

int main (void) 
{

int n,s,x;
int i,j,k;

while(1){

   scanf("%d",&n); scanf("%d",&x);

   s=0;

   if(n==0 && x==0){
      break;
   }

   for(i = 1;i < n-1;i++){
      for(j = i + 1 ;j < n;j++)
         for(k = j + 1;k <= n;k++)
            if(i + j + k == x){
               s = s + 1;
            }
   }
   printf("%d\n",s);
}

return 0;
}

Measured memory_bytes: 1812
#include<cstdio>
using namespace std;
const int N=200200,M=2002000;
int i,j,k,n,m,En,ch,ff,rtA,rtB;
int h[N],A[N],B[N],fg[N],z[M],ans[N];
struct edge { int s,n;} E[M];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].n=h[y];h[y]=En;
}
void dfs(int x,int F) {
	fg[x]=1;
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		dfs(E[k].s,x);
		fg[x]^=1;
	}
}
void Dfs(int x) {
	for (int &k=h[x];k;k=E[k].n) if (!z[k>>1]) {
		z[k>>1]=1;
		if ((k|1)!=En) {
			if (x+n==E[k].s) ans[x]=1;
			if (x-n==E[k].s) ans[x-n]=-1;
		}
		Dfs(E[k].s);
	}
}
int main() {
	R(n);
	En=1;
	for (i=1;i<=n;i++) {
		R(A[i]);
		if (A[i]==-1) rtA=i;
		else E_add(A[i],i);
	}
	for (i=1;i<=n;i++) {
		R(B[i]);
		if (B[i]==-1) rtB=n+i;
		else E_add(n+B[i],n+i);
	}
	dfs(rtA,0);dfs(rtB,0);
	for (i=1;i<=n;i++) {
		if (fg[i]!=fg[n+i]) return puts("IMPOSSIBLE"),0;
		if (fg[i]) E_add(i,n+i);
	}
	puts("POSSIBLE");
	E_add(rtA,rtB);
	Dfs(rtA);
	for (i=1;i<=n;i++) W(ans[i]),putchar(' ');
	puts("");
}

Measured memory_bytes: 24832
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000000;
const long long MOD = 1000000007;

bool f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  slen--;
  for (int i = 0; i < s.length(); i++)
  {
    if(s[i]!=s[slen-i])
      return false;
  }
  return true;
}

int main()
{
  long long N, X;
  cin >> N >> X;
  long long mi = INF;
  for (int i = 0; i < N;i++){
    long long m;
    cin >> m;
    X -= m;
    mi = min(mi, m);
  }
  cout << N + (X / mi) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  string S;
  cin >> N >> S;
  if(N < 3){
    cout << 0 << endl;
    return 0;
  }
  
  ll r,g,b;
  r = g = b = 0;
  REP(i,S.size()){
    switch(S[i]){
      case 'R':
        r++;
        break;
      case 'G':
        g++;
        break;
      case 'B':
        b++;
        break;
    }
  }
  ll sub = 0;
  REP(i,S.size()-2){
    for(int k=2; k<(int)S.size(); k++){
      if(0 != (i+k)%2)continue;
      int j = (i+k)/2;
      vint v = {i,j,k};
      if(i < j && j < k){
        do{
          if('R' == S[v[0]] && 'G' == S[v[1]] && 'B' == S[v[2]]){
            sub++;
          }
        }while(next_permutation(v.begin(),v.end()));
      }
    }
  }
  cout << r*g*b-sub << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;

int main() {
	
	ll h, w;
	cin >> h >> w;
	ll ans = LLINF;
	FOR(j,2){
		FOR1(i, h) {
			vector<ll> a(3);
			a[0] = i * w;
			a[1] = (h - i) * (w / 2);
			a[2] = (h - i) * (w - w / 2);
			SORT(a);
			ans = min(ans, a[2] - a[0]);
			a[0] = i * w;
			a[1] = ((h - i) / 2) * w;
			a[2] = (h - i - (h - i) / 2) * w;
			SORT(a);
			ans = min(ans, a[2] - a[0]);
		}
		swap(h, w);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int num=0;
string str,ans;

int main(){
	cin>>str;
	for(int i=0;i<str.size();i++){
		if(str[i]=='0'){
			ans+='0';
			num++;
		}
		else if(str[i]=='1'){
			ans+='1';
			num++;
		}
		else if(num){
			ans.erase(ans.begin()+num-1);
			num--;
		}
	}
	cout<<ans<<endl;
}

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

int main(){
	// sengen
	int a,b;
	// nyuryoku
	cin >> a >> b;
	// keisan
	if(b%a == 0){
		cout << a + b << endl;
	}else{
		cout << b - a << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Scanner cin = new Scanner();
            int N = cin.Int();
            int[] a = cin.ArrayInt(N);

            int[] cnt = new int[100002];
            foreach(var i in a)
            {
                if (i != 0) cnt[i - 1]++;
                cnt[i]++;
                cnt[i + 1]++;
            }

            Console.WriteLine(cnt.Max());
            Console.ReadLine();
        }

        static int BinarySearch<T>(T[] array, T target) where T : IComparable<T> //2分探索
        {
            int min = 0;
            int max = array.Length - 1;

            while (true)
            {
                // 範囲内に見つからなかった
                if (max < min) return -1;
                // 範囲内の中央値と比較する
                int mid = min + (max - min) / 2;
                switch (target.CompareTo(array[mid]))
                {
                    case -1:    // 中央値より小さい
                        max = mid - 1;
                        break;
                    case 1:     // 中央値より大きい
                        min = mid + 1;
                        break;
                    case 0:     // 見つかった
                        return mid;
                }
            }
        }

        static void Swap<T>(ref T a, ref T b)
        {
            T tmp = a;
            a = b;
            b = tmp;
        }
    }

    class Scanner //標準入力
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int Int()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Int() + add;
            }
            return Array;
        }

        public long Long()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Long() + add;
            }
            return Array;
        }

        public double Double()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Double() + add;
            }
            return Array;
        }
    }
}


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

using namespace std;

int main() {
  int x;
  cin >> x;
  
  if (400 <= x && x <= 599) {
    cout << '8' << endl;
  } else if (600 <= x && x <= 799) {
    cout << '7' << endl;
  } else if (800 <= x && x <= 999) {
    cout << '6' << endl;
  } else if (1000 <= x && x <= 1199) {
    cout << '5' << endl;
  } else if (1200 <= x && x <= 1399) {
    cout << '4' << endl;
  } else if (1400 <= x && x <= 1599) {
    cout << '3' << endl;
  } else if (1600 <= x && x <= 1799) {
    cout << '2' << endl;
  } else if (1800 <= x && x <= 1999) {
    cout << '1' << endl;
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>
#include <bitset>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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 = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int A, B; cin >> A >> B;
  cout << A * B << endl;
}


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

using namespace std;

int a[Maxn];
int b[Maxn];

int main()
{
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		cin >> b[i];
		a[i] += b[i];
	}
	if(is_sorted(b+1, b + 1 + n) == 1)
	{
		cout << "Yes" << endl;
		return 0;
	}
	else
	{
		sort(b+1, b+1+n);
		for(int i=1;i<n+1;i++)
		{
			int temp = abs(b[i] - a[i]);
			if(temp > 1)
			{
				cout << "No" << endl;
				return 0;
			}
			else
				continue;
		}
		cout << "Yes" << endl;
	}
	
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)

int main(void){
	int a,b,c,d;	cin >> a >> b >> c >> d;
	// cout << abs(a-b) << abs(b-c) << abs(a-c);
	if ((abs(a-b)>d || abs(b-c)>d) && abs(a-c)>d)	cout << "No" << endl;
	else	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
num = input('')

a = int(num.split()[0])
b = int(num.split()[1])
c = int(num.split()[2])
d = int(num.split()[3])

if abs(c-a) <= d or (abs(a-b) <= d and abs(b-c) <= d):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
if __name__ == '__main__':
	n = input().split()
	c = input().split()
	dp = [50000] * (int(n[0]) + 1)

	for i in range(int(n[1])):
		if int(c[i]) > int(n[0]):
			continue
		dp[int(c[i])] = 1
		for j in range(int(n[0])):
			if int(c[i])+j > int(n[0]):
				break;
			if dp[j] != 50000:
				dp[int(c[i])+j] = min(dp[int(c[i])+j], dp[j]+1)

	print (dp[int(n[0])])




Measured memory_bytes: 7520
#include<stdio.h>

int main(void){

int a, b,x;

while(1){

scanf("%d %d",&a, &b);


if(a == 0 && b == 0){
break;
}

if(a<=b){

printf("%d %d\n",a,b);
}else {
printf("%d %d\n",b,a);
}
}
return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int x,a;
    cin>>x>>a;
    cout<<10*(x>=a)<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)

res = 0
while true do
  N.times do |i|
    if A[i] % 2 != 0
      puts res
      return
    end
    A[i] /= 2
  end
  res += 1
end

Measured memory_bytes: 14416
#include <iostream>
#include <vector>


int main(int argc, char const *argv[]) {
  int n; // .. 100
  std::cin >> n;


  std::vector<std::vector<bool> > adj(n, std::vector<bool>(n));

  for(int q=0; q<n; ++q){
    int i_plus_1, k;
    std::cin >> i_plus_1;
    std::cin >> k;
    for(int p=0; p<k; ++p){
      int j_plus_1;
      std::cin >> j_plus_1;
      adj[i_plus_1-1][j_plus_1-1] = true;
    }
  }

  for(int i=0; i<n; ++i){
      for(int j=0; j<n; ++j){
        std::cout  <<  adj[i][j] << (j==n-1 ? "" : " "); 
      }
      std::cout << std::endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const ll MOD = 1e9+7;

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

	int k, x; cin >> k >> x;
	if(k*500 >= x) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}

int main(){
	int n;
	cin >>n;	
	vector<string>s(n+1,"");
	int both=0;
	int A=0;
	int B=0;
	int flag=0;
	int ans=0;
	char last='\0';
	for(int i=0;i<n;i++){
		flag=0;
		last='\0';
		cin >>s[i];
		for(int j=0;j<s[i].size();j++){
			if(j==0 and s[i].at(j)=='B'){
				flag+=1;
			}
			if(j==s[i].size()-1 and s[i].at(j)=='A'){
				flag+=2;
			}
			if(last =='A' and s[i].at(j)=='B'){
				ans++;
			}
			last=s[i].at(j);
		}
		switch(flag){
			case 1:
			B++;
			break;
			case 2:
			A++;
			break;
			case 3:
			A++;
			B++;
			both++;
			break;
		}

	}
	//cout<<ans<<endl;
	if(both==A and both==B and A!=0){
		A--;
	}
	ans+=min(A,B);
//	cout<<both<<" "<<A<<" "<<B<<" ";
	cout <<ans<<endl;

}


Measured memory_bytes: 768
#include<cstdio>
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 3000
struct edge{int nx,t;}e[MN*2+5];
int a[MN+5],h[MN+5],en,f[MN+5];
inline void ins(int x,int y)
{
	e[++en]=(edge){h[x],y};h[x]=en;
	e[++en]=(edge){h[y],x};h[y]=en;
}
void dfs(int x)
{
	if(f[x])return;f[x]=1;
	for(int i=h[x];i;i=e[i].nx)if(a[e[i].t]<a[x])
		dfs(e[i].t),f[e[i].t]>1?0:f[x]=2;
}
int main()
{
	int n=read(),i;
	for(i=1;i<=n;++i)a[i]=read();
	for(i=1;i<n;++i)ins(read(),read());
	for(i=1;i<=n;++i)dfs(i),f[i]>1?printf("%d ",i):0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int k,s;
    cin>>k>>s;
    ll ans=0;
    rep(i,k+1)
    {
        for(int j=i;j<=k;j++)
        {
            for(int l=j;l<=k;l++)
            {
                if(i+j+l==s)
                {
                    if(i==j && j==l)
                    {
                        ans+=1;
                    }
                    else if(i==j || j==l || i==l)
                    {
                        ans+=3;
                    }
                    else
                    {
                        ans+=6;
                    }
                    
                    

                }
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

template<typename T>//O(V^2)　全点間距離 辺のコストがすべて等しいとき,ダイクストラより高速に使える
vector<vector<T>> bfs(vector<vector<T>> &g){
    queue<T>q;
    int n=g.size();
    T INFTY=numeric_limits<T>::max();
    vector<vector<T>>dist(n,vector<T>(n,INFTY));
    for(int i=0;i<n;++i){
        dist[i][i]=0;
        q.emplace(i);
        while(!q.empty()){
            int v=q.front();
            q.pop();
            for(auto x:g[v]){
                if(dist[i][x]==INFTY){
                    q.emplace(x);
                    dist[i][x]=dist[i][v]+1;
                }
            }
        }
    }
    return dist;
}

void solve(){
  int n;
  cin>>n;
  vector<vector<int>>g(n);
  rep(i,n){
      int id;
      cin>>id;
      id--;
      int k;
      cin>>k;
      rep(j,k){
          int a;
          cin>>a;
          a--;
          g[id].pb(a);
      }
  }
  auto d=bfs(g);
  rep(i,n){
      cout<<i+1<<" "<<(d[0][i]!=numeric_limits<int>::max()?d[0][i]:-1)<<"\n";
  }
}


int main(){
    ios::sync_with_stdio(false);
  cin.tie(0);
    cout<<fixed<<setprecision(15);
  solve();
    return 0;
}



Measured memory_bytes: 3200
n=int(input())
m=10**9+7
p=[1 for i in range(10000)]
p[0]=0
p[1]=0
for i in range(2,n+1):
  if p[i]==1:
    for j in range(i*i,n+1,i):
        p[j]=0
ans=1
for i in range(2,n+1):
  if p[i]:
    c=0
    k=i
    while n//k>0:
      c=c+(n//k)%m
      k=k*i
    ans=(ans*((c+1)%m))%m
print(ans%m)
    
    
      
      


Measured memory_bytes: 9168
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
long long M;
long long dp[600][300];
pair<int,int>p[600];
int main(){
	int a,b;scanf("%d%d",&a,&b);printf("%d\n",(a-1)*(b-1));
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
    int h, w,n;
    scanf("%d%d%d", &h,&w,&n);
    int k;
    if(h>w){
        k = n/h;
        if(n%h!=0) k++;
    }
    else{
        k = n/w;
        if(n%w!=0) k++;
    }
    printf("%d", k);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
using namespace std;
struct graph{
	int h[360010],nex[27000010],to[27000010],col[360010],M;
	bool v[360010];
	graph(){
		M=0;
		memset(h,0,sizeof(h));
		memset(v,0,sizeof(v));
		memset(col,0,sizeof(col));
	}
	void ins(int a,int b){
		M++;
		to[M]=b;
		nex[M]=h[a];
		h[a]=M;
	}
	void add(int a,int b){
		ins(a,b);
		ins(b,a);
	}
	void dfs(int x,int c){
		col[x]=c;
		v[x]=1;
		int i,j;
		for(i=h[x];i;i=nex[i]){
			if(!v[to[i]]){
				v[to[i]]=1;
				for(j=h[to[i]];j;j=nex[j]){
					if(!v[to[j]])dfs(to[j],c);
				}
			}
		}
	}
}g[2];
int n;
int p(int i,int j){return i*2*n+j+1;}
bool sq(int x){
	double d=sqrt(x);
	return fabs(d-round(d))<1e-6;
}
void build(int f,int x,int y){
	if(y>=2*n)return;
	int i,j;
	for(i=0;i+x<2*n;i++){
		for(j=0;j+y<2*n;j++)g[f].add(p(i,j),p(i+x,j+y));
	}
	for(i=0;i+x<2*n;i++){
		for(j=2*n-1;j-y>=0;j--)g[f].add(p(i,j),p(i+x,j-y));
	}
}
struct pr{
	int x,y;
	pr(int a=0,int b=0){x=a;y=b;}
};
vector<pr>v[4];
int main(){
	int i,j,d1,d2;
	scanf("%d%d%d",&n,&d1,&d2);
	for(i=0;i<2*n&&i*i<=d1;i++){
		if(sq(d1-i*i))build(0,i,round(sqrt(d1-i*i)));
	}
	for(i=0;i<2*n&&i*i<=d2;i++){
		if(sq(d2-i*i))build(1,i,round(sqrt(d2-i*i)));
	}
	for(i=1;i<=4*n*n;i++){
		if(!g[0].v[i])g[0].dfs(i,1);
		if(!g[1].v[i])g[1].dfs(i,2);
	}
	for(i=0;i<2*n;i++){
		for(j=0;j<2*n;j++)v[g[0].col[p(i,j)]|g[1].col[p(i,j)]].push_back(pr(i,j));
	}
	for(i=0;i<4;i++){
		if((int)v[i].size()>=n*n){
			for(j=0;j<n*n;j++)printf("%d %d\n",v[i][j].x,v[i][j].y);
			break;
		}
	}
}

Measured memory_bytes: 128116
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,temp=0;
	cin >> a >> b >> c;
	for(int i=0;i<3;i++){
		for(int j=3;j>i;j--){
			if(a>b){
				temp=a;
				a=b;
				b=temp;
			}
			else if(b>c){
				temp=b;
				b=c;
				c=temp;
			}
		}
	}
	cout << a << " " << b << " " << c << endl;
	
	return 0;
}

Measured memory_bytes: 3096