akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
        import java.math.BigDecimal;
        import java.math.BigInteger;
        import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);


    public static void main(String[] args) {
        int N = in.nextInt();
        for (int M = in.nextInt(); M > 0; M--)
            N -= in.nextInt();
        if (N < 0) N = -1;
        out.println(N);
        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}

Measured memory_bytes: 34500
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	int n,m;
	cin >> n >> m;
	int ans = n*(n-1)/2 + m*(m-1)/2;
	cout << ans << endl;

	return 0;
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
	#define wtf freopen("input.txt","w",stdout)
	#include "Debug.h"
#else
	#define de(x)
	#define rff
#endif

#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define vi vector <int>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=1e5+3;
const int BASE=100000;
#define low_bit(x) x&(-x)

int bit[MAXN*2],n,a[MAXN];
vi v;

ll query(int x){
	x+=BASE;
	ll r=0;
	while (x){
		r+=bit[x];
		x-=low_bit(x);
	}
	re r;
}

void add(int x){
	x+=BASE;
	while (x<MAXN*2){
		bit[x]++;
		x+=low_bit(x);
	}
}

int main(){
	fio;
	cin>>n;
	For(i,n){
		cin>>a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	ll l=0,r=v.size(),mid,x,cnt;
	ll tar=(ll)(n)*(n+1)/2/2;
	while (l<r-1){
		memset(bit,0,sizeof(bit));
		cnt=0;	
		mid=(l+r)>>1;
		x=0;
		add(0);
		For(i,n){
			if (a[i]>=v[mid]) x++;
			if (a[i]<v[mid]) x--;
			cnt+=query(x);
			add(x);
		}
		if (cnt<tar){
			r=mid;
		}else{
			l=mid;
		}
	}
	cout<<v[l]<<endl;
	re 0;
}

Measured memory_bytes: 1912
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;
    vector<long long> L;

    cin >> N;
    long long m = 0;
    for(long long i = 0; i < N + 1; i++){
      long long t;
      cin >> t;
      L.push_back(t);
      m += t;
    }

    long long max_node = 1;
    long long usable = 1;
    long long c = 0;
    m -= L[0];
    for(long long i = 0; i < N; i++){
      if(min(usable, max_node) <= L[i]){
        cout << -1 << endl;
        return 0;
      }
      if(m + L[i] > max_node){
        c += min(max_node, usable);
        usable = 2 * (min(max_node, usable) - L[i]);
      }
      else{
        if(m + L[i] <= usable){
          c += m + L[i];
          usable = 2 * m;
        }
        else{
          c += usable;
          usable = 2 * (usable - L[i]);
        }
      }
      max_node *= 2;
      max_node = min(max_node, INF);
      m -= L[i + 1];
      if(usable <= 0){
        cout << -1 << endl;
        return 0;
      }
    }

    if(min(usable, max_node) < L[N]){
      cout << -1 << endl;
      return 0;
    }
    c += L[N];

    cout << c << endl;
}


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

ok = []
no_and_no_even = []
no_and_even = []
for i in range(N):
    if (A[i] % 4 == 0):
        ok.append(A[i])
    elif (A[i] % 4 != 0 and A[i] % 2 == 0):
        no_and_even.append(A[i])
    else:
        no_and_no_even.append(A[i])

if (len(ok) == 0 and len(no_and_no_even) != 0):
    print('No')
    exit()
else:
    if (len(ok) < len(no_and_no_even) and len(no_and_even) != 0):
        print('No')
        exit()

if (len(ok) == len(no_and_no_even) or len(ok) == len(
        no_and_no_even) - 1 or len(ok) > len(no_and_no_even)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14480
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 最大値 */
	private static final int MAX = 100_000;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] count = new int[MAX];
			count[0] = 0;
			IntStream.range(1, MAX).forEach(i -> count[i] = count[i - 1] + (isPalindromic(i) ? 1 : 0));
			int a = scanner.nextInt(), b = scanner.nextInt();
			System.out.println(count[b] - count[a - 1]);
		}
	}

	/**
	 * 入力数字の10進数表現は回文かどうかを計算
	 * 
	 * @param n 入力数字
	 * @return 入力数字の10進数表現は回文かどうか
	 */
	private static boolean isPalindromic(int n) {
		char[] s = String.valueOf(n).toCharArray();
		for (int i = 0; i < s.length / 2; i++) {
			if (s[i] != s[s.length - 1 - i]) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 45480
#include <bits/stdc++.h>
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 FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s; cin>>s;
	int n=s.size();
	if(s=="keyence") return cout<<"YES"<<endl,0;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(n-(j-i+1)==7){
				string t="";
				rep(k,n){
					if(k<i||k>j) t+=s[k];
				}
				if(t=="keyence") return cout<<"YES"<<endl,0;
			}
		}
	}
	cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = Console.ReadLine();
            string[] b = a.Split(' ');

            int c1 = 0;
            int d0 = 0;
            int c = int.Parse(b[1]);
            int d = int.Parse(b[0]);

            for (int i= 0; i<c; i++)
            {
               d0 = (int)(Math.Pow(10, i)) * d +d0 ;
            }

            for (int i = 0; i<d; i++)
            {
                c1 = (int)(Math.Pow(10, i)) * c + c1;
            }

            if (c1<d0)
            {
                Console.WriteLine(d0);
            }
            else
            {
                Console.WriteLine(c1);

            }

        }

    }
}

Measured memory_bytes: 11092
# -*- coding: utf-8 -*-

def main():
    # 整数の入力
    n, a, b = map(int, input().split())

    # 雑な探索
    sum = 0
    for i in range(1, n+1):
        # 桁数
        keta = len(str(i))
        num = i
        sum_all_keta = 0
        for j in range(keta):
            sum_all_keta += num % 10
            num = num // 10

        # print(sum_all_keta)
        if a <= sum_all_keta <= b:
            sum += i

    print(sum)


main()


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

using namespace std;

string s;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> s;
	if (s == "SUN") cout << 7 << endl;
	if (s == "MON") cout << 6 << endl;
	if (s == "TUE") cout << 5 << endl;
	if (s == "WED") cout << 4 << endl;
	if (s == "THU") cout << 3 << endl;
	if (s == "FRI") cout << 2 << endl;
	if (s == "SAT") cout << 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>

using namespace std;

int main(int argc, const char * argv[]) {
    string s1="CODEFESTIVAL2016";
    string s2;
    cin>>s2;
    int count=0;
    for (int i=0; i<16; i++) {
        if (s1[i]-s2[i]!=0) {
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int H, W, A, B;

void MAIN() {
    scanf("%d%d%d%d", &H, &W, &A, &B);
    REP (i, H) {
	REP (j, W) {
	    char c = '0';
	    if (A <= j) c ^= 1;
	    if (B <= i) c ^= 1;
	    putchar(c);
	}
	puts("");
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1280
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long N, D;
    cin >> N >> D;
    long long ans = 0;
    long long D2 = D * D;
    for (long long i = 0; i < N; ++i) {
        long long x, y;
        cin >> x >> y;
        long long d2 = x * x + y * y;
        if (d2 <= D2) {
            ++ans;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a + b + c <= 21 ? "win\n" : "bust\n");
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]

dic=Counter(a)
if n%2!=0:
    ans=2**((n-1)//2)
    if dic[0]!=1:
        ans=0
    for i in range(1,n//2+1):
        if dic[i*2]!=2:
            ans=0
            break
else:
    ans=2**(n//2-1)*2
    for i in range(1,n//2+1):
        if dic[i*2-1]!=2:
            ans=0
            break
print(ans%(10**9+7))    

Measured memory_bytes: 14820
let () =
  Scanf.scanf "%d %d\n" @@ fun n k ->
  let h = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let ans = Array.fold_left (fun a x -> if x >= k then a+1 else a) 0 h in
  Printf.printf "%d\n" ans

Measured memory_bytes: 6684
#include<iostream>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  string ans = "No";
  for(int i = 0; i <= N/7; i++){
    if((N-7*i) % 4 == 0 && (N-7*i) >=0){
    ans = "Yes";
    break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,x,M=map(int,input().split())
k=x
L=list()
c=dict()
for i in range(M):
  if i==N:
    print(sum(L))
    exit()
  if x==0:
    print(sum(L))
    exit()
  L.append(x)
  x=(x*x)%M
  if x in c:
    q=x
    break
  c[x]=1
moto=sum(L)
N-=len(L)
for i in range(len(L)):
  if L[i]==q:
    roop=list(L[i:])
L=roop
a=len(L)
if N%a==0:
  print(moto+(sum(L)*(N//a)))
else:
  s=N//a
  t=N%a
  ans=sum(L)*s
  ans+=sum(roop[:t])
  print(moto+ans)

Measured memory_bytes: 14340
#include<stdio.h>
int main(void)
{
    int h,m,s;
	scanf("%d",&s);
	h=s/3600;
	s=s%3600;
	m=s/60;
	s=s%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
n = gets.to_i
as = gets.split.map(&:to_i)
avg, rem = as.inject(:+).divmod(n)

if rem.zero?
  p(as.inject(0) { |pre, x| pre + (x - avg)**2 })
else
  off = as.inject(0) { |pre, x| pre + (x - avg)**2 }
  up = as.inject(0) { |pre, x| pre + (x - (avg + 1))**2 }
  p up < off ? up : off
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
  char s[100000];
  int i;
  cin >> s;
  for(i=0;i<100000;i+=2){
    if(s[i]!=0){
      cout << s[i];
    }else{
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
map<string,bool> a;
int main()
{
	int n;
	cin>>n;
	char la=' ';
	string h;
	cin>>h;
	la=char(h[h.length()-1]);
	a[h]=true;
	for(int i=1;i<n;i++)
	{
		cin>>h;
		if(a[h] || char(h[0])!=la)
		{
			cout<<"No"<<endl;
			return 0;
		}
		la=h[h.length()-1];
		a[h]=true;
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

int main(){
    cin >> k;
    int curr = 0;
    int ans = -1;
    for(int i=0; i<=k; i++){
        curr*=10; curr+=7; curr%=k;
        if(curr%k == 0){
            ans = i+1;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
from itertools import product

n, m = map(int, input().split())
ss = product([0, 1], repeat=n)
lb = [[0] * n for _ in range(m)]
for i in range(m):
    tmp = list(map(int, input().split()))
    k = tmp.pop(0)
    for j in tmp:
        lb[i][j-1] = 1

p = list(map(int, input().split()))
ans = 0
# n個スイッチのパターンループ
for state in ss:
    flag = True
    sc = 0
    # 電球のスイッチ条件1～iループ
    for j, l in enumerate(lb):
        if sum([min(e) for e in zip(l, state)]) % 2 != p[j]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	int N, *d;

	cin >> N;

	d = new int[N];

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

	sort(d, d + N, greater <int>());

	cout << d[N / 2- 1] - d[N / 2];
	
	return 0;
}


Measured memory_bytes: 640
n, m = map(int, input().split())
ans = [0]*(n+1)

for _ in range(m):
    a,b = map(int, input().split())
    ans[a] += 1
    ans[b] += 1
#print(ans)
#print(ans[1:])
#unpack
print(*ans[1:], sep='\n')

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

int main(int argc, char **argv)
{
    int N;
    std::cin >> N;

    std::vector<int> d(N);

    for(int i = 0; i < N; i++){
        std::cin >> d.at(i);
    }

    std::sort(d.begin(), d.end());

    int ans = 0;
    int prev = 0;
    for(int i = 0; i < N; i++){
        if(d.at(i) > prev){
            ans++;
            prev = d.at(i);
        }
    }

    std::cout << ans << std::endl;
    
}


Measured memory_bytes: 256
N, D = map(int, input().split())
List = []
for _ in range(N):
  l = list(map(int,input().split()))
  List.append(l)

counter = 0
for i in range(N):
  for j in range(N-i-1):
    base = 0
    for k in range(D):
      base += (List[i][k]-List[i+j+1][k])**2
    if float.is_integer(base**0.5):
      counter += 1
  
print(counter)

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

int main(){
  long long int n;
  cin>>n;
  if(n==1){ cout<<"1"; return 0; }
  for(int i=1;i<=n;i++){
    if(i*i>n){
      cout<<(i-1)*(i-1);
      return 0;
    }
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
 
int main() {
long A,B,V,W,T;
long lastA,lastB;
cin>>A>>V>>B>>W>>T;

    if(A<B){
        lastA=A+V*T;
        lastB=B+W*T;
        if(lastA-lastB>=0){
        cout<<"YES"<<endl;
        }else{
        cout<<"NO"<<endl;
        }


    }else{

        lastA=A-V*T;
        lastB=B-W*T;
        if(lastA-lastB<=0){
        cout<<"YES"<<endl;
        }else{
        cout<<"NO"<<endl;
        }

    }


}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

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

void solve() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a, b);
  dump(a, b, g);

  vector<ll> dv;
  for (ll i = 1; i * i <= g; i++) {
    if (g % i == 0) {
      dv.push_back(i);
      if (i * i != g) {
        dv.push_back(g / i);
      }
    }
  }
  sort(dv.begin(), dv.end());
  dump(dv);

  vector<ll> prime;
  prime.push_back(dv[0]);
  if (dv.size() > 1)
    prime.push_back(dv[1]);
  for (int i = 2; i < dv.size(); i++) {
    int flag = true;
    for (int j = 1; j < i; j++) {
      if (dv[i] % dv[j] == 0) {
        flag = false;
        break;
      }
    }
    if (flag) prime.push_back(dv[i]);
  }
  dump(prime);
  cout << prime.size() << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    array<int,15> p{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    int pl=15;
    cin.tie(0);ios::sync_with_stdio(0);
    map<int,int> f;
    int n;
    cin>>n;
    for(int q:p){
        for(int i=q;i<=n;i*=q)f[q]+=n/i;
    }
    dprint(f);
    // 75 = 3 * 5 * 5
    // (5,5,3)(15,5)(25,3)(75)
    array<int,5> oo{3,5,15,25,75};
    map<int,int> o;
    REP(i,pl){
        for(int x:oo)if(f[p[i]]>=x-1)o[x]++;
    }
    dprint(o);
    ll ans=0;
    ans+=o[ 5]*(o[5]-1)/2*(o[3]-2);
    ans+=o[15]*(o[5]-1);
    ans+=o[25]*(o[3]-1);
    ans+=o[75];

    print(ans);

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

struct choice {
  int a;
  int b;
  int c;
  ll v;

  bool operator < (const choice& rhs) const {
    if(a != rhs.a) return a < rhs.a;
    else if(b != rhs.b) return b < rhs.b;
    else if(c != rhs.c) return c < rhs.c;
    else return false;
  }

  bool operator == (const choice& rhs) const {
    return a == rhs.a && b == rhs.b && c == rhs.c;
  }
};

struct vComparator {
  bool operator()(choice& left, choice& right) {
    return left.v < right.v;
  }
};

int X, Y, Z, K;
priority_queue<choice, vector<choice>, vComparator> choices;
set<choice> chosen;
ll as[1010], bs[1010], cs[1010];

void solve() {
  choices.push(choice {0, 0, 0, as[0]+bs[0]+cs[0]});
  int count = 0;
  while(!choices.empty() && count < K) {
    choice c = choices.top(); choices.pop();
    if(chosen.find(c) != chosen.end()) continue;
    chosen.insert(c);
    printf("%lld\n", c.v);
    count++;
    choice succ;
    if(c.a+1 < X) {
      succ = choice {c.a+1, c.b+0, c.c+0, as[c.a+1]+bs[c.b+0]+cs[c.c+0]};
      choices.push(succ);
    }
    if(c.b+1 < Y) {
      succ = choice {c.a+0, c.b+1, c.c+0, as[c.a+0]+bs[c.b+1]+cs[c.c+0]};
      choices.push(succ);
    }
    if(c.c+1 < Z) {
      succ = choice {c.a+0, c.b+0, c.c+1, as[c.a+0]+bs[c.b+0]+cs[c.c+1]};
      choices.push(succ);
    }
  }
}

int main() {
  scanf("%d %d %d %d", &X, &Y, &Z, &K);
  rep(i, X) scanf("%lld", &as[i]);
  rep(i, Y) scanf("%lld", &bs[i]);
  rep(i, Z) scanf("%lld", &cs[i]);
  sort(as, as+X, greater<ll>());
  sort(bs, bs+Y, greater<ll>());
  sort(cs, cs+Z, greater<ll>());
  solve();
  return 0;
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int N;
    string X;
    cin >> N >> X;
    int popcnt = count(X.cbegin(), X.cend(), '1');

    vector<vector<ll>> delta(2, vector<ll>(N));

    auto calc = [&](ll mod, int t) {
        if (mod <= 0)
            return -1LL;
        ll digit = 1;
        ll ans = 0;
        REPR(i, N - 1, -1)
        {
            if (X[i] == '1')
                ans = (ans + digit) % mod;
            delta[t][i] = digit;
            digit = (digit * 2) % mod;
        }
        return ans;
    };

    ll p0 = calc(popcnt + 1, 0), p1 = calc(popcnt - 1, 1);

    auto solve = [](int x) {
        int cnt = 0;
        while (x > 0)
        {
            x = x % __builtin_popcount(x);
            ++cnt;
        }
        return cnt;
    };

    REP(i, 0, N)
    {
        if (X[i] == '0')
        {
            int n = (p0 + delta[0][i]) % (popcnt + 1);
            cout << solve(n % (popcnt + 1)) + 1 << "\n";
        }
        else
        {
            if (p1 == -1)
            {
                cout << "0\n";
                continue;
            }
            int n = (p1 - delta[1][i] + popcnt - 1) % (popcnt - 1);
            cout << solve(n % (popcnt - 1)) + 1 << "\n";
        }
    }
}


Measured memory_bytes: 8356
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

signed main(){
  str s;
  cin>>s;
  int a=0,b=0;
  rep(i,s.length()){
    if(s[i]=='1')a++;
    else b++;
  }
  cout<<(min(a,b)*2)<<endl;

  return 0;
}



Measured memory_bytes: 512
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
int siz = 1e8+1;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;

void solve(){
	int a, b;
	cin >> a >> b;
	cout << a*b << endl;
	
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


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

using namespace std;

int fun (int a, int b)
{
	int ls, lt, ms = 0, mt = 0; 
	string s, t;
	stringstream ss, tt;
	ss << a;
	s = ss.str();
	tt << b;
	t = tt.str();
	ls = s.size();
	lt = t.size();
	for (int i = 0; i < ls; i++)
	{
		ms += int (s[i] - '0');
	}
	for (int i = 0; i < lt; i++)
	{
		mt += int (t[i] - '0');
	}
	return (ms + mt);
}

int n, g = 1e9, a, b;

int main()
{
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		a = i;
		b = n - i;
		if (fun(a, b) < g)
		{
			g = fun(a, b);
		}
	}	
	cout << g;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
const int MAXN = 5010;
const int mod = 1e9 + 7;
int n, k, fac[MAXN], inv[MAXN];
int getc(int n, int m) {
  if(m > n) return 0;
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void work() {
  fac[0] = inv[0] = fac[1] = inv[1] = 1;
  for(reg int i = 2; i <= 2000; ++i) fac[i] = 1ll * fac[i - 1] * i % mod, inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
  for(reg int i = 2; i <= 2000; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % mod;
  scanf("%lld%lld", &n, &k);
  for(reg int i = 1; i <= k; ++i) printf("%lld\n", getc(k - 1, i - 1) * getc(n - k + 1, i) % mod); 
}
signed main() {
  int _ = 1;
  // scanf("%d", &_);
  while(_--) work();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int W[1010][1010], B[1010][1010];

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

    int n, k;
    cin >> n >> k;
    rep(i, n)
    {
        int x, y;
        char c;
        cin >> x >> y >> c;
        x %= 2 * k;
        y %= 2 * k;
        bool f = false;
        if (x >= k && y >= k)
        {
            x %= k;
            y %= k;
        }
        else if (x >= k || y >= k)
        {
            f = true;
            x %= k;
            y %= k;
        }
        if (f)
            c = (c == 'B' ? 'W' : 'B');
        if (c == 'B')
            B[x][y]++;
        else
            W[x][y]++;
    }
    rep(i, k - 1)
    {
        rep(j, k)
        {
            W[i + 1][j] += W[i][j];
            B[i + 1][j] += B[i][j];
        }
    }
    rep(i, k - 1)
    {
        rep(j, k)
        {
            W[j][i + 1] += W[j][i];
            B[j][i + 1] += B[j][i];
        }
    }
    int ans = 0;
    rep(i, k)
    {
        rep(j, k)
        {
            int num1 = B[k - 1][k - 1];
            if (i > 0)
                num1 -= B[i - 1][k - 1];
            if (j > 0)
                num1 -= B[k - 1][j - 1];
            if (i > 0 && j > 0)
                num1 += 2 * B[i - 1][j - 1];
            int num2 = B[k - 1][k - 1] - num1;
            int num3 = W[k - 1][k - 1];
            if (i > 0)
                num3 -= W[i - 1][k - 1];
            if (j > 0)
                num3 -= W[k - 1][j - 1];
            if (i > 0 && j > 0)
                num3 += 2 * W[i - 1][j - 1];
            int num4 = W[k - 1][k - 1] - num3;
            int tmp = max(num1 + num4, num2 + num3);
            //cout << i << " " << j << endl;
            //cout << num1 << " " << num2 << " " << num3 << " " << num4 << endl;
            //cout << endl;
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 16128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    List<Tuple<int, int>>[] es;


    int MAX = 10;
    bool[] ngflag;

    int best = 9999999;

    int bestNG = 9999999;

    int N;

    void calc()
    {
        cin = new Scanner();
        N = cin.nextInt();
        int K = cin.nextInt();
        ngflag = new bool[MAX];
        for (int i = 0; i < K; i++)
        {
            ngflag[cin.nextInt()] = true;
        }

        dfs(0, 0);

        Console.WriteLine(best);
    }

    void dfs(int now, int ng)
    {
        if(now >= N)
        {
            if (bestNG > ng || (bestNG==ng && now < best))
            {
                best = now;
                bestNG = ng;
            }
            return;
        }
        for (int i = 0; i < MAX; i++)
        {
            if (now == 0 && i == 0) continue;
            int next = now * 10 + i;
            int nextNG = ng;
            if (ngflag[i]) nextNG++;
            dfs(next, nextNG);
        }
    }
}


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 nextInt()
    {
        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] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        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] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        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] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long 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 int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  map<int,int>mp;
  int a;
  REP(i,N){
    cin>>a;
    mp[a]++;
  }
  int ans=0;
  REP(i,100000){
    chmax(ans,mp[i-1]+mp[i]+mp[i+1]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4992
def main():
    sts=input()
    n= len(sts)
    mod = 10**9+7
    s = []
    for c in sts:
        s.append(c)

    dp = [[0 for _ in range(13)]for _ in range(n)]

    ss = s[0]
    if ss == '?':
        for i in range(10):
            dp[0][i] = 1
    else:
        ss = int(ss)
        dp[0][ss] = 1

    for i in range(1,n):
        ss = s[i]
        if ss == "?":
            for k in range(10):
                for j in range(13):
                    dp[i][(j * 10 +k) % 13] += dp[i-1][j]
        else:
            for j in range(13):
                dp[i][(j * 10 +int(ss)) % 13] += dp[i-1][j]
        for j in range(13):
            dp[i][j]%= mod


    print(dp[n-1][5])

main()

Measured memory_bytes: 70044
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	int a[110];
	for (int i = 0; i < N; ++i)cin >> a[i];
	int i = 0;
	int ans = 0;
	while (i < N) {
		int sum = 1;
		if (a[i] == a[i + 1]) {
			while (a[i] == a[i + 1]) {
				sum++;
				i++;
				if (i == N)break;
			}
		}
		i++;
		ans += sum / 2;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

const ll N = 1700000, M = 1e5 + 3;
const ll BIG = 9e18, CH = 27;
const double EPS = 1e-5;

vector<vector<ll>> gr;
vector<ll> depth, par;

void dfs(ll v) {
	for (ll i = 0; i < (ll) gr[v].size(); i++) {
		if (gr[v][i] != par[v]) {
			par[gr[v][i]] = v;
			depth[gr[v][i]] = depth[v] + 1;
			dfs(gr[v][i]);
		}
	}
}

ll sec, frst;

void dfs2(ll v) {
	sec++;
	for (ll i = 0; i < (ll) gr[v].size(); i++) {
		if (gr[v][i] != par[v]) {
			dfs2(gr[v][i]);
		}
	}

}
int main() {
	//freopen("polygon.in", "r", stdin), freopen("polygon.out", "w", stdout);
	cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
	ll n;
	cin >> n;
	gr.resize(n);
	depth.resize(n);
	par.resize(n);
	ll fr, to;
	for (ll i = 0; i < n - 1; i++) {
		cin >> fr >> to, fr--, to--;
		gr[fr].push_back(to);
		gr[to].push_back(fr);
	}
	par[0] = 0;
	dfs(0);
	ll v = n - 1, d;
	if (depth[v] % 2 == 1)
		d = (depth[v] + 1) / 2;
	else
		d = depth[v] / 2 + 1;
	while (depth[v] != d) {
		v = par[v];
	}
	dfs2(v);
	frst = n - sec;
	if (sec < frst)
		cout << "Fennec";
	else
		cout << "Snuke";
	return 0;
}


Measured memory_bytes: 12032
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll r, c;
  cin >> r >> c;
  vector<vector<ll> > vec(r+1, vector<ll>(c+1, 0));
  rep (i, r) rep (j, c) cin >> vec[i][j];
  rep (i, r) {
    ll sum = 0;
    rep (j, c) sum += vec[i][j];
    vec[i][c] = sum;
  }
  rep (j, c + 1) {
    ll sum = 0;
    rep (i, r) sum += vec[i][j];
    vec[r][j] = sum;
  }
  rep (i, r+1) {
    bool flag = false;
    rep (j, c+1) {
      if (flag) cout << " ";
      flag = true;
      cout << vec[i][j];
    }
    cout << endl;
  }
}

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



Measured memory_bytes: 3176
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()))

from heapq import heappop,heappush,heapify
def main1(a,b,c,k):
  ans=[]
  for x in a:
    for y in b:
      ans.append(-x-y)
  ans.sort()
  ans=ans[:k] if len(ans)>=k else ans+[0]*(k-len(ans))
  ans1=[]
  for z in c:
    for xy in ans:
      heappush(ans1,xy-z)
  for _ in range(k):
    print(-heappop(ans1))
def main2(a,b,c,k):
  a.sort(reverse=True)
  b.sort(reverse=True)
  c.sort(reverse=True)
  al=[]
  for i,x in enumerate(a):
    for j,y in enumerate(b):
      for l,z in enumerate(c):
        if (i+1)*(j+1)*(l+1)<=k:
          al.append(x+y+z)
        else:
          break
  al.sort()
  for _ in range(k):
    print(al.pop())

main2(a,b,c,k)



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

int main() {
  int N;
  string S;
  cin>>N>>S;

  if(N%2!=0){
    cout<<"No"<<endl;
    return 0;
  }

  int i=N/2;
  for(int j=0;j<i;j++){
    if(S[j]!=S[j+i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;    
}

Measured memory_bytes: 256
#BIT

N=int(input())
H=[0]+list(map(int,input().split()))
A=[0]+list(map(int,input().split()))

inf=float('inf')

#DP[height]=heightの時の最大美しさ
DP=[0]*(N+1)
#DPの最大値を求めるために使う
BIT=[0]*(N+1)

#DP[1]からDP[idx]までの最大値
def BIT_query(idx): #1<=idx
    global BIT

    res=0
    while idx>0:
        res=max(res,BIT[idx])
        idx-=idx&(-idx)
    return res

#DP[idx]がxに変化したときにBITを変化させる
def BIT_update(idx,x):
    global BIT
    global N

    while idx<=N:
        BIT[idx]=max(BIT[idx],x)
        idx+=idx&(-idx)

DP[H[1]]=A[1]
BIT_update(H[1],A[1])
#print(DP,BIT)
for i in range(2,N+1):
    rel=BIT_query(H[i]-1)+A[i]
    if rel>DP[H[i]]:
        DP[H[i]]=rel
        BIT_update(H[i],rel)
    #print('i={0}'.format(i),DP,BIT)

print(BIT_query(N))


    




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

int main() {
  string W;
  cin >> W;
  if (W == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (W == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else if (W == "Rainy") {
    cout << "Sunny" << endl;
  }
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


int N;

void MAIN() {
    scanf("%d", &N);

    VI p;
    LL ans = 0;
    REP (i, N) {
	LL a, b;
	scanf("%lld%lld", &a, &b);
	ans += b;
	if (a > b) {
	    p.push_back(b);
	}
    }

    if (p.empty()) {
	puts("0");
    } else {
	ans -= *min_element(p.begin(), p.end());
	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
#define endstring std::string::npos
#define prtarr(n,len) {for(int i=0;i<len;i++) cout<<n[i]<<" "; cout<<"\n";}
#define prtpair(n) {cout<<n.fr<<" "<<n.sc<<"\n";}
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;
int judge(int x,int y){
    cout<<"? "<<x+1<<" "<<y+1<<endl;
    int a; cin>>a;
    return a;
}

ll n;
int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    cin>>n;
    vll dp(n+1,0);
    for(int i=0;i<n+1;i++){
        if(i<3) dp[i]=0;
        else{
            dp[i]+=1;
            for(int j=3;j<=i;j++) if(i-j>=3) dp[i]+=(dp[i-j])%MOD;
        }
    }
    //prtarr(dp,dp.size());
    cout<<dp[n]%MOD;


    return 0;
}




Measured memory_bytes: 3628
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = nextInt()
    val g = Graph(N)
    repeat(N - 1) {
        val (a, b, c) = nextIntList()
        g.addEdge(a, b, c)
        g.addEdge(b, a, c)
    }
    val (Q, K) = nextIntList()
    val d = g.dijkstra(K)
    repeat(Q) {
        val (x, y) = nextIntList()
        println(d[x] + d[y])
    }
}

class Graph(v: Int) {
    private val vec = Array(v + 1) { mutableListOf<E>() }

    fun addEdge(a: Int, b: Int, c: Int) = addEdge(a, b, c.toLong())
    fun addEdge(a: Int, b: Int, c: Long = 0L) {
        vec[a].add(E(b, c))
    }

    fun dijkstra(start: Int): LongArray {
        val que = PriorityQueue<E>(11, Comparator { o1, o2 -> (o1.c - o2.c).toInt() })
        que.add(E(start, 0))
        val d = LongArray(vec.size) { -1 }
        d[start] = 0
        while (que.isNotEmpty()) {
            val cur = que.poll()
            if (d[cur.v] < cur.c) continue
            for (next in vec[cur.v]) {
                if (d[next.v] < 0 || d[next.v] > d[cur.v] + next.c) {
                    d[next.v] = d[cur.v] + next.c
                    que.add(next)
                }
            }
        }
        return d
    }

    data class E(val v: Int, val c: Long)
}

Measured memory_bytes: 94560
import math

def make_tree(n):
    i = 2
    while True:
        if i >= n * 2:
            tree = [0] * i
            break
        else:
            i *= 2
    return tree

def get(i):
    i += len(tree) // 2
    ans = 0
    while True:
        if i == 0:
            break
        ans += tree[i] 
        i //= 2
    return ans

def update(s, t, x):
    s += len(tree) // 2
    t += len(tree) // 2
    while True:
        if s > t:
            break
        if s % 2 == 0:
            s //= 2
        else:
            tree[s] += x
            s = (s + 1) // 2
        if t % 2 == 1:
            t //= 2
        else:
            tree[t] += x
            t = (t - 1) // 2
    return

n, d, a = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
s.sort()
tree = make_tree(n)
l = len(tree)
for i in range(n):
    tree[i + l // 2] = s[i][1]
y = [n - 1] * n
j = 0
for i in range(n):
    if j == n:
        break
    while True:
        if j == n:
            break
        if s[i][0] + 2 * d >= s[j][0]:
            j += 1
        else:
            y[i] = j - 1
            break
ans = 0
for i in range(n):
    h = get(i)
    if h > 0:
        c = math.ceil(h / a)
        ans += c
        update(i, y[i], -1 * a * c)
print(ans)

Measured memory_bytes: 119384