akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
auto solve(string s_) {
    auto NK = s_.split.map!(to!long)();
    immutable N=NK[0], K=NK[1];
    auto xys = new long[2][N];
    long[] xs; xs.reserve(N);
    long[] ys; ys.reserve(N);
    foreach(ref xy;xys) {
        xy=readln.split.map!(to!long).array();
        xs~=xy[0];
        ys~=xy[1];
    }
    xs=xs.sort.uniq.array();
    ys=ys.sort.uniq.array();
    immutable xn=xs.length;
    immutable yn=ys.length;
    auto dp=new int[][](xn,yn);
    foreach(ref xy;xys) {
        long idx(long[] as, long v) {
            long l=0,r=as.length-1;
            while(l!=r) {
                immutable m=(l+r)/2;
                if(as[m]==v) return m;
                if(as[m]<v) l=m+1;
                else        r=m-1;
            }
            return l;
        }
        immutable xi=idx(xs,xy[0]);
        immutable yi=idx(ys,xy[1]);
        dp[idx(xs,xy[0])][idx(ys,xy[1])]++;
    }
    foreach(xi;0..xn) foreach(yi;0..yn) {
        if(xi!=0) dp[xi][yi]+=dp[xi-1][yi];
        if(yi!=0) dp[xi][yi]+=dp[xi][yi-1];
        if(xi!=0 && yi!=0) dp[xi][yi]-=dp[xi-1][yi-1];
    }
    long m=long.max;
    foreach(xi;0..xn-1) foreach(yi;0..yn-1) {
        foreach(xj;xi..xn) foreach(yj;yi..yn) {
            auto c=dp[xj][yj];
            if(xi!=0) c-=dp[xi-1][yj];
            if(yi!=0) c-=dp[xj][yi-1];
            if(xi!=0 && yi!=0) c+=dp[xi-1][yi-1];
            if(c<K) continue;
            m=min(m,(xs[xj]-xs[xi])*(ys[yj]-ys[yi]));
        }
    }
    return m;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 380
def qual(a,b,c)
  if (a + b > c) && (a + c > b) && (b + c > a)
    return true
  else
    return false
  end
end
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
i = 0
cand = []
while i < n - 2
  j = i + 1
  while j < n - 1
    k = j + 1
    while k < n
      cand.push([arr[i],arr[j],arr[k]])
      k += 1
    end
    j += 1
  end
  i += 1
end
count = 0
cand.each do |trio|
  unless trio.uniq.size != 3
    if qual(trio[0],trio[1],trio[2])
      count += 1
    end
  end
end
puts count

Measured memory_bytes: 29840
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    int x,y,z,o;
    cin>>x>>y>>z>>o;
    int k=max({x,y,z});
    double bilal=k*pow(2,o);
    double sum=0;
    if(k==x)sum=bilal+y+z;
    else if(k==y)sum=bilal+x+z;
    else if(k==z)sum=bilal+x+y;
    cout<<sum;




















return 0;}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
typedef long long int ll;

int main()
{
	int n, d, sum = 0;
	ll x, y, dis;
	cin >> n >> d;
	while (n--)
		{
			cin >> x >> y;
			double q = (double)sqrt(x * x + y * y);
			if (q <= (double)d)
				sum++;
		}
	cout << sum << endl;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x,a,b; cin>>x>>a>>b;
  if(abs(a-x)>abs(b-x))
  cout<<"B"<<endl;
  else
  cout<<"A"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;
  ll ans = 1;
  for (int i = 1; i <= N; i++) {
    ans = ans * i % mod;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  string s;
  int k;
  cin >> s >> k;
  vector<string> dic;
  
  for(int j=1; j<=k; j++){
    for(int i=0; i+j-1<s.size(); i++){
      string t;
      for(int l=0; l<j; l++){
        t.push_back(s[i+l]);
      }
      dic.push_back(t);
    }
  }
  
  sort(dic.begin(), dic.end());
  
  if(k==1){
    cout << dic[0] << endl;
    return 0;
  }
  
  int count = 1;
  for(int i=1; i<dic.size(); i++){
    if(dic[i]!=dic[i-1])
      count++;
    if(count==k){
      cout << dic[i] << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

int h,w;
int board[21][21];
vector<string> ss;

void moveG(int &x,int &y,char p){
    int tx,ty;
    tx = x;
    ty = y;
    if(p == '5'){
	return;
    }else if(p == '8'){
	if(y > 0)
	    y--;
    }else if(p == '6'){
	if(x < w-1)
	    x++;
    }else if(p == '4'){
	if(x > 0)
	    x--;
    }else if(p == '2'){
	if(y < h-1)
	    y++;
    }

}
int main(){
    while(true){
	cin >> h >> w;
	if(h == 0 && w == 0) break;
	string pattern;
	ss = vector<string>(h);
	REP(i,h) cin >> ss[i];
	cin >> pattern;

	int sx,sy,gx,gy;
	int ans = 0;
	REP(i,h)REP(j,w){
	    board[i][j] = INF;
	    if(ss[i][j] == 'A'){
		sx = j;
		sy = i;
	    }else if(ss[i][j] == 'B'){
		gx = j;
		gy = i;
	    }
	}

	bool flg = false;
	int p = 0;
	int t = 0;
	board[sy][sx] = 0;
	queue<int> qx;
	queue<int> qy;
	qx.push(sx);
	qy.push(sy);
	while(!qx.empty()){
	    int x = qx.front();
	    int y = qy.front();
	    qx.pop();
	    qy.pop();
	    int v = board[y][x]+1;
	    REP(i,4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx < 0 || w <= nx || ny < 0 || h <= ny || ss[ny][nx] == '#') continue;
		if(board[ny][nx] > v){
		    board[ny][nx] = v;
		    qx.push(nx);
		    qy.push(ny);
		}
	    }
	}
	bool u[31][31];
	REP(i,31)REP(j,31) u[i][j] = false;
	while(t < 1000){
	    if(board[gy][gx] <= t ){
		printf("%d %d %d\n",t,gy,gx);
		flg = true;
		break;
	    }
	    moveG(gx,gy,pattern[p]);
	    p = (p+1) % pattern.size();
	    t++;
	}
	if(!flg) cout << "impossible" << endl;
    }

    return 0;
}

Measured memory_bytes: 1244
n=int(input())
w=list(map(int,input().split()))
su=sum(w)
av=su/2
s=0
fs=0
for iii in range(n):
  fs=s
  s+=w[iii]
  if s>=av:
    print(min(abs(su-fs-fs),abs(su-s-s)))
    break


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] array = new int[n + 1];

		for(int i = 2; i <= n; i++) {//2~nに対して
			int a = i;
			for(int j = 2; j <= a;) {//素因数分解して、因数をarray配列に詰める
				if(a % j == 0) {
					a = a / j;
					array[j]++;
				} else {
					j++;
				}
			}
		}
		long sum = 1;
		for(int i = 0; i <= n; i++) {
			sum *= (array[i] + 1);
			sum %= 1000000007;
		}

		System.out.println(sum);
	}
}




Measured memory_bytes: 35656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
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 () {
  int n = in();
  vi a(n);
  rep(i,n) cin >> a[i];
  reverse(rng(a));
  rep(i,n) {
    if (i) cout << ' ';
    cout << a[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll n, k;
    cin >> n >> k;
    vector<ll> w(n), d(n);
    REP(i,n) cin >> w[i] >> d[i];

    auto isok = [&](ll x) {
        ll f = 0;
        REP(i,n) {
            if (x < w[i]) continue;
            f += (x-w[i]) / d[i]+1;
            if (k <= f) return true;
        }
        //cerr << f << endl;
        return (k <= f);
    };

    ll ok = 1LL << 62, ng = 0;

    while(abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (isok(mid)) ok = mid;
        else ng = mid;
        //cerr << mid << endl;
    }

    OUT(ok)

    return 0;
}

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

using namespace std;

int cut(vector<int>, int);

int main(){
    int N, data;
    vector<int> h;
    cin >> N;
    h.push_back(0);
    for(int i = 0; i < N; i++){
        cin >> data;
        h.push_back(data);
    }
    h.push_back(0);
    int ans = cut(h, 0);
    cout << ans << endl;
}

int cut(vector<int> h, int ans){
    if(h.size() == 2) return ans;
    else if(h[1] <= h[2]){
        h.erase(h.begin()+1);
        return cut(h, ans);
    } 
    else{
        ans += (h[1] - h[2]);
        h.erase(h.begin()+1);
        return cut(h, ans);
    }
}

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

const static int INF = 1e9 + 7;

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
	if ((x += a.x) >= mod) x -= mod;
	return *this;

    }
    mint& operator-=(const mint a) {
	if ((x += mod-a.x) >= mod) x -= mod;
	return *this;

    }
    mint& operator*=(const mint a) {
	(x *= a.x) %= mod;
	return *this;

    }
    mint operator+(const mint a) const {
	mint res(*this);
	return res+=a;

    }
    mint operator-(const mint a) const {
	mint res(*this);
	return res-=a;

    }
    mint operator*(const mint a) const {
	mint res(*this);
	return res*=a;

    }
    mint pow(ll t) const {
	if (!t) return 1;
	mint a = pow(t>>1);
	a *= a;
	if (t&1) a *= *this;
	return a;

    }

    // for prime mod
    mint inv() const {
	return pow(mod-2);

    }
    mint& operator/=(const mint a) {
	return (*this) *= a.inv();

    }
    mint operator/(const mint a) const {
	mint res(*this);
	return res/=a;

    }

};

class Sieve{
    public:
	int common;
	std::vector<int> f;

	Sieve(int n): f(n+1){
	    f[0] = -1, f[1] = -1;
	    for(int i = 2; i <= n; i++){
		for(int j = i + i; j <= n; j = j + i){
		    if(f[j]) continue;
		    f[j] = i;
		}
	    }
	}

	std::vector<int> factorList(int n){
	    std::vector<int> fl;
	    while(f[n] != 0){
		fl.push_back(f[n]);
		n /= f[n];
	    }
	    fl.push_back(n);
	    return fl;
	}

	std::map<int, int> factor(int n){
	    std::map<int, int> mp;
	    std::vector<int> f = factorList(n);
	    for(int i = 0; i < f.size(); i++){
		mp[f[i]]++;
	    }
	    return mp;

	}


};

int main(void){
    int n;

    std::cin >> n;
    std::vector<int> A(n);
    Sieve sieve = Sieve(1000001);

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

    // std::map<int, int> fl = sieve.factor(10000000);
    std::map<int, int> lcmm;
    mint lcm = 1;
    for(int i = 0; i < n; i++){
	std::map<int, int> cur = sieve.factor(A[i]);
	int tmp = 0;
	for(auto j = cur.begin(); j != cur.end(); j++){
	    lcmm[j->first] = std::max(lcmm[j->first], j->second);
	}
    }
    for(auto i = lcmm.begin(); i != lcmm.end(); i++){
	for(int j = 0; j < i->second; j++){
	    lcm *= i->first;
	}
    }
    mint ans;
    for(int i = 0; i < n; i++){
        mint b = lcm / A[i];
	ans += b;
    }
    std::cout << ans.x << std::endl;

    return 0;
}



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

int main(){
	int n;
	vector <int> d;
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		d.push_back(t);
	}
	sort(d.begin(),d.end());
	cout<<d[n/2]-d[n/2-1]<<endl;
	return 0;
}

Measured memory_bytes: 892
#encoding:utf-8 No.0032 2014.10.6
data = []
while gets
  input = $_.chomp.split(/,/)
  data.push input.map{|item| item = item.to_i}
end

rectangle = 0
diamond = 0

data.length.times do |i|
  if data[i][0]**2 + data[i][1]**2 == data[i][2]**2
    rectangle += 1
  elsif data[i][0] == data[i][1]
    diamond += 1
  end
end

puts rectangle
puts diamond

Measured memory_bytes: 6100
N, T = map(int, input().split())
A = [int(i) for i in input().split()]

l = A[0]
mp = 0
for i in range(1, N):
    if A[i]-l > mp:
        mp = A[i]-l
        c = 1
    elif A[i]-l == mp:
        c += 1
    elif A[i] < l:
        l = A[i]

print(c)


Measured memory_bytes: 16148
#include<iostream>
#include<cstring>
using namespace std;
int x[32000][500], n;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[0][i];
		}
		for (int i = 1; i < 30000; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (x[i - 1][k] == x[i - 1][j]) {
						x[i][j]++;
					}
				}
			}
		}
		for (int i = 1; i < 30000; i++) {
			for (int j = 0; j < n; j++) {
				if (x[i - 1][j] != x[i][j]) { goto E; }
			}
			cout << i - 1 << endl; 
			for (int j = 0; j < n; j++) {
				if (j) { cout << ' '; } cout << x[i][j];
			}
			cout << endl;
			goto owata;
		E:;
		}
	owata:;
	}
}

Measured memory_bytes: 63668
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from random import randint
from collections import defaultdict
from itertools import accumulate
from fractions import gcd
from collections import defaultdict
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = 3 * 10**5
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

N, K = inpl()

ans = 0
for i in range(min(K+1, N)):
    ans = (ans + cmb(N, i, MOD) * cmb(N-1, i, MOD))%MOD
print(ans)


Measured memory_bytes: 75464
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b;cin>>a>>b;
  P((a+b)%24);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    int c = b - a;
    if (c <= 0)
        cout << "delicious" << endl;
    else if (c > x)
        cout << "dangerous" << endl;
    else
        cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});

process.stdin.on('end', () => {
  const stack = [];
  const tokens = content
    .trim()
    .split(' ')
    .map(line => {
      const num = parseInt(line, 10);
      return isNaN(num) ? line : num;
    });

  const opTokens = '+-/*'.split('');
  for (const token of tokens) {
    if (opTokens.includes(token)) {
      const b = stack.pop();
      const a = stack.pop();
      stack.push(expr(token, a, b));
    } else {
      stack.push(token);
    }

  }

  console.log(stack.pop());
});

const expr = (op, a, b) => {
  switch(op) {
    case '*':
      return a * b;
    case '/':
      return a / b;
    case '+':
      return a + b;
    case '-':
      return a - b;
  }
};


Measured memory_bytes: 16232
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int sumb = 0;
        int sumc = 0;

        /*
        if(K >= A) {
            sumb = K - A;
            if(sumb > 0) {
                sumc = K - A - B;
            }
            System.out.println(A - sumc);
        } else System.out.println(K);
        */

        //別解
        int xa = Math.min(A,K);
        K -= xa;
        int xb = Math.min(B,K);
        K -= xb;
        int xc = K;
        int ans = xa -xc;
        System.out.println(ans);

    }
}

Measured memory_bytes: 35792
from collections import Counter
n = int(input())
x = []
for i in range(n):
    s = input()
    t = Counter(s)
    x.append(t)
ans = ""
for i in "abcdefghijklmnopqrstuvwxyz":
    tmp = []
    for j in x:
        tmp.append(j[i])
    ans += i*min(tmp)
print(ans)

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

using namespace std;

#define INF 1e15

int main() {
	int n, k; cin >> n >> k;
	vector <long long> h(n);
	vector<long long> dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) cin >> h[i];
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j <= i + k; ++j) {
			if (j >= n) break;
			if (dp[j] > dp[i] + abs(h[i] - h[j])) dp[j] = dp[i] + abs(h[i] - h[j]);
		}
	}
	cout << dp[n - 1] << endl;

	return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n,x,ans=0;
    cin>>n>>x;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(all(a));
    
    for(int i = 0; i < n; i++)
    {
        if(x>=a[i])
        {
            x-=a[i];
            ans++;
            if(i==n-1 && x>0)
            {
                ans--;
            }
        }
        else break;
    }
    cout<<ans<<endl;

    return 0;
}

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

int main() {
  long n; 
  cin >> n;
  vector<long> a(n);
  vector<long> b(n);
  for (long i=0; i<n; i++){
    cin >> a.at(i);
  }
  for (long i=0; i<n; i++){
    cin >> b.at(i);
  }
  vector<long> d(n);
  for (long i=0; i<n; i++){
    d.at(i) = a.at(i) - b.at(i);
  }
  sort(d.begin(), d.end());
  
  long long sum = 0;
  for (long i=0; i<n; i++){
    sum += d.at(i);
  }
  if (sum < 0){
  cout << -1 << endl;
  }
    
  else{ 
    long j=0; //j：A<Bとなる個数
    long l=0;
    while (d.at(l) < 0){
        j++;
        l++;
    }
  
    if (j == 0){
      cout << 0 << endl;
    }
    else{
    long long dif = 0;
    for (long i=0; i<j; i++){
      dif += d.at(i);
    }    
    long k=0; //k:分配に必要な個数
    long long x = 0;
    for (long i=0; i<n-j; i++){
      k++;
      x += d.at(n-1-i);
      if (x + dif >= 0){
        cout << j+k << endl;
        break;
      }
    }
    }
  }
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;


int main(){

    int n,m;
    cin >> n;

    map<string,int> blue;
    map<string,int> red;

    rep(i,n){
        string s;
        cin >> s;

        blue[s]++;
    }

    cin >> m;

    rep(i,m){
        string s;
        cin >> s;

        red[s]++;
    }

    int ans = 0;

    for(auto itr = blue.begin(); itr != blue.end(); itr++){
        string s = (*itr).first;
        int bcount = (*itr).second;

        int rcount = red[s];

        ans = max(ans, bcount - rcount);
    }

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

Measured memory_bytes: 256
//#include<stdio.h>
#include<string.h>
 int main(void){
    int i;
    char c[1300];
    while(1){
        scanf("%c",&c[i]);
        if(c[i]>=97)printf("%c",toupper(c[i]));
        else printf("%c",tolower(c[i]));
        if(c[i]=='\n')break;
    }
    return 0;
 }

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
using namespace std;
int main(){
    int n;
    long long ans=0;
    long long ans2=0;
    cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    long long dp[100100];
    dp[0]=0;
    bool flag = true;
    for(int i=0;i<n;i++){
        if(flag==true&&dp[i]+a[i]>=0){
            dp[i+1]=-1;
            ans+=abs(a[i]-(-1-dp[i]));
        }else if(flag==false&&dp[i]+a[i]<=0){
            dp[i+1]=1;
            ans+=abs(a[i]-(1-dp[i]));
        }else{
            dp[i+1]=dp[i]+a[i];
        }
        flag =  !flag;
    }
    flag = false;
    for(int i=0;i<n;i++){
        if(flag==true&&dp[i]+a[i]>=0){
            dp[i+1]=-1;
            ans2+=abs(a[i]-(-1-dp[i]));
        }else if(flag==false&&dp[i]+a[i]<=0){
            dp[i+1]=1;
            ans2+=abs(a[i]-(1-dp[i]));
        }else{
            dp[i+1]=dp[i]+a[i];
        }
        flag =  !flag;
    }
    cout << min(ans,ans2) << endl;
}

Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

const MOD: i64 = 1000_000_007;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn dfs(s: i64, x: i64, memo: &mut HashMap<i64, HashMap<i64, i64>>) -> i64 {
    if memo.contains_key(&s) && memo[&s].contains_key(&x) {
        return memo[&s][&x];
    }
    if s == 0 {
        return 1;
    }

    if s < 0 {
        return 0;
    }
    let mut ret = dfs(s / 2, x / 2, memo);
    ret += dfs((s - 1) / 2, (x - 1) / 2, memo);
    ret %= MOD;
    if s >= 2 {
        ret += dfs((s - 2) / 2, x / 2, memo);
        ret %= MOD;
    }
    if !memo.contains_key(&s) {
        memo.insert(s, HashMap::new());
    }
    memo.get_mut(&s).unwrap().insert(x, ret);
    ret
}

fn main() {
    let n = read::<i64>();
    let mut memo = HashMap::new();
    memo.insert(0, HashMap::new());
    memo.get_mut(&0).unwrap().insert(0, 1);
    println!("{}", dfs(n, n, &mut memo));
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    string s; cin >> s;
    int cnt = 0;
    rep(i, 3){
        if(s[i] == 'R') cnt++;
    }
    if(cnt > 1 && s[1] != 'R') cnt--;
    
    cout << cnt << endl;
    return;
}

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

Measured memory_bytes: 3572
N=int(input())

t0=0
x0=0
y0=0

ans="Yes"

for i in range(N):
    t,x,y=map(int,input().split())
    d=abs(x-x0)+abs(y-y0)
    dt=t-t0
    if d>dt:
        ans="No"
    else:
        if (dt-d)%2!=0:
            ans="No"
    t0=t
    x0=x
    y0=y

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    int n = s.size();
    char pre = s[0];
    for(int i = 1; i < n; i++){
        if(s[i] == pre){
            cout << i << " " << i + 1 << endl;
            return 0;
        }
        pre = s[i];
    }
    pre = s[0];
    for(int i = 2; i < n; i += 2){
        if(s[i] == pre){
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
        pre = s[i];
    }
    pre = s[1];
    for(int i = 3; i < n; i += 2){
        if(s[i] == pre){
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
        pre = s[i];
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=1e3+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
int main()
{
	int k,x;
	scanf("%d%d",&k,&x);
	if(k*500>=x)puts("Yes");
	else puts("No");
}

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

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

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}

template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}

template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}

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

    int n;
    cin >> n;
    int a[n], b[n];
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    
    int raises = 0, possibles = 0;
    REP(i, n) {
        raises += max(0LL, a[i]-b[i]);
        possibles += max(0LL, (b[i]-a[i])/2);
    }
    if (possibles >= raises) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
 
void doit()
{
	string a,b;
	int n,m;
	cin >> n>>m;
	
	a="", b="";
	
	for(int i =0;i< n;i++)
		a+=48+m;
	
	for(int i =0;i< m;i++)
		b+=48+n;
	
	cout<< (a> b ? b : a);
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	int t=1;
	//cin >>t;
	
	while(t--)
		doit();
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ld N,K;
    cin>>N>>K;
    
    VEC(ld,kiti,N);
    VEC(ld,sum,N);
    ld m=0;
    REP(i,N){
        ld p;
        cin>>p;
        kiti[i]=(1.0+p)/2.0/p*p;
        if(i==0)sum[i]=kiti[i];else sum[i]=kiti[i]+sum[i-1];
        if(i>=K-1){
            m=max(m,sum[i]-sum[i-K]);
        }
    }
    if(K==N) cout<<fixed<<setprecision(10)<<sum[N-1];
    else cout<<fixed<<setprecision(10)<<m;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ld A, B;
    cin >> A >> B;
    int a = A, b = B * 100 + 0.5;
    a *= b;
    a /= 10;
    a /= 10;
    cout << a << '\n';
}


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>

using namespace std;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	cout << ((a[0] == 5 && a[1] == 5 && a[2] == 7) ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string A,B,C;
  cin >> A >> B >> C;
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  reverse(C.begin(),C.end());
  bool a=true,b=false,c=false;
  while (A.size()>=0&&B.size()>=0&&C.size()>=0){
    if (a){
      if (A.size()==0){
        break;
      }
      else if (A[A.size()-1]=='b'){
        a=false;
        b=true;
      }
      else if (A[A.size()-1]=='c'){
        a=false;
        c=true;
      }
      A.pop_back();
    }
    if (b){
      if (B.size()==0){
        break;
      }
      else if (B[B.size()-1]=='a'){
        a=true;
        b=false;
      }
      else if (B[B.size()-1]=='c'){
        b=false;
        c=true;
      }
      B.pop_back();
    }
    if (c){
      if (C.size()==0){
        break;
      }
      else if (C[C.size()-1]=='a'){
        a=true;
        c=false;
      }
      else if (C[C.size()-1]=='b'){
        b=true;
        c=false;
      }
      C.pop_back();
    }
  }
  if (a){
    cout << 'A' << endl;
  }
  else if (b){
    cout << 'B' << endl;
  }
  else {
    cout << 'C' << endl;
  }
}

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


/*
3,3,1,0?
111
111
000

4,4,2,1?

1110
1110
0001
0001

6,6,3,2?

111000
111000
111000
111000
000111
000111

すなわち、
・最初のw-a個は１、それ以外は０
・これをh-b行繰り返す



*/

void solve(){
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  string tmp="";
  rep(i,w-a){
    tmp = tmp + '1';
  }
  rep(i,a){
    tmp = tmp + '0';
  }
  string tmp2 = "";
  rep(i,w-a){
    tmp2 = tmp2 + '0';
  }
  rep(i,a){
    tmp2 = tmp2 + '1';
  }
  rep(i,h-b){
    cout << tmp << endl;
  }
  rep(i,b){
    cout << tmp2 << endl;
  }
}

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

Measured memory_bytes: 1280
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k; cin >> n >> k; --k;
  string s; cin >> s;
  s[k] += 32;
  cout << s << '\n';
  return 0;
}


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

int main(){

	int n;
	cin >> n;
	n = 2*n;
	int l[1001];
	for(int i = 0; i < n; i ++){
		cin >> l[i];
	}
	sort(l, l + n);
	long long ans = 0;
	for(int i = 0; i < n; i+=2){
		ans += l[i];
		// cout << l[i];
	}
	cout << ans;


}

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

int main(){
	int n, a, m;
	while( cin >> n , n ){
		map<int,int> p;
		m = 0;
		
		for(int i=0 ; i<n; i++ ){
			cin >> a;
			m = max( m , a );
			p[a] = 1;
		}
		bool flag = false;
		bool flag2 = false;
		for(int i=1 ; i<=m+1 ; i++ ){
			if( flag == false ){
				if( p.count(i) ){
					cout << i ;
					flag = true;
					flag2 = true;
				}
			}else{
				if( p.count( i ) ){
					if( flag2 )
						cout << "-";
					flag2 = false;
				}else{
					if( !flag2 )
						cout << (i-1);
					if( i < m )
						cout << " ";
					flag2 = false;
					flag = false;
				}
			}
		}
		cout << endl;
	}
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll S, W;
  scanf("%lld %lld", &S, &W);

  if (W >= S) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}


Measured memory_bytes: 3688
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N, Ma, Mb;
        static int[] a, b, c;
        
        

        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            Ma = input[1];
            Mb = input[2];
            a = new int[N];
            b = new int[N];
            c = new int[N];
            for(var i = 0; i < N; i++)
            {
                var p = cin.SplitReader();
                a[i] = p[0];
                b[i] = p[1];
                c[i] = p[2];
            }
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            int A = a.Sum();
            int B = b.Sum();
            long[,,] dp = new long[N + 1, A + 1, B + 1];

            for(var i = 0; i <= N; i++)
            {
                for(var x = 0; x <= A; x++)
                {
                    for(var y = 0; y <= B; y++)
                    {
                        if (i == 0 && x == 0 && y == 0) { dp[i, x, y] = 0; }
                        else { dp[i, x, y] = INF; }
                    }
                }
            }

            for(var i = 0; i < N; i++)
            {
                for(var x = 0; x <= A; x++)
                {
                    for(var y = 0; y <= B; y++)
                    {
                        if (dp[i, x, y] == INF) { continue; }
                        dp[i + 1, x, y] = Min(dp[i + 1, x, y], dp[i, x, y]);
                        dp[i + 1, x + a[i], y + b[i]] = Min(dp[i + 1, x + a[i], y + b[i]], dp[i, x, y] + c[i]);
   
                    }
                }
            }

            long ans = INF;
            for(var x = 1; x <= A; x++)
            {
                for(var y = 1; y <= B; y++)
                {
                    if (x * Mb == y * Ma)
                    {
                        ans = Min(ans, dp[N, x, y]);
                    }
                }
            }
            Console.WriteLine(ans == INF ? -1 : ans);
            
            //Console.Out.Flush();

        }





    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 29792
N = int(input())
S = input()

# #. というパターンをなくしたい

from collections import Counter
cntr = Counter(S)
kuro = cntr["#"]
siro = cntr["."]

ans = min(kuro, siro)
if kuro >= 1 and siro >= 1:
    tmp = N - siro # 全部白にする
    for i in range(N-1, -1, -1):
        if S[i] == ".":
            tmp += 1
            # ans = min(ans, tmp)
        else:
            tmp -= 1
            ans = min(ans, tmp)

print(ans)

    

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

int main() {
    string str;
    cin >> str;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        string ord;
        int A, B;
        cin >> ord >> A >> B;
        if (ord == "print") cout << str.substr(A, B - A + 1) << endl;
        else if (ord == "reverse") {
            string tmp = str.substr(A, B - A + 1);
            reverse(tmp.begin(), tmp.end());
            str.replace(A, B - A + 1, tmp);
        }
        else {
            string rpl;
            cin >> rpl;
            str.replace(A, B - A + 1, rpl);
        }
    }
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define ll long long
using namespace std;
ll M;
ll mul(ll x,ll y,ll m){
    ll s=0; for (;y;y>>=1,x=(x+x)%m) if (y&1) s=(s+x)%m;
    return s;
}
ll fpw(ll x,ll y,ll m){
    ll s=1; x%=m;
    for (;y;y>>=1,x=x*x%m) if (y&1) s=s*x%m;
    return s;
}
ll gcd(ll x,ll y){ return y==0?x:gcd(y,x%y); }
void exgcd(ll a,ll b,ll &x,ll &y){
    if (b==0){ x=1,y=0; return; }
    exgcd(b,a%b,y,x); y-=a/b*x;
}
ll phi(ll n){
    ll s=1;
    rep(i,2,sqrt(n))
        if (n%i==0){
            s*=i-1,n/=i; while (n%i==0) s*=i,n/=i;
            if (n==1) break;
        }
    return s*(n==1?1:n-1);
}
ll solve(ll a,ll m){
    if (m==1) return M;
    ll p=phi(m),g=gcd(m,p),_y=solve(a,g);
    ll pw=fpw(a,_y,m),c=_y%p-pw;
    //ans=m*x+pw=p*y+_y m*x-p*y=pw-_y
    //m*x-p*y=c
    ll x1,y1; exgcd(m,p,x1,y1);
    x1=(x1%(p/g)+(p/g))%(p/g)*(c/g);
    ll d=m*p/g; x1=(x1%d+d)%d;
    ll ans=(mul(x1,m,d)+pw)%d;
    while (ans<M) ans+=d;
    return ans;
}
int main(){
    int q; cin>>q;
    while (q--){
        ll a,m; cin>>a>>m; M=100;
        ll s=solve(a,m); cout<<s<<endl;
    }
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi v(n);
	REP(i, n)cin >> v[i];
	REP(i, n)v[i] -= i+1;
	ll sum = 0;
	sort(ALL(v));
	ll a = v[n / 2];
	REP(i, n)sum += abs(a - v[i]);
	cout << sum << endl;
}

Measured memory_bytes: 1024
def E():
    N = int(input())

    sum_ = 0
    c = -1

    for _ in range(N):
        a, b = list(map(int, input().split(' ')))
        if a > b:
            if c == -1:
                c = b
            elif b < c:
                c = b
            
        sum_ += a

    if c == -1:
        print(0)
    else:
        print(sum_ - c)
        
if __name__ == '__main__':
    E()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define debug(a,b,c) cout << a << " " << b << " " << c << endl;
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define inl(x,n) for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code
	int n;
	cin >> n;
	cout <<  (n%1000 ? ((n/1000)+1)*1000 - n : 0) << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n,k;
  cin>>n>>k;
  vecint v(n);
  REP(i,n) cin>>v[i];
  int mx = 0;
  REP(i,n+1)REP(j,n+1) {
    if (i+j > n) break;
    if (i+j > k) break;
    vector<int> s;
    REP(l,i) s.push_back(v[l]);
    REP(l,j) s.push_back(v[n-l-1]);
    sort(ALL(s));
    int d = k-(i+j);
    int sum=0;
    REP(l,s.size()) {
      if (l<d && s[l] < 0) continue;
      sum += s[l];
    }
    mx=max(mx,sum);
  }
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	int n;
	while(cin >> n){ 
		int weight[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		for(int i = 9; i >= 0; i--){
			if(n >= pow(2, i)){
				n -= pow(2, i);
				weight[i] = 1;
			}
		}

		int i;
		for(i = 0; i < 10; i++){
			if(weight[i]){
				cout << pow(2, i);
				i++;
				break;
			}
		}
		for(; i < 10; i++){
			if(weight[i]){
				cout << " " << pow(2, i);
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1272