akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Arrow
import Control.Concurrent
import Control.Monad
import Data.Bits
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Complex
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Maybe
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn
    rs <- UM.replicate n (0 :: Int)

    let l1      = length $ takeWhile (<= n) (map (\x -> f x x x) [1..])
    let l2 x    = length $ takeWhile (<= n) (map (\y -> f x y y) [1..])
    let l3 x y  = length $ takeWhile (<= n) (map (\z -> f x y z) [1..])

    forM_ [1..l1] (\x ->
        forM_ [x..l2 x] (\y ->
            forM_ [y..l3 x y] (\z ->
                    UM.modify rs (let l = length (nub [x,y,z]) in
                        if  | l==1 -> succ
                            | l==2 -> (+3)
                            | l==3 -> (+6)
                        ) (f x y z - 1)
                )
            )
        )

    U.mapM_ print =<< U.freeze rs

f x y z = x^2 + y^2 + z^2 + x*y + y*z + z*x



Measured memory_bytes: 5036
#include <stdio.h>
#include <valarray>

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

int main(void){
  int n; scanf("%d", &n);
  std::valarray<int> C(n-1), S(n-1), F(n-1);
  REP(i, n-1) scanf("%d%d%d", &C[i], &S[i], &F[i]);
  REP(i, n){
    int t = 0;
    FOR(j, i, n-1){
      if(t < S[j]) t = S[j];
      else if(t % F[j] != 0) t = t + F[j] - (t % F[j]);
      t += C[j];
    }
    printf("%d\n",t);
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

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

bool solve(){
  int w,h;
  bool f[SIZE][SIZE][4] = {};
  
  scanf("%d%d",&w,&h);

  if(w + h == 0) return false;
  
  for(int i=0;i<h;i++){
    int in;
    
    for(int j=0;j<w-1;j++){
      scanf("%d",&in);

      f[i][j][0] = 1-in;
      f[i][j+1][2] = 1-in;
    }
    
    if(i+1 == h) break;

    for(int j=0;j<w;j++){
      scanf("%d",&in);

      f[i][j][3] = 1-in;
      f[i+1][j][1] = 1-in;
    }
  }

  queue<pair<int,int> > que;
  bool visited[SIZE][SIZE] = {};
  que.push({0,0});

  for(int i=1;que.size();i++){
    queue<pair<int,int> > q2;
    
    while(que.size()){
      pair<int,int> p = que.front();
      que.pop();

      int y = p.first;
      int x = p.second;
      
      if(visited[y][x]) continue;
      visited[y][x] = 1;

      if(y == h-1 && x == w-1){
        printf("%d\n",i);
        return true;
      }
      
      for(int j=0;j<4;j++){
        if(f[y][x][j]){
          q2.push({y+dy[j],x+dx[j]});
        }
      }
    }

    que = q2;
  }

  puts("0");
  
  return true;
}

int main(){

  while(solve());
  
  return 0;
}

Measured memory_bytes: 8200
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define sortall(obj) sort(ALL(obj))
#define revall(obj) reverse(ALL(obj))
#define SortRevAll(obj) revall(sortall(obj))
typedef string str;
typedef long long ll;
const int mod=1e9+7;
const int INF=1e9;
const ll LINF=1e18;
#define VI vector<int>
#define P pair
#define M map
#define F first()
#define S second()
#define PB(a) push_back(a)
#define IN(a) insert(a)
#define ins(a) int a;cin >> a
#define lls(a) ll a;cin >> a
#define in(a) cin >> a
#define sts(a) string (a);cin >> a
#define For(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) For(i,0,n)
#define Forr(i,m,n) for(int i=n-1;i>=m;i--)
#define repr(i,n) Forr(i,0,n)
#define print(a) cout << a << endl
#define Endl cout << endl
#define YES(n) cout << ((n)? "YES" : "NO") << endl
#define Yes(n) cout << ((n)? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define br(c,y,n) cout << ((c)? y : n) << endl

int cnt;

void check(int n)
{
    map<int,int> mp;
    while(n!=0){
        mp[n%10]++;
        n/=10;
    }
    if((mp[3]>=1)&&(mp[5]>=1)&&(mp[7]>=1)&&mp[0]==0){
        cnt++;
    }
}

int digit(int n)
{
    int c=0;
    while(n!=0)
    {
        c++;
        n/=10;
    }
    return c;
}

int main(){
    ins(N);cnt=0;
    rep(i,pow(4,digit(N-1))){
        int s=0;
        rep(j,digit(N)){
            VI chk(3);
            chk.at(0)=3*pow(2,2*j);
            chk.at(1)=2*pow(2,2*j);
            chk.at(2)=1*pow(2,2*j);
            if                  ((chk.at(0)& i)==3<<2*j){
                s+=pow(10,j)*7;
            }else if            ((chk.at(1)& i)==2<<2*j){
                s+=pow(10,j)*5;
            }else if            ((chk.at(2)& i)==1<<2*j){
                s+=pow(10,j)*3;
            }
        }
        if(s<=N)check(s);
    }
    print(cnt);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 14;
char cn[cm], * ci = cn, ct;
const double p = 0.01;

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


	fread(ci, 1, cm, stdin);

	int N = 0;
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';

	int M = N / 2;
	vector<double> dp(M + 2);
	dp[0] = 1.0;

	rep(i, N) {
		ci += 2;
		int k = (*ci++ - '0') * 10;
		k += *ci++ - '0';
		double P = p * k;
		ci++;

		for (int j = min(M, i); j >= max(0, i - M); j--) {
			dp[j + 1] += dp[j] * P;
			dp[j] *= 1 - P;
		}
	}

	printf("%.15f", dp[M + 1]);

	Would you please return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++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 SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    string n;
    cin >> n;
    if(n[0]==n[2])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll x,N,bf=1,ans;
  cin>>N;
  N--;
  cin>>x;
  ans=x-1;
  while(N--){
    cin>>x;
    if(x-1==bf){
      bf++;
      continue;
    }
    ans+=(x-1)/(bf+1);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int s[5050];
bool cmp(int a,int b)
{
	return a<b;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	int num=n,temp,ans=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&temp);
		if(temp>=k) num--;
		else s[ans++]=temp;
	}
	ans--;
	sort(s+1,s+num+1,cmp);
	temp=0;
	while(num>=2)
	{
		temp+=s[num];
		if(s[num-1]+temp<k)
		{
			num--;
			continue;
		}
		if(s[1]+temp>=k)
		{
			ans=0;
			break;
		}
		int l=1,r=num-2;
		while(l+1<r)
		{
			int mid=(l+r)/2;
			if(temp+s[mid]>=k) r=mid;
			else l=mid;
		}
		ans=ans-(num-r);
		num=r;
	}
	printf("%d\n",ans);
	return 0;
}

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


int main() {
  string s ;
  cin >> s ;
  
  string a ;
  int n=s.size();
  int c=0;
  
  for(int i = 0; i < n ; i++ ){
    if(s.at(i)=='A'){
      c++;
    }
    if(c>0){
      a+=s.at(i);
    }
  }
  
  reverse(a.begin(),a.end());
  
  int m =a.size();
  int d=0;
  string b ;
  for(int i = 0 ; i < m ; i++ ){
    if(a.at(i)=='Z'){
      d++;
    }
    if(d>0){
      b+=a.at(i);
    }
  }
  
  cout << b.size() << endl;
}
    
    

Measured memory_bytes: 1032
H,W=map(int,input().split())
S=[input() for i in range(H)]
visit=[[False]*W for i in range(H)]
par=[[None]*W for i in range(H)]
dd={}
X=[-1,0,1,0]
Y=[0,-1,0,1]
for j in range(H):
    for i in range(W):
        if visit[j][i]:
            continue
        if S[j][i]=='.':
            continue
        lH=[]
        lH.append((j,i,0))#0が黒
        par[j][i]=(i,j)
        num=0
        while lH:
            y,x,t=lH.pop()
            visit[y][x]=True
            for k in range(4):
                nx=x+X[k]
                ny=y+Y[k]
                if 0<=nx<W and 0<=ny<H:
                    if visit[ny][nx]:
                        continue
                    if t==0 and S[ny][nx]=='.':
                        visit[ny][nx]=True
                        num+=1
                        lH.append((ny,nx,1))
                    elif t==1 and S[ny][nx]=='#':
                        visit[ny][nx] = True
                        par[ny][nx]=(i,j)
                        lH.append((ny,nx,0))
        dd[(i,j)]=num
ans=0
for j in range(H):
    for i in range(W):
        if S[j][i]=='#':
            x,y=par[j][i]
            ans+=dd[(x,y)]
print(ans)


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

typedef long long ll;

// int K = 2;
// int S = 2;

int K, S;
int main() {
    cin >> K >> S;
    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if (0 <= S - i - j && S - i - j <= K) {
                ans++;
            }
            // for (int k = 0; k <= K; k++) {
            //     if (i + j + k == S) {
            //         // printf("%d, %d, %d\n", i, j, k);
            //         ans++;
            //     }
            // }
        }
    }

    cout << ans << endl;
}

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

int main(){
    string str;
    bool size = false , num = false , l = false , s = false;
    
    cin >> str;
    
    if(str.size() >= 6) size = true;
    for(int i = 0 ; i < str.size() ; i++){
        if('0' <= str[i] && str[i] <= '9') num = true;
        if('A' <= str[i] && str[i] <= 'Z') l = true;
        if('a' <= str[i] && str[i] <= 'z') s = true;
    }

    if(size && num && l && s) cout << "VALID" << endl;
    else cout << "INVALID" << endl;
    
    return 0;
}

Measured memory_bytes: 1180
#include <cmath>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;

constexpr int m = 3;

vector<vi> a(m, vi(m));

int n;
vi b;

void input() {
  for (auto&& i : a) {
    for (auto&& j : i)
      cin >> j;
  }

  cin >> n;

  b.resize(n);
  for (auto&& i : b)
    cin >> i;
}

void solve() {
  sort(b.begin(), b.end());

  for (auto&& i : a) {
    for (auto&& j : i) {
      if (binary_search(b.cbegin(), b.cend(), j))
        j = 0;
    }
  }

  string ans = "No";
  int cnt = 0;

  for (int i = 0; i < m; ++i)
    cnt += a[i][i] == 0;

  if (cnt == 3)
    ans = "Yes";

  cnt = 0;

  for (int i = 0; i < m; ++i)
    cnt += a[i][m - i - 1] == 0;

  if (cnt == 3)
    ans = "Yes";

  for (auto&& i : a) {
    if (count(i.cbegin(), i.cend(), 0) == 3)
      ans = "Yes";
  }

  for (int i = 0; i < m; ++i) {
    cnt = 0;

    for (int j = 0; j < m; ++j)
      cnt += a[j][i] == 0;

    if (cnt == 3)
      ans = "Yes";
  }

  cout << ans << '\n';
}

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

  cout.precision(16);
  cout << fixed;

  int _times = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  _times = 3;
#endif

  // cin >> _times;

  while (_times--) {
    input();
    solve();
  }
}


Measured memory_bytes: 3600
using System;


namespace _002_DigitNumber
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			int[] digitCompare = { 0, 
									 10, 
									 100, 
									 1000, 
									 10000, 
									 100000, 
									 1000000, 
									 10000000 };

			while ((inputStr = Console.ReadLine ()) != null)
			{
				string[] split = inputStr.Split (' ');
				int sum = int.Parse (split[0]) + int.Parse (split[1]);
				
				for (int digit = 1; digit <= 7; digit++)
				{
					if (sum < digitCompare[digit])
					{
						Console.WriteLine (digit);
						break;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 9032
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, C, D, E, M, N, K, Q, W, H, T, X, Y;

int main()
{
    string str;
    cin >> str;
    for (int i = 0; i < str.size()-1; ++i) {
        string s = str.substr(0, str.size()-(i+1));
        if (s.size() % 2 != 0) continue;
        if (s.substr(0, s.size()/2) == s.substr(s.size()/2, s.size()-1)) {
            cout << s.size() << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, m, k;
  cin >> n >> m >> k;

  string ans = "No";
  for (ll a = 0; a <= m; a++) {
    for (ll b = 0; b <= n; b++) {
      ll val = a * (n - b) + b * (m - a);

      if (val == k) {
        ans = "Yes";
      }
    }
  }

  cout << ans << ln;

  return 0;
}


Measured memory_bytes: 256
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=10 ** 9 + 7):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer

n, a, b = map(int, input().split())
mod = 10**9 + 7
ans = pow(2, n, mod) +  mod
ans -= nCk(n, a)
ans -= nCk(n, b)
print((ans-1)%mod)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const ll MOD=1e9+7;
int main()
{
    int n;
    cin>>n;
    vector<ll> a(n);
    ll ans=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<60;i++)
    {
        ll cnt=0;
        for(int j=0;j<n;j++)
            if(a[j]&(1ll<<i))
                cnt++;
        ans+=(cnt*(n-cnt)%MOD*((1ll<<i)%MOD))%MOD,ans%=MOD;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 10;

vector<int> g[maxn];
int res[maxn];

int t[4 * maxn], add[4 * maxn];

int st, ed, dt;

void upd(int v, int l, int r) {
    if (l >= ed || r <= st) return;
    if (st <= l && r <= ed) {
        add[v] += dt;
        return;
    }
    add[2 * v] += add[v];
    add[2 * v + 1] += add[v];
    add[v] = 0;
    upd(2 * v, l, (l + r) / 2);
    upd(2 * v + 1, (l + r) / 2, r);
    t[v] = t[2 * v] + (r - l) / 2 * add[2 * v] + t[2 * v + 1] + add[2 * v + 1] * (r - (r + l) / 2);
}

void show(int v, int l, int r) {
    if (l + 1 == r) {
        cout << t[v] + add[v] << ' ';
        return;
    }
    add[2 * v] += add[v];
    add[2 * v + 1] += add[v];
    add[v] = 0;
    show(2 * v, l, (l + r) / 2);
    show(2 * v + 1, (l + r) / 2, r);
    t[v] = t[2 * v] + add[2 * v] + t[2 * v + 1] + add[2 * v + 1];
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int n;
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        if (v < u) g[u].push_back(v);
        if (u < v) g[v].push_back(u);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        sort(all(g[i]));
        st = 1, ed = i + 1, dt = 1;
        upd(1, 1, n + 1);
        for (auto &el : g[i]) {
            st = 1, ed = el + 1, dt = -1;
            upd(1, 1, n + 1);
        }
        ans += t[1] + add[1] * n;
    }
    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 20644
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
work = [[[] for j in range(w)] for i in range(h)]
result = 0
for i in range(h):
    for j in range(w):
        append = work[i][j].append
        if i<h-1 and s[i+1][j] == ".":
            append([i+1,j])
        if i>0 and s[i-1][j] == ".":
            append([i-1,j])
        if j<w-1 and s[i][j+1] == ".":
            append([i,j+1])
        if j>0 and s[i][j-1] == ".":
            append([i,j-1])
q = deque()
popleft = q.popleft
append = q.append
for i in range(h):
    for j in range(w):
        if s[i][j] != ".":
            continue
        q.clear()
        q.append([i, j])
        temp = [[i, j]]
        tempappend = temp.append
        d = -1
        count = 1
        counter = 0
        for k in range(w*h):
            x, y = popleft()
            count -= 1
            for el in work[x][y]:
                if el not in temp:
                    counter += 1
                    append(el)
                    tempappend(el)
            if count == 0:
                d += 1
                count = counter
                counter = 0
            if len(q) == 0:
                break
        result = result if result>d else d
    if result == h+w-2:
        break
print(result)

Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
#define mp make_pair
#define vl vector<long long>
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/******************************define**********************************/

/*****************************functions********************************/

/****************************main function*****************************/
int main(void){
    int M,N; cin >> M >> N;
    string S; cin >> S;
    
    N--;
    if(S[N] == 'A') S[N] = 'a';
    if(S[N] == 'B') S[N] = 'b';
    if(S[N] == 'C') S[N] = 'c';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SWAP(a,b)({a ^= b; b ^= a; a ^= b;})

int main(){
    long long int a, b, d;

    scanf("%lld %lld", &a, &b);
    if(b>a) SWAP(a, b);
    while(b!=0){
        d = a%b;
        a = b;
        b = d;
    }
    printf("%lld\n", a);

return 0;
}



Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main(){
  int n;
  cin >> n;
  vector<priority_queue<int>> a(n);
  int q;
  cin >> q;
  REP(i,q){
    int b,t;
    cin >> b >> t;
    if(b==0){
      int x;
      cin >> x;
      a[t].push(x);
    }else if(b==1){
      if(!a[t].empty()){
        cout << a[t].top() << endl;
      }
    }else{
      if(!a[t].empty()){
        a[t].pop();
      }
    }
  }
}



Measured memory_bytes: 5080
n = int(input())
rs = [[0, 0] for _ in range(n)]
bs = [[0, 0] for _ in range(n)]

for i in range(n):
  a, b = map(int, input().split())
  rs[i][0] = a
  rs[i][1] = b

for i in range(n):
  c, d = map(int, input().split())
  bs[i][0] = c
  bs[i][1] = d


#rs.sort(key=lambda x: x[0]+x[1])
#bs.sort(key=lambda x: x[0]+x[1])

#print(rs)
#print(bs)

rb = [[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if rs[i][0]<bs[j][0] and rs[i][1]<bs[j][1]:
      rb[i].append(j)
rb.sort(key=lambda x: len(x))
#print(rb)

br = [[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if rs[j][0]<bs[i][0] and rs[j][1]<bs[i][1]:
      br[i].append(j)
#print(br)

use = [False]*n
ans = 0
for i in range(n):
  min_br = n+1
  min_b = n+1
  for j in rb[i]:
    if use[j]:
      continue
    if len(br[j]) <= min_br:
      min_br = len(br[j])
      min_b = j
  if min_b != n+1:
    use[min_b] = True
    ans += 1

print(ans)
    

Measured memory_bytes: 40304
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s; cin >> s;
	int k; cin >> k;
	set<string> st;
	auto itr = st.begin();
	REP(i, s.size()){
		REP1(j, s.size()-i){
			//cout << st.size() << endl;
			if(st.size()< 5){
				st.insert(s.substr(i, j));
				//cout << "add:" << s.substr(i, j) << endl;
			}
			else if(st.find(s.substr(i, j)) == st.end()) {
				itr = st.begin();
				REP(v, 4) itr++;
				if(*itr > s.substr(i, j)){
					st.erase(*itr);
					st.insert(s.substr(i, j));
					//cout << "add:" << s.substr(i, j) << endl;
				}
				else break;
			} 
		}
	}
	itr = st.begin();
	REP(i, k - 1) itr++;
    cout << *itr << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

ll n;
ll ans=0;

void dfs(ll m,int s,int u,int v)
{
  if(m>n) return ;
  if(m<=n && s>0 && u>0 && v>0) ans++;

  dfs(10*m+3,s+1,u,v);
  dfs(10*m+5,s,u+1,v);
  dfs(10*m+7,s,u,v+1);
}

int main()
{
  cin>>n;
  dfs(0,0,0,0);
  cout<<ans<<endl;
}

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

int main() {
	// your code goes here
	string a,b;
	cin>>a>>b;
	int l=a.length();
	int m=b.length();
	if(l>=m){
		cout<<"No";
		return 0;
	}
	else{
		for(int i=0;i<l;i++){
			if(a[i]!=b[i]){
				cout<<"No";
				return 0;
			}
	}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3620
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> s;
    rep(i,3){
        int temp;
        cin>>temp;
        s.insert(temp);
    }
    if(s.size()==2)yes;
    else no;
}


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

#define endl '\n'

vector<int> adj[401];
int dist[401];

int bfs(int root){
    for (int i=0; i<401; i++) dist[i] = 1e9;
    dist[root] = 0;
    queue<int> q;
    q.push(root);
    int maior = 0;
    while(!q.empty()){
        int top = q.front(); q.pop();
        for (int f : adj[top]){
            if (dist[f] > dist[top] + 1){
                dist[f] = dist[top] + 1;
                q.push(f);
                maior = max(maior, dist[f]);
            }
        }
    }
    return maior;
}

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

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

    int n,m; cin >> n >> m;
    char g[n][m];
    for (int i=0; i<n; i++) for (int j=0; j<m; j++) cin >> g[i][j];
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            if (g[i][j] == '#') continue;
            for (int k =0; k<4; k++){
                int ii = dy[k], jj = dx[k];
                if (i + ii >= 0 && i + ii <n && j + jj >=0 && j + jj < m && g[i+ii][j+jj] == '.'){
                    adj[i*m + j].push_back((i +ii)*m + j +jj);
                    adj[(i+ii)*m + j+jj].push_back(i*m + j);
                }
            }
        }
    }
    int ans = 0;
    for (int i=0; i<n; i++){
        for (int j=0; j<m; j++){
            if (g[i][j] == '#') continue;
            ans = max(ans, bfs(i*m + j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
X,Y,Z,K = map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

from collections import defaultdict
done = defaultdict(lambda:False)
import heapq
q = [(-A[0]-B[0]-C[0],0,0,0)]
heapq.heapify(q)

for _ in range(K):
    ma,i,j,k = heapq.heappop(q)
    if not done[(i+1,j,k)] and i<X-1:
        done[(i+1,j,k)]=True
        heapq.heappush(q,(-A[i+1]-B[j]-C[k] , i+1,j,k))
    
    if not done[(i,j+1,k)] and j<Y-1:
        done[(i,j+1,k)]=True
        heapq.heappush(q,(-A[i]-B[j+1]-C[k] , i,j+1,k))
    
    if not done[(i,j,k+1)] and k<Z-1:
        done[(i,j,k+1)]=True
        heapq.heappush(q,(-A[i]-B[j]-C[k+1] , i,j,k+1))
    print(-ma)

Measured memory_bytes: 76372
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("in.txt", "r", stdin); 
    freopen("out.txt", "w", stdout); 
#endif 
}

const int MX=1e5;
int N; 
int t[MX];
int memo[MX];

int solve(int idx){
	if(idx==N-1) return 0;
	if(idx>=N) return INF;
	if(memo[idx]!=-1) return memo[idx];
	int ans=solve(idx+1)+abs(t[idx]-t[idx+1]);
	if(idx<N-2) ans=min(ans,solve(idx+2)+abs(t[idx]-t[idx+2]));
	return memo[idx]=ans;
}

int32_t main(){
   boost;
   IO();
   memset(memo,-1,sizeof(memo));
   cin>>N;
   for(int i=0; i<N; i++) cin>>t[i];
   cout << solve(0) << endl;

   return 0;
}



Measured memory_bytes: 9852
// AOJ ALDS1_8_C Binary Search Tree III
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void skip(int k) { while (k--) gc(); }

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	if (n < 0) pc('-'), n = -n;
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

void sout(char *s) { while (*s) pc(*s++); }

typedef struct { int key; int parent; int left, right; } BT;
BT bt[500005]; int sz;
int root;

void preorder(int node)
{
	pc(' '), out(bt[node].key);
	if (bt[node].left  > 0) preorder(bt[node].left);
	if (bt[node].right > 0) preorder(bt[node].right);
}

void inorder(int node)
{
	if (bt[node].left  > 0) inorder(bt[node].left);
	pc(' '), out(bt[node].key);
	if (bt[node].right > 0) inorder(bt[node].right);
}

void insert(int z)
{
	int x, y;

	y = 0, x = root;
	while (x) {
		y = x;
		if (bt[z].key < bt[x].key) x = bt[x].left;
		else                       x = bt[x].right;
	}
	bt[z].parent = y;

	if (!y) root = z;
	else if (bt[z].key < bt[y].key) bt[y].left  = z;
	else                            bt[y].right = z;
}

int find(int node, int key)
{
	int t;

	t = key - bt[node].key;
	if (!t) return node;
	if (t < 0) {
		if (bt[node].left > 0) return find(bt[node].left, key);
	} else {
		if (bt[node].right > 0) return find(bt[node].right, key);
	}
	return -1;
}

void delete(int z)
{
	int p, c, y;

	if (bt[z].left <= 0 && bt[z].right <= 0) {
		p = bt[z].parent;
		if (z == bt[p].left) bt[p].left  = 0;
		else                 bt[p].right = 0;
	} else if (bt[z].left > 0 && bt[z].right > 0) {
		y = bt[z].right;
		while (bt[y].left > 0) y = bt[y].left;
		bt[z].key = bt[y].key;
		delete(y);
	} else {
		p = bt[z].parent;
		if (bt[z].left > 0) c = bt[z].left;
		else                c = bt[z].right;
		if (z == bt[p].left) bt[p].left  = c;
		else                 bt[p].right = c;
		bt[c].parent = p;
	}
}

int main()
{
	int n, i;
	char op;

	n = in(), root = 0, sz = 1;
	for (i = 0; i < n; i++) {
		op = gc();
		if (op == 'p') {            // print
			skip(5);
			inorder(root), pc('\n');
			preorder(root), pc('\n');
		} else if (op == 'i') {     // insert
			skip(6);
			bt[sz].key = in();
			insert(sz++);
		} else if (op == 'f') {     // find
			skip(4);
			sout(find(root, in()) >= 0? "yes": "no"), pc('\n');
		} else {                    // delete
			int z;
			skip(6);
			z = find(root, in());
			if (z >= 0) delete(z);
		}
	}
	return 0;
}


Measured memory_bytes: 7828
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

int n;
double x[512];
double y[512];

void init() {
  for(int i = 0; i < (int)512; ++i) {
    x[i] = y[i] = 0.0;
  }
} 

inline double Heron(double a, double b, double c) {
  double s = (a + b + c) / 2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

class solve_ {
public:
  int operator() (void) {
    int res = 1;
    for(int i = 0; i < (int)n; ++i) {
      for(int j = 0; j < (int)i; ++j) {
        res = std::max(res, CountPoints(i, j));
      }
    }
    return res;
  }
  int CountPoints(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    double dist = sqrt(dx * dx + dy * dy);
    if( dist > 2.0 ) return 0;
    auto t1 = std::pair<double, double>((x[i] + x[j]) / 2, (y[i] + y[j]) / 2);
    auto t2 = std::pair<double, double>(dx / dist, dy / dist);
    double h = 2 * Heron(1, 1, dist) / dist;
    auto t3 = std::pair<double, double>(t2.first * h, t2.second * h);
    auto c1 = std::pair<double, double>(t1.first + t3.second, t1.second - t3.first);
    auto c2 = std::pair<double, double>(t1.first - t3.second, t1.second + t3.first);
    int count1 = 0;
    int count2 = 0;
    {
      double cx = c1.first, cy = c1.second;
      for(int k = 0; k < (int)n; ++k) {
        if( k == i or k == j ) continue;
        if( (cx - x[k]) * (cx - x[k]) + (cy - y[k]) * (cy - y[k]) <= 1 ) {
          count1 += 1;
        }
      }
    }
    {
      double cx = c2.first, cy = c2.second;
      for(int k = 0; k < (int)n; ++k) {
        if( k == i or k == j ) continue;
        if( (cx - x[k]) * (cx - x[k]) + (cy - y[k]) * (cy - y[k]) <= 1 ) {
          count2 += 1;
        }
      }
    }
    int res = std::max(count1, count2) + 2;
    //printf("(%d, %d) -> %d\n", i, j, res);
    return res;
  }
};
solve_ solve;

int main() {
  for(;;) {
    init();
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < (int)n; ++i) {
      scanf("%lf %lf", &x[i], &y[i]);
    }
    printf("%d\n", solve());
  }
  return 0;
}

Measured memory_bytes: 3088
<?php
  
fscanf(STDIN,"%d %d",$n,$m);
$l_r = array();

for($i=0;$i<$m;$i++){
  $l_r[] = explode(" ",trim(fgets(STDIN)));
}

$pass_all = $l_r[0];

for($i=1;$i<$m;$i++){
  if($pass_all[0]<$l_r[$i][0]){
    $pass_all[0] = $l_r[$i][0];
  }
  if($pass_all[1]>$l_r[$i][1]){
    $pass_all[1] = $l_r[$i][1];
  }
}

if(($pass_all[1]-$pass_all[0]+1)<=0){
	echo "0\n";
}else{
	echo ($pass_all[1]-$pass_all[0]+1)."\n";
}


 

Measured memory_bytes: 51700
#include <cctype>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

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

int main(){
	LL x, a, b;

	cin >> x >> a >> b;

	if(a - b >= 0){
		cout << "delicious" << endl;
	}else if(b <= x + a){
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}


}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){
    ll x;
    cin>>x;
    for(ll i=1;;i++){
        ll a=i*(i+1)/2;
        if(a>=x){
            cout<<i<<endl;return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a[4], b[4];
    while (cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]) {
        int hit = 0;
        int blow = 0;
        for (int i=0; i<4; ++i)  {
            for (int j=0; j<4; ++j) {
                if (a[i] == b[j]) {
                    if (i == j) hit ++;
                    else blow ++;
                }
            }
        }
        cout << hit << " " << blow << "\n";
    }
    return 0;
}

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

int solve(string);

stack <int> st;

int main()
{
  string str;
  while(cin >> str){
    if(str == "+" || str == "-" || str == "*")
      st.push(solve(str));
    else st.push(atoi(str.c_str()));
    
    if(getchar()=='\n'){
      cout << st.top() << endl;
      return 0;
    }
  }
  return 0;
}

int solve(string str){
  int b = st.top();
  st.pop();
  int a = st.top();
  st.pop();
  if(str == "+")return a+b;
  else if(str == "-")return a-b;
  else if(str == "*")return a*b;
}



Measured memory_bytes: 3232
//      whn6325689
//		Mr.Phoebe
//		http://blog.csdn.net/u013007900
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
#include <functional>
#include <numeric>
#pragma comment(linker, "/STACK:1024000000,1024000000")


using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef complex<ld> point;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;

#define CLR(x,y) memset(x,y,sizeof(x))
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define lowbit(x) (x&(-x))
#define MID(x,y) (x+((y-x)>>1))
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LLINF 1LL<<62

template<class T>
inline bool read(T &n)
{
    T x = 0, tmp = 1;
    char c = getchar();
    while((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
    if(c == EOF) return false;
    if(c == '-') c = getchar(), tmp = -1;
    while(c >= '0' && c <= '9') x *= 10, x += (c - '0'),c = getchar();
    n = x*tmp;
    return true;
}
template <class T>
inline void write(T n)
{
    if(n < 0)
    {
        putchar('-');
        n = -n;
    }
    int len = 0,data[20];
    while(n)
    {
        data[len++] = n%10;
        n /= 10;
    }
    if(!len) data[len++] = 0;
    while(len--) putchar(data[len]+48);
}
//-----------------------------------

int n,m,a[23];

int main()
{
	while(read(n)&&read(m)&&(n+m))
	{
		CLR(a,0);
		int ans=0;
		for(int i=1,x;i<=n;i++)
		{
			read(x);
			a[x]++;ans+=x;
		}
		for(int i=1,x;i<=m;i++)
		{
			read(x);
			if(a[x]>0) a[x]--;
			else ans+=x;
		}
		write(ans),putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1068
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect
import queue

class Graph:

    def __init__(self, size):
        # id starts from 0
        self.size = size
        self.vertices = [0] * size # indicate parent
        self.visited = [False] * size
        self.edges = [None] * size
        for i in range(size):
            self.edges[i] = []

    def add_edge(self, frm, to):
        self.edges[frm].append(to)
        self.edges[to].append(frm)


class Solver:

    def __init__(self, graph):
        self.graph = graph
        self.que = queue.Queue() # (to, parent)
        self.set(0, -1)

    def set(self, v, parent):
        self.que.put(v)
        self.graph.visited[v] = True
        self.graph.vertices[v] = parent

    def run(self):
        while not self.que.empty():
            parent = self.que.get()
            for to in self.graph.edges[parent]:
                if self.graph.visited[to]:
                    continue
                self.set(to, parent)
        self.print_ans()

    def print_ans(self):
        #print('self.graph.parent') # debug
        #print(self.graph.vertices) # debug
        print("Yes")
        for parent in self.graph.vertices[1:]:
            print(parent + 1)

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    graph = Graph(n)
    for _ in range(m):
        a, b = list(map(int, input().split()))
        a -= 1
        b -= 1
        graph.add_edge(a, b)
    Solver(graph).run()

    #print('\33[32m' + 'end' + '\033[0m') # debug


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n;
    cin>>n;
    Vec a(n);
    Vec b(n);
    Vec c(n);
    cin>>a;
    cin>>b;
    cin>>c;
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    ll ans=0;
    rep(i,n){
        ll x = b[i];
        //a<x x<c
        ll cnta =  lower_bound(ALL(a),x)-a.begin();
        ll cntc = n-(upper_bound(ALL(c),x)-c.begin());
        ans += cnta*cntc;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    int i=0;
    int A,B,C;
    cin >> A >> B >> C;
    int ans = 0;
    if(C -(A+B+1)>=0){
        ans = A + B*2+1;
    }else{
        ans = B + C;
    }

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

Measured memory_bytes: 256