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

using namespace std;

struct UnionFind{
private:
  std::vector<int> data;

public:
  UnionFind(int n = 0) : data(n, -1){}

  int find(int x){
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }

  bool unite(int x, int y){
    x = find(x); y = find(y);

    if(x == y) return false;
    else{
      if(data[x] > data[y]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
      return true;
    }
  }

  bool is_same(int x, int y){
    return find(x) == find(y);
  }

  int size(int x){
    return -data[find(x)];
  }
};

int main(){
  int N;
  cin >> N;
  
  vector<int> x(N), y(N);
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i];
  }
  
  vector<int> d_x = x, d_y = y;
  sort(d_x.begin(), d_x.end());
  sort(d_y.begin(), d_y.end());
  d_x.erase(unique(d_x.begin(), d_x.end()), d_x.end());
  d_y.erase(unique(d_y.begin(), d_y.end()), d_y.end());
  
  map<int, int> zip_x, zip_y;
  for(int i = 0; i < d_x.size(); i++){
    zip_x[d_x[i]] = i;
  }
  for(int i = 0; i < d_y.size(); i++){
    zip_y[d_y[i]] = i;
  }
  
  UnionFind uf(2 * N);
  
  for(int i = 0; i < N; i++){
    uf.unite(zip_x[x[i]], zip_y[y[i]] + N);
  }
  
  vector<long long> count_x(2 * N, 0), count_y(2 * N, 0);
  for(int i = 0; i < N; i++){
    ++count_x[uf.find(i)];
    ++count_y[uf.find(i + N)];
  }
  
  long long ans = 0;
  for(int i = 0; i < 2 * N; i++){
    ans += count_x[i] * count_y[i];
  }
  
  cout << ans - N << endl;
  
  return 0;
}

Measured memory_bytes: 13508
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;


const ll commax = 1000100;
vll fact(commax);
vll factinv(commax);
vll inv(commax);
void cominit()
{
    fact[0] = fact[1] = 1;
    factinv[0] = factinv[1] = 1;
    inv[1] = 1;
    rep(i, 2, commax) {
        fact[i] = fact[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        factinv[i] = factinv[i-1] * inv[i] % mod;
    }
}

ll com(ll a, ll b)
{
    if (a < b or a < 0 or b < 0) return 0;
    return fact[a] * (factinv[b] * factinv[a-b] % mod) % mod;
}

ll per(ll a, ll b)
{
    if (a < b or a < 0 or b < 0) return 0;
    return fact[a] * factinv[a-b] % mod;
}

ll route(ll a, ll b)
{
    return fact[a+b] * (factinv[a] * factinv[b] % mod) % mod;
}


int main()
{
        ll N, M;
        cin >> N >> M;
        if (abs(N - M) > 1) {
                cout << 0 << endl;
                return 0;
        }

        if (N == 1 and M == 1) {
                cout << 2 << endl;
                return 0;
        }

        cominit();
        ll ans = -1;
        if (N == M) {
                ans = ((fact[N] * fact[N] % mod) * 2) % mod;
        } else {
                //if (M > N) swap(N, M);
                ans = (fact[N] * fact[M]) % mod;
        }
        cout << ans << endl;
}

Measured memory_bytes: 23808
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List
import qualified  Data.ByteString as B


bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

main :: IO ()
main = do 
    r <- bsToInt <$> BS.getLine  :: IO Int
    --rgbs <- BS.getLine :: IO BS.ByteString
    print $ 2 * pi * (fromIntegral r)


Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


string S;


int solve(){
	int ans = 0;
	int i = 0;
	while(S[i] == 'W' && i < SIZE(S)) i++;
	int cnt = 0;
	for(;i < SIZE(S);i++)
		if(S[i] == 'B') cnt++;
		else ans += cnt;
	return ans;
}


signed main(){
	cin >> S;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#define N 200000
#define NIL -1
typedef struct Trees{
  int parent;
  int right;
  int left;
} tree;
tree tr[N];
int depth[N];
void print(int);
void culDepth(int, int);
int main() {
  int i, j, n, node,  m, right, left, c, rooti;
  scanf("%d", &n);
  for ( i = 0; i < n; i++) {
    tr[i].parent = NIL;
    tr[i].left = NIL;
    tr[i].right = NIL;
  }
  for (i = 0; i < n; i++) {
    scanf("%d %d", &node, &m);
    for (j = 0; j < m; j++) {
      scanf("%d", &c);
      if( j == 0 ) {
	tr[node].left = c;
      } else {
	tr[left].right = c;
      }
      left = c;
      tr[c].parent = node;
    }
  }
  for ( i = 0; i < n; i++) {
    if ( tr[i].parent == NIL ) {
      rooti = i;
    }
  }
  culDepth(rooti,0);
  for ( i = 0; i < n; i++) {
    print(i);
  }
  return 0;
}

void print(int i) {
  int j, c;
  printf("node %d: parent = %d, depth = %d, ", i, tr[i].parent, depth[i]);
  if ( tr[i].parent == NIL ) {
    printf("root, ");
  } else if (tr[i].left == NIL){
    printf("leaf, ");
  } else {
    printf("internal node, ");
  }
  printf("[");
  c = tr[i].left;
  for (j = 0; c != NIL; c = tr[c].right) {
    if ( j != 0 ) {
      printf(", ");
    }
    printf("%d", c);
    j++;
  }
  printf("]\n");
  return ;
}
void culDepth(int i, int p) {
  depth[i] = p;
  if ( tr[i].right != NIL ) {
    culDepth(tr[i].right, p);
  }
  if ( tr[i].left != NIL ) {
    culDepth(tr[i].left, p+1);
  }
  return ;
}

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

using namespace std;

typedef long long LL;

int main(){
    LL X, K, D;
    cin>>X>>K>>D;

    if(X<0)X=-X;

    if(K<=X/D){
        cout<<X-D*K;
    }else{
        K-=X/D;
        X=X%D;
        LL Y=D-X;

        if(K%2==0){
            cout<<X;
        }else{
            cout<<Y;
        }
    }

    return 0;
}


Measured memory_bytes: 3636
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int nmax = 1000000;
vint bl(nmax,0);
vint wh(nmax,0);
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = n;
    bl[0]=0;
    wh[0]=0;
    REP(i,n){
        if(s[i]=='#'){
            bl[i+1]=bl[i]+1;
            wh[i+1]=wh[i];
        }else{
            bl[i+1]=bl[i];
            wh[i+1]=wh[i]+1;
        }
    }
    REP(i,n+1){
        int tmp = bl[i]+wh[n]-wh[i];
        ans = min(ans,tmp);
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

set<int> g[200005];
int main()
{
    int n, m;
    cin >> n >> m;

    for(int i = 0; i<m; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].insert(y);
        g[y].insert(x);
    }
    set<int> :: iterator it;
    bool f = 0;
    for(it = g[1].begin(); it!=g[1].end(); it++)
    {
        int v = *it;
        if(g[v].find(n)!=g[v].end())
        {
            cout << "POSSIBLE" << endl;
            f = 1;
            break;
        }
    }

    if(f == 0) cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 28416
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;
//全探索
// int main()
// {

//     int D, G;

//     cin >> D >> G;

//     vector<int> P(D);
//     vector<int> C(D);

//     int sum = 0;
//     vector<int> sum_st(D);
//     vector<int> sum_ed(D);

//     for (int i = 0; i < D; i++)
//     {

//         cin >> P[i] >> C[i];

//         sum_st[i] = sum;

//         sum = sum + P[i];

//         sum_ed[i] = sum;
//     }

//     int score = 0;

//     int bit = 0;

//     int ans = sum;

//     for (ll bit = 0; bit < (1 << sum); bit++)
//     {

//         int score = 0;
//         int trys = 0;
//         for (int i = 0; i < D; i++)
//         {

//             bool all_flag = 1;

//                 int mini_try =0;
//             for (int k = sum_st[i]; k < sum_ed[i]; k++)
//             {

//                 if (bit & (1 << k))
//                 {

//                     mini_try++;

//                     trys++;
//                     score += (i+1)*100;
//                 }
//                 else
//                 {

//                     all_flag = 0;
//                 }
//             }

//             if(i==0){

//               cout << bit << endl;

//             }

//             if (all_flag == 1)
//             {

//                 if(P[i]!=1){
//                     cout << P[i] << endl;

//                 }

//                 score += C[i];
//             }
//         }

//         if (G <= score)
//         {

//             ans = min(trys, ans);
//         }
//     }

//     cout << ans << endl;

//     return 0;
// }

int main()
{

    int D, G;

    cin >> D >> G;

    vector<int> P(D);
    vector<int> C(D);

    int sum = 0;

    for (int i = 0; i < D; i++)
    {

        cin >> P[i] >> C[i];

        sum += P[i];
    }

    int ans = sum;

    for (int bit; bit < (1 << D); bit++)
    {

        vector<int> use(0);
        int unuse = 0;
        for (int i = 0; i < D; i++)
        {

            if ((1 << i) & bit)
            {

                use.push_back(i);
            }
            else
            {

                unuse = max(i, unuse);
            }
        }

        int score = 0;

        int trys = 0;

        for (int k :use)
        {

            score += C[k];

            score += P[k] * (k + 1) * 100;
            trys += P[k];
        }

        if (score >= G)
        {

            ans = min(trys, ans);
        }

        else
        {

            bool kasu_flag = 1;

            for (int j = 0; j < P[unuse] - 1; j++)
            {

                score += 100 * (unuse + 1);
                trys++;

                if (score >= G)
                {

                    kasu_flag = 0;
                    ans = min(trys, ans);

                    break;
                }
            }
        }
    }


cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
#define int long long
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
//素因数分解
map<int, ll> pri[SIZE]={};
void fuc(int idx, ll a){
	ll b=a;
	//cout<<a<<":";
	for(int i=2;i*i<=a;i++){
		while(a%i==0){
			pri[idx][i]++;
			a/=i;
			//cout<<i<<" ";
		}
	}
	if(a!=1){
		pri[idx][a]++;
		//cout<<a<<" ";
	}
	//cout<<endl;
}
signed main(){

	ll N;
	cin>>N;
	vll A;
	ll lcm=0;
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	map<ll, ll> maxi;
	for(int i=0;i<N;i++){
		fuc(i, A[i]);
		for(pll p:pri[i]){
			maxi[p.first]=max(maxi[p.first], p.second);
		}
	}

	ll LCM=1;
	for(pll p:maxi){
		for(int i=0;i<p.second;i++){
			LCM*=p.first;
			LCM%=MOD;
		}
	}
	//cout<<LCM<<endl;
	ll ans=0;
	for(int i=0;i<N;i++){
		ans+=(LCM*mod_pow(A[i], MOD-2, MOD));
		ans%=MOD;
	}

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

Measured memory_bytes: 3968
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ll a,b,c;

void solve(){
    cin >> a >> b >> c;
    if(a%2==0 || b%2==0 || c%2==0){
        cout << 0 << endl;
        return;
    }
    ll d=min(a*b,min(b*c,c*a));
    cout << d << endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=1000000007,BS,k;
ll fun(ll l,ll r){
    if(l>r)return 0;
    ll num;
    num=(r-l)/3+1;
    return num;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
      
        ll arr[5];
        for(ll i=0;i<5;i++){
            cin>>arr[i];

        }
        for(ll i=0;i<5;i++)
        if(arr[i]==0)
        cout<<i+1;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string A, B;
  cin >> A >> B;

  int a_l = A.length();
  int b_l = B.length();
  if (a_l > b_l) {
    cout << "GREATER" << endl;
    return 0;
  }
  if (a_l < b_l) {
    cout << "LESS" << endl;
    return 0;
  }

  REP(i, a_l) {
    if (A.at(i) > B.at(i)) {
      cout << "GREATER" << endl;
      return 0;
    }
    if (A.at(i) < B.at(i)) {
      cout << "LESS" << endl;
      return 0;
    }
  }

  cout << "EQUAL" << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

int n;
ld pr[3005];
ld dp[3005][3005];

// probability of getting h heads on first c coin flips
ld solve(int h, int c) {
  if (h == 0 && c == 0) {
    return 1.0L;
  }
  if (h < 0 || c == 0 || h > c) {
    return 0;
  }
  ld& res = dp[h][c];
  if (res > -1e-9) {
    return res;
  }
  res = pr[c] * solve(h - 1, c - 1) + (1 - pr[c]) * solve(h, c - 1);
  return res;
}

int main() {
  fill(&dp[0][0], &dp[0][0] + 3005 * 3005, -1.0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> pr[i];
  }
  ld res = 0;
  for (int i = 0; i <= n; i++) {
    if (i > n - i) {
      res += solve(i, n);
    }
  }
  cout << fixed << setprecision(30) << res << '\n';
  return 0;
}


Measured memory_bytes: 141696
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int bfs(const vector<vector<char>>& field, int H, int W) {
    v2int score_map(H, vint(W, -1));
    queue<pair<int, int>> q;
    rep(i, H) {
        rep(j, W) {
            if (field[i][j] == '#') {
                q.push(make_pair(i, j));
                score_map[i][j] = 0;
            }
        }
    }
    auto move = { make_pair(0, 1), make_pair(1, 0), make_pair(0, -1), make_pair(-1, 0) };
    int max_dist = 0;
    while (1) {
        if (q.size() <= 0) break;
        auto nd = q.front();
        q.pop();

        for (auto &m : move) {
            auto adj_i = nd.first + m.first;
            auto adj_j = nd.second + m.second;
            if (adj_i >= 0 && adj_i < H && adj_j >= 0 && adj_j < W) {
                if (score_map[adj_i][adj_j] == -1) {
                    score_map[adj_i][adj_j] = score_map[nd.first][nd.second] + 1;
                    max_dist = max(score_map[adj_i][adj_j], max_dist);
                    q.push(make_pair(adj_i, adj_j));
                }
            }
        }
    }
    return max_dist;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> field(H, vector<char>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> field[i][j];
        }
    }
    cout << bfs(field, H, W) << endl;
    return 0;
}


Measured memory_bytes: 13456
#include<stdio.h>

int A[11]={0,1,2,3,4,5,6,7,8,9,0};
int cnt=0;
int C[10];

void dfs(int i,int rest,int d,int n){
int j;

 if(i<11){
  if(d==n){
 /*   for(j=0;j<n;j++)printf("%d ",C[j]);
    printf("\n");*/
    if(rest==0){cnt++;return;}
    else return;
  }
/*  if(rest<0)return;*/

    C[d]=A[i];
    dfs(i+1,rest-A[i],d+1,n);
 
    dfs(i+1,rest,d,n);

 }

return;
}




int main(){
 int n,s;
 int ans;

 while(1){

      scanf("%d %d",&n,&s);
      if(n==0 && s==0)break;
      if(s > 55)printf("0\n");
      else {
            cnt=0;
            dfs(0,s,0,n);
            printf("%d\n",cnt);

      }

 }

 return 0;
}


Measured memory_bytes: 2044
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
A = Counter(a)
cnt = 0
for i in A.items():
    cnt += i[1]*(i[1]-1)//2
for j in a:
    k = A[j]
    before = k*(k-1)//2 
    after = (k-1)*(k-2)//2
    print(cnt -before +after)


Measured memory_bytes: 26780
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll x,y;
  cin >> x >> y;
  if(x < y)
    cout << x << endl;
  else if(x == y)
    cout << -1 << endl;
  else{
    if(x%y == 0)
      cout << -1 << endl;
    
    else{
      for(int i = 1;i < 1000000001 ; i++){
	if(x*i%y != 0){
	  cout << x*i << endl;
	  break;
	}
      }
    }
  }
  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K, S;
    cin >> N >> K >> S;
    REP(i, N) {
        if (K-- > 0)
            cout << S;
        else
            cout << (S == INF ? INF - 1 : INF);
        cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;

long mod = 1000000007;
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    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;
    }
} mint_t;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    mint ans;
    /*
    10101111001
    1***の計算 => もうちょい考えよ
    0***の計算 => 3^(len-1)
    */
    
    mint dp[100010][2] = {0};
    dp[0][0] = 1;//0,0になったことがある
    dp[0][1] = 2;//0,0になったことがない
    rep(i, len){
        if (i == 0) continue;
        if (s[i] == '1'){
            dp[i][0] = (dp[i-1][0] * 3) + (dp[i-1][1]);
            dp[i][1] = dp[i-1][1] * 2;
        } else {
            dp[i][0] = dp[i-1][0] * 3;
            dp[i][1] = dp[i-1][1];
        }
        //cout << i <<" " << dp[i][0].x <<" " << dp[i][1].x << endl;
    }

    cout << (dp[len-1][0] + dp[len-1][1]).x << endl;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define MAX 1000000010
using namespace std;
typedef long long int ll;
int dp[3010][3010];
int main(){
	int n,m,x,ans=0;
	string s,t,res="";
	cin>>s>>t;
	n=s.size(), m=t.size();
	f(i,0,n+1){
		f(j,0,m+1){
			if(i==0 || j==0) continue;
			if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}
	int a=n,b=m;
	while(dp[a][b]>0){
		int x=dp[a][b];
		if(x==dp[a-1][b]) a--;
		else if(x==dp[a][b-1])b--;
		else res+=s[a-1], a--, b--;
	}
	reverse(res.begin(),res.end());
	cout<<res;
}

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

typedef long long ll;

int D;

int main() {
    cin >> D;
    string ans = "";

    switch (D)
    {
    case 25: 
        ans = "Christmas";
        break;
    case 24:
        ans = "Christmas Eve";
        break;
    case 23:
        ans = "Christmas Eve Eve";
        break;
    case 22:
        ans = "Christmas Eve Eve Eve";
        break;
    default:
        break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int DN=1e5+5;
long long n,w,dp[105][DN],f[DN],val[DN],ma,st,dr,mij,mi,lim;
int vf(int w)
{
	mi=2e9;
	for(int j=1;j<=w;j++)
		dp[0][j]=2e9;
	for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
            dp[i][j]=dp[i-1][j];
        for(int j=0;j<=w-f[i];j++)
            dp[i][j+f[i]]=min(dp[i][j+f[i]],dp[i-1][j]+val[i]);
    }
    for(int i=w;i>=0;i--)
    	if(dp[n][i]<=lim)
    		return i;
}
int main()
{
    cin>>n>>lim;
    for(int i=1;i<=n;i++)
        cin>>val[i]>>f[i];
    cout<<vf(1e5);
}


Measured memory_bytes: 80640
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-17 16:56:16
**/
#pragma region kyomukyomupurin
#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template <class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int flag = 0; for (auto e : vec) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int flag = 0; for (auto e : st) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int flag = 0; for (auto e : mp) os << (flag++ ? ", " : "{") << e; return os << '}'; }
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
#pragma endregion kyomukyomupurin

const double PI = acos(-1);

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

  double r; cin >> r;
  cout << setprecision(17) << 2 * PI * r << endl;

  return 0;
}

Measured memory_bytes: 3804
X,K,D = map(int,input().split())

nex = abs(X) - K * D

if nex > 0:
    print (nex)

else:
    num = abs(X) // D

    a = abs(X) % D
    b = a - D

    if K % 2 == num % 2:
        print (a)
    else:
        print (abs(b))


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s, t;
    cin >> s >> t;

    int ans = LLINF;
    function<void(int,int,string)> dfs = [&](int idx, int cost, string str) {
      if(idx == n || str == t) { chmin(ans, cost); return; }
      // idx番目をstr[idx]->t[idx]にもっていくのにかかるコスト
      int diff = (t[idx]-str[idx]+10)%10;
      // [idx, i] を回転させる
      FOR(i, idx, str.size()) {
        str[i] = ((str[i]-'0') + diff)%10 + '0';
        dfs(idx+1, cost+(diff==0?0:1), str);
      }
    };

    dfs(0, 0, s);
    cout << ans << endl;
  }

  return 0;
}



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

int main(){
  string s;
  while(true){
    cin>>s;
    if(s=="#")break;
    stack<string> st;
    for(int i=0; i<s.length(); i++){
      if(s[i]=='n'){st.push(s.substr(i, 5)); i+=4;}
      else if(s[i]=='w'){st.push(s.substr(i, 4)); i+=3;}
    }
    double dir=0;
    if(st.top()=="north")dir=0.0;
    else if(st.top()=="west")dir=90.0;
    st.pop();
    int cnt=1;
    while(!st.empty()){
      if(st.top()=="north")dir-=(90.0/pow(2.0, (double)cnt));
      else dir+=(90.0/pow(2.0, (double)cnt));
      st.pop();
      cnt++;
    }
    int m=1;
    while(dir!=(double)((int)dir)){
      dir*=2;
      m*=2;
    }
    if(m==1)cout<<(int)dir<<endl;
    else cout<<(int)dir<<"/"<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    xs <- map digitToInt <$> getLine
    print $ solve xs

solve :: [Int] -> Int
solve xs = go 0 0 xs
  where
    go :: Int -> Int -> [Int] -> Int
    go res s (0:xs) = go res s xs
    go res s (x:xs) = go (max res res') (s + x) xs
      where
        res' = s + x - 1 + sum (9 <$ xs)
    go res s [] = max res s

Measured memory_bytes: 380
#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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int x;
    cin>>x;
    cout<<(long long)pow(x,3)<<endl;
    return 0;
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007LL;
const double INF=1000000000;
const int MAX=100001;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool f=true;
    for(int i=c;i<=3600+c;i+=60){
        if(i%(a+b)<=a){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

                           



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    vector<pii> edge[N];
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].pb(pii(b, i));
        edge[b].pb(pii(a, i));
    }
    int M = 1;
    cin >> M;
    ll es[M];
    fill_n(es, M, 0);
    rep(i, M){
        int u, v;
        cin >> u >> v;
        u--, v--;
        queue<int> que;
        vector<int> path[N];
        bool used[N];
        fill_n(used, N, false);
        que.push(u);
        used[u] = true;
        while(!que.empty()){
            int j = que.front();
            que.pop();
            rep(k, edge[j].size()){
                int p = edge[j][k].first;
                if(!used[p]){
                    used[p] = true;
                    que.push(p);
                    path[p] = path[j];
                    path[p].pb(edge[j][k].second);
                }
            }
        }
        rep(j, path[v].size()){
            es[i] |= 1ll<<path[v][j];
        }
    }
    ll ans = 0;
    rep(bit, 1<<M){
        ll eset = 0;
        rep(i, M){
            if(bit & 1<<i) eset |= es[i];
        }
        int white = __builtin_popcountll(eset);
        ll now = 1ll<<(N-1-white);
        if(__builtin_popcountll(bit)%2) ans -= now;
        else ans += now;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
	$n = fgets(STDIN);

	for ($i = 1; $i <= $n; $i++) {
		$x = $i;
		if ($x % 3 == 0) {
			echo " $i";
			continue;
		}

		while ($x) {
			if ($x % 10 == 3) {
				echo " $i";
				break;
			}

			$x = floor($x / 10);
		}
	}

	echo "\n";

Measured memory_bytes: 6552
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b;
  cin >> a >> b;
  if (a > 8 || b > 8)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N,i;
  long long count=0;
  scanf("%d",&N);
  int A[N+1],B[N];
  for(i=0;i<N+1;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    scanf("%d",&B[i]);
  }
  /*for(i=0;i<N;i++){
  if((A[i]+A[i+1])<=B[i]){
      count += A[i]+A[i+1];
      A[i+1] = 0;
    }else{
      count += B[i];
      if(A[i]<B[i]){
        A[i+1] = A[i+1] - (B[i]-A[i]);
      }
  }*/
  
   for(i=0;i<N;i++){
    if(A[i] >= B[i]){
      count = count + B[i];
    }else{
      if(A[i+1] >= B[i] - A[i]){
        A[i+1] = A[i+1] - (B[i] - A[i]);
        count = count + B[i];
      }else{
        count = count + A[i] + A[i+1];
        A[i+1] = 0;
      }
    } 
  }
  printf("%lld",count);
}
        

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  long double w,h,x,y; cin >> w >> h >> x >> y;
  int ok = 0;

  long double ans  = w*h/2.0;
  if(x == w/2.0 && y == h/2.0) ok = 1;

  cout  << setprecision(6) << ans << " " << ok << endl;
}


Measured memory_bytes: 3716
n = int(input())
ab, tail_a, head_b, th_a = 0, 0, 0, 0

for _ in range(n):
    s = input()
    ab += s.count('AB')
    if s[-1] == 'A' and s[0] == 'B': th_a += 1
    elif s[-1] == 'A': tail_a += 1
    elif s[0] == 'B': head_b += 1

if tail_a+head_b == 0 and th_a > 0:
    print(ab + th_a - 1)
else:
    if min(tail_a, head_b) + th_a == n:
        print(ab + min(tail_a, head_b) + th_a - 1)
    else:
        print(ab + min(tail_a, head_b) + th_a)


Measured memory_bytes: 9160
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, H, W = mi()
    A, B = i2(N)
    
    cnt = 0
    for a, b in zip(A, B):
        if a >= H and b >= W:
            cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27164
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0 

using namespace std;
using ll = long long;

int n;
ll k;
vector<int> vis;
void testcase() {
	cin >> n >> k;
	k++;
	vector<int> to(n+1);
	rep (i, 1, n) {
		int x; cin >> x;
		to[i] = x;
	}    
	vis = vector<int>(n+1, -1);
	int pos = 0, cur = 1;
	vector<int> v;
	while (vis[cur] == -1) {
		//db1(cur);
		vis[cur] = pos;
		if (pos == k-1) {
			cout << cur << "\n";
			return;
		}
		v.push_back(cur);
		pos++;
		cur = to[cur];
	}
	pos = vis[cur];
	//db1(pos);
	int cycle = v.size() - pos;
	//db1(cycle);
	k -= (ll)pos;
	//db1(k);
	int ind = k % cycle;
	if (ind==0) ind = cycle;
	cout << v[pos + ind - 1];
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 5844
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A, B = np.array([lr() for _ in range(N)]).T
if np.all(A == B):
    print(0); exit()

index = np.where(B<A)[0]
answer = np.sum(A) - np.min(B[index])
print(answer)

# 12

Measured memory_bytes: 17248
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = 900010;
static const int white = 0;
static const int gray = 1;
static const int black = 2;
using P = pair<int ,int>;

ll N;
vector<vector<P> > G(10010);

void dijkstra(){
    priority_queue<P, vector<P> , greater<P> > pq;
    vector<int> color(N,white);
    vector<int> d(N,INF);
    d[0] = 0;
    pq.push(make_pair(0,0));
    color[0] = gray;

    while(!pq.empty()){
        P f = pq.top(); pq.pop();
        int u = f.second;
        color[u] = black;

        if(d[u] > f.first ) continue;

        for(auto e : G[u]){
            int v = e.first;
            if( color[v] == black ) continue;
            if(d[v] > d[u] + e.second ){
                d[v] = d[u] + e.second;
                pq.push(make_pair(d[v], v));
                color[v] = gray;
            }
        }
    }

    rep(i,N){
        cout << i << " " << (d[i] == INF ? -1 : d[i] ) << endl;
    }
}

int main(){
    cin >> N;
    rep(j,N){
        ll u,k; cin >> u >> k;
        rep(i,k){
            ll v,c; cin >> v >> c;
            G[u].push_back(make_pair(v,c));
        }
    }

    dijkstra();
}


Measured memory_bytes: 7964
#include<iostream>
using namespace std;
int a[31],n;

void hyo(int sum=0,int size=0){
  if(sum==n){
    for(int i=0;i<size;i++){
      if(i)cout<<" ";
      cout<<a[i];
    }cout<<endl;
  }
  for(int i=n-sum;i>0;i--){
    a[size]=i;
    if(sum!=0)if(i>a[size-1])continue;
    hyo(i+sum,size+1);
  }
}

int main(){
  while(cin>>n,n)hyo();
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

ll mod_pow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = mod_pow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * mod_pow(a, b-1)) % MOD;
    }
}

ll numer[100010], denom[100010];

void calc(int n){
    numer[0]=denom[0]=1;
    for(int i=1; i<=n+1; i++){
        numer[i]=(numer[i-1]*i)%MOD;
        denom[i]=mod_pow(numer[i], MOD-2);
    }
}

ll comb(int n, int r){
    if(n<0 || r<0 || n<r) return 0;
    return numer[n]*denom[r]%MOD*denom[n-r]%MOD;
}

int main(){
    int n; cin>>n;
    vector<int> a(n+1), cnt(n+10, 0);
    for(int i=0; i<n+1; i++){
        cin>>a[i];
        cnt[a[i]]++;
    }

    int lb=-1, ub;
    for(int i=0; i<n+1; i++){
        if(cnt[a[i]]==2 && lb==-1) lb=i;
        else if(cnt[a[i]]==2) ub=i;
    }

    calc(100005);

    for(int i=1; i<=n+1; i++){
        ll ans=0;
        ans+=comb(n+1, i)-comb(n-ub+lb, i-1)+MOD;
        cout << ans%MOD << endl;
    }
}

Measured memory_bytes: 3584
//けんちょんさんに感謝！！！！！！！！！！！（2回目）

//http://drken1215.hatenablog.com/entry/2019/06/30/183400



#include <queue>
#include <iostream>
#include <map>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(long long i = 0;(i) < (n);(i)++)
using namespace std;
using ll = long long;


template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v% MOD) {
		if (val < 0) v += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * v; swap(a, b);
			u -= t * v; swap(a, b);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
		return is >> x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

template<class T> struct BiCoef {
	vector<T> fact_, inv_, finv_;
	constexpr BiCoef() {}
	constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
		init(n);
	}
	constexpr void init(int n) noexcept {
		fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
		int MOD = fact_[0].getmod();
		for (int i = 2; i < n; i++) {
			fact_[i] = fact_[i - 1] * i;
			inv_[i] = -inv_[MOD % i] * (MOD / i);
			finv_[i] = finv_[i - 1] * inv_[i];
		}
	}
	constexpr T com(int n, int k) const noexcept {
		if (n < k || n < 0 || k < 0) return 0;
		return fact_[n] * finv_[k] * finv_[n - k];
	}
	constexpr T fact(int n) const noexcept {
		if (n < 0)  return 0;
		return fact_[n];
	}
	constexpr T inv(int n) const noexcept {
		if (n < 0) return 0;
		return inv_[n];
	}
	constexpr T finv(int n) const noexcept {
		if (n < 0) return 0;
		return finv_[n];
	}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;
BiCoef<mint> bc;

int main() {
	int N, K; cin >> N >> K;
	bc.init(110000);

	for (int k = 1; k <= K; ++k)
		cout << bc.com(K - 1, k - 1) * bc.com(N - K + 1, k) << endl;
}


Measured memory_bytes: 2816