akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    if A[0] != 0:
        print(-1)
        exit()
    cnt = A[-1]

    for i in range(N-2,-1,-1):
        if A[i] >= A[i+1]:
            cnt += A[i]
        elif A[i] == A[i+1] - 1:
            continue
        else:
            print(-1)
            exit()

    print(cnt)

if __name__ == "__main__":
    main()

Measured memory_bytes: 88076
N = int(input())
p = 10**9 + 7

def po(a,n):
    r = 1
    while n != 0:
        if n % 2 == 1:
            r = (r*a)%p
        a = (a*a)%p
        n = n//2
    return r

print((po(10,N)-2*po(9,N)+po(8,N))%p)

Measured memory_bytes: 61560
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,m,dp[100010];
bool vis[100010];
vector<int> adj[100010],topo;
void f(int u) {
	if(vis[u]) return;
	vis[u]=1;
	for(auto& it:adj[u])f(it);
	topo.push_back(u);
}
int main() {
	scanf("%d%d",&n,&m);
	int i;
	for(i=0;i<m;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		adj[x].push_back(y);
	}
	for(i=1;i<=n;i++) f(i);
	int res=0;
	for(i=0;i<sz(topo);i++) {
		dp[topo[i]]=0;
		for(auto& it:adj[topo[i]]) {
			dp[topo[i]]=max(dp[topo[i]],dp[it]+1);
		}
		res=max(res,dp[topo[i]]);
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 8824
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
  int N, INF = 1e9;
  cin >> N;
  int m = INF, M = 0, bigger_m = INF, smaller_M = 0, x, y;
  priority_queue< pair<int,int> > smaller;
  vector<int> X(N), Y(N);
  for(int i = 0; i < N; ++i){
    cin >> x >> y;
    if(x > y) swap(x,y);
    m = min(m,x);
    M = max(M,y);
    bigger_m = min(bigger_m,y);
    smaller_M = max(smaller_M,x);
    smaller.emplace(-x, i);
    X[i] = x;
    Y[i] = y;
  }
  long long int ans = (long long int)(M - bigger_m)*(smaller_M - m);
  for(int i = 0; i < N; ++i){
    pair<int,int> p = smaller.top();
    int x = -p.first, k = p.second;
    smaller.pop();
    if(Y[k] < x) {
      printf("break: Y[k] = %d, x = %d\n", Y[k], x);
      break;
    }
    smaller.emplace(-Y[k],k);
    smaller_M = max(Y[k], smaller_M);
    bigger_m = -smaller.top().first;
    ans = min(ans,(long long int)(M-m)*(smaller_M-bigger_m));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define pb push_back
#define sf scanf
#define pf printf
using namespace std;
#define ll long long
const int N=1e6+9;
const ll mod=1e9+7;
const ll inf=2e10;
int prime[N],vis[N];
void seive()
{
    for(int i=1;i<N;i++) prime[i]=i;
    for(int i=2;i<N;i+=2) prime[i]=2;
    for(int i=3;i*i<N;i+=2) {
        if(prime[i] == i) {
            for(int j=i*i;j<N;j+=i) {
                if(prime[j] == j) prime[j]=i;
            }
        }
    }
}
vector<int> chk(int v)
{
    vector<int>ans;
    while (v != 1)
    {
        int p=prime[v];
        ans.push_back(p);
        while (v%p==0) v/=p;
    }
    return ans;
}
void slv()
{
    seive();
    int n;
    cin >> n;
    int a[n+3],gcd=0;
    for(int i=0;i<n;i++) {
        cin >> a[i];
        gcd=__gcd(gcd,a[i]);
    }
    bool okk=0;
    for(int i=0;i<n;i++) {
        vector<int>ans = chk(a[i]);
        bool ok=0;
        for(auto x : ans)
        {
            if(vis[x]==1) ok=1;
            vis[x]=1;
        }
        if(ok) okk=1;
    }
    if(!okk) puts("pairwise coprime");
    else {
        if(gcd == 1) puts("setwise coprime");
        else puts("not coprime");
    }
}
int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while (t--)
    {
        slv();
    }
    return 0;
}


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

int main(void){

    int N;
    cin >> N;
    double A[N];
    double sum;
    for (int i = 0; i < N; i++){
        cin >> A[i];
        A[i] = 1/A[i];
        sum += A[i];
    }
    cout <<  1/sum << endl;

    return 0;
}

Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]
# row
for i in range(3):
    ok = True
    for j in range(3):
        if A[i][j] not in b:
            ok = False
            break
    if ok:
        print('Yes')
        exit()
# column
for i in range(3):
    ok = True
    for j in range(3):
        if A[j][i] not in b:
            ok = False
            break
    if ok:
        print('Yes')
        exit()
# diagonal
ok = True
for i in range(3):
    if A[i][i] not in b:
        ok = False
        break
if ok:
    print('Yes')
    exit()
ok = True
for i in range(3):
    if A[i][2-i] not in b:
        ok = False
        break
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>

int main(void) {
  int N, D, cnt = 0;
  scanf("%d %d", &N, &D);
  int X[N][D];
  for (int n = 0; n < N; ++n) {
    for (int d = 0; d < D; ++d) {
      scanf("%d", &X[n][d]);
    }
  }
  for (int n1 = 0; n1 < N; ++n1) {
    for (int n2 = n1+1; n2 < N; ++n2) {
      int dist = 0;
      for (int d = 0; d < D; ++d) {
        dist += (X[n1][d] - X[n2][d]) * (X[n1][d] - X[n2][d]);
      }
      double rt = sqrt(dist);
      if (rt == (int)rt) ++cnt;
    }
  }
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int max = 0;
        int total = 0;
        int tmp = 0;
        for(int i = 0;i<n;i++){
            tmp = sc.nextInt();
            total += tmp;
            max = Math.max(tmp,max);
        }
        if(total - max > max){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  int res = 0;
  for(int i = 0; i < s.size() - 1; i++){
    if(s[i] != s[i + 1])res++;
  }
  cout << res << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

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

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n, x, y; cin >> n >> x >> y;
    x--; y--;

    vector<int> dist(n, 0);
    
    for (int src = 0; src < n - 1; src++) {
        for (int dst = src + 1; dst < n; dst++) {
            int d = min(dst - src, abs(x - src) + abs(dst - y) + 1);
            dist.at(d)++;
        }
    }

    for (int k = 1; k < n; k++) {
        cout << dist.at(k) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
// #define mp make_pair
//#define endl '\n'
 
int main() {
    int n;
    string yes = "YES";
    string no = "NO";
    cin >> n;
    vi p(n+1);
    rep1(i,n){
        cin >> p[i];
    }

    int count = 0;
    rep1(i,n){
        if(p[i] != i){
            count++;
        }
    }
    if(count > 2){
        cout << no << endl;
    }
    else{
        cout << yes << endl;
    }
    
    return 0;
}

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

int main() {
	
	string s; cin >> s;
	if (s.size() == 1) {
		cout << s[0] - '0' << endl;
		return 0;
	}

	ll n = s.size() - 1;
	ll ans = 0;
	for (int bit = 0; bit < (1 << n); ++bit) {
		ll tmpAns = 0;
		ll tmpS = (ll)(s[0] - '0');
		for (int i = 0; i < n; ++i) {
			if (bit & (1 << i)) {
				tmpAns += tmpS;
				tmpS= (ll)(s[i + 1] - '0');
			}
			else {
				tmpS *= 10;
				tmpS+= (ll)(s[i + 1] - '0');				
			}
			if (i == n - 1) tmpAns += tmpS;
		}
		ans += tmpAns;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll k,x;
	rl2(k,x);
	k*=500;
	if(k>=x)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define rg register
#define N 500010
using namespace std;
int n,m,now,last;
char s[N];
inline int read(){
    int k=0,f=1; char c=getchar();
    while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
    return k*f;
}
int main(){
	scanf("%s",s+1); n=strlen(s+1);
	if(s[n]=='1'||s[1]!='1'){
		puts("-1"); return 0;
	}
	for(rg int i=1;i<n;i++) if(s[i]!=s[n-i]){
		puts("-1"); return 0;
	}
	last=1;
	for(rg int i=2;i<n;i++){
		if(s[i]=='1'){
			printf("%d %d\n",last,i);
			for(rg int j=last+1;j<i;j++) printf("%d %d\n",j,i);
			last=i;
		}
	}
	printf("%d %d\n",last,n);
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a =sc.nextInt();
		int Max=a;
		int min=a;
		long sum=a;
		for(int i=0;i<n-1;i++){
		int b=sc.nextInt();
		sum += b;
		if(Max<b) Max=b;
		if(min>b) min=b;
		}
		System.out.println(min+" "+Max+" "+sum);
	}
}

Measured memory_bytes: 41808
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
int n,m,a[110][110],f[1<<15][20],s[1<<15];
int main()
{
	n=read();m=read();int sum=0;
	for(int i=1;i<=m;i++){
		int x=read()-1,y=read()-1,z=read();
		a[x][y]=a[y][x]=z;sum+=z;
	}
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<n;j++)f[i][j]=-1;
	for(int i=1;i<(1<<n);i++)
		for(int j=0;j<n;j++)if((1<<j)&i)
			for(int k=j+1;k<n;k++)if((1<<k)&i)s[i]+=a[j][k];
	f[1][0]=0;
	for(int i=1;i<(1<<n);i++)
		for(int j=0;j<n;j++)if(f[i][j]!=-1){
			for(int k=0;k<n;k++)if(((1<<k)&i)==0&&a[j][k]>0)f[i|(1<<k)][k]=max(f[i|(1<<k)][k],f[i][j]+a[j][k]);
			int x=(((1<<n)-1)^i)|(1<<j);
			for(int y=x;y>=0;y--)y&=x,f[i|y][j]=max(f[i|y][j],f[i][j]+s[y]);
		}
	int ans=1e9;
	for(int i=0;i<(1<<n);i++)ans=min(ans,sum-f[i][n-1]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main() {
  int i, flag = 0;
  char board[3][4];
  scanf("%s", board[0]);
  scanf("%s", board[1]);
  for(i = 0; i < 3; i++) {
    if(board[0][i] == board[1][2-i]) {
      flag++;
    }
  }
  if(flag == 3) {
    printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
#define chmax(a, b) a = max(a, b);
typedef long long ll;
typedef double lf;
typedef short int si;

static const int max_n = 43;
vector<vector<vector<ll>>> dp(max_n, vector<vector<ll>>(2, vector<ll>(2, -1)));



void Main(){
    ll N;
    sll(N);
    vector<ll> as(N, 0);
    ll X = 0;
    ll S;
    rep(i, N){
        cin >> as[i];
    }
    for(ll i=2;i<N;i++){
        X ^= as[i];
    }

    ll A = as[0];
    ll B = as[1];
    S = A + B;
    // cout << "S="<<S<<", A,B=" << A << "," << B <<endl;

    dp[0][0][0] = 0;
    ll v = 1;
    rep(i, max_n-1){
        ll cx = X & 1;
        ll cs = S & 1;
        ll ca = A & 1;
        rep(j, 2){
            rep(k, 2){
                if(dp[i][j][k]==-1){
                    continue;
                }
                rep(na, 2)rep(nb, 2){
                    ll ni = i + 1;
                    ll nk = 0, nj = j;
                    if((na^nb) != cx) continue;
                    ll ns = na + nb + k;
                    if(ns%2 != cs) continue;
                    if(ns>=2) nk = 1;
                    if(ca<na){
                        nj = 1;
                    }else if(ca == na){
                        nj = j;
                    }else{
                        nj = 0;
                    }

                    chmax(dp[ni][nj][nk], dp[i][j][k]|(v*na));

                }
            }
            int k = 0;
            // printf("dp[%lld][%lld][%lld]=%lld\n", i, j, k, dp[i][j][k]);

        }
        X >>= 1;
        S >>= 1;
        A >>= 1;
        v <<= 1;
    }

    ll i = max_n-1, j=0, k = 0;
    // printf("dp[%lld][%lld][%lld]=%lld\n", i, j, k, dp[i][j][k]);


    ll a = dp[max_n-1][0][0];
    if(a==0 || a==-1){
        cout << "-1" <<endl;
    }else{
        cout << as[0]-a << endl;
    }


}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

Measured memory_bytes: 3264
#include<vector>
#include<iostream>
#include<set>
#include<string>
using namespace std;
int n, a = 0, b = 0, c = 0, d = 0;
string x;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		if (x == "AC")
			a++;
		else if (x == "WA")
			b++;
		else if (x == "TLE")
			c++;
		else if (x == "RE")
			d++;

	}
	cout << "AC" << " " << "x " << a << endl;
	cout << "WA" << " " << "x " << b << endl;
	cout << "TLE" << " " << "x " << c<< endl;
	cout << "RE" << " " << "x " << d << endl;
	
}

Measured memory_bytes: 3604
def floor_sum(n, m, a, b):
    res = 0
    while True:
        if a >= m:
            res += a//m * n * (n-1) // 2
            a %= m
        if b >= m:
            res += b//m * n
            b %= m
        Y = (a*n+b) // m
        X = Y*m-b
        if Y == 0:
            return res
        res += (n-(X+a-1)//a) * Y
        n, m, a, b = Y, a, m, -X%a

import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))

Measured memory_bytes: 9268
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	long long int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2)cout << b - a << endl;
	else cout << a - b << endl;

	return 0;

}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

inline int ctoi(char c){
    return c - '0';
}

signed main(){
    string s; cin >> s;
    int sum = 0;
    
    bitset<10> b;
    rep(i,1<<(s.length()-1)){
        b = i;
        int waiting = ctoi(s[0]);
        rep(j,s.length()-1){
            if(b[j]){
                sum += waiting;
                waiting = 0;
            }
            waiting *= 10;
            waiting += ctoi(s[j+1]);
        }
        sum += waiting;
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = pow(10, 9) + 7
c1, c2 = 1, 1
n1, n2 = n, n - 1
ans = 1
for r in range(1, min(k + 1, n)):
    c1 = (c1 * n1 * pow(r, mod - 2, mod)) % mod
    c2 = (c2 * n2 * pow(r, mod - 2, mod)) % mod
    n1 -= 1
    n2 -= 1
    ans += (c1 * c2) % mod
    ans %= mod
print(ans)

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

int main(){
  string S;
  cin >> S;
  
  string before="ATGC";
  string after="TACG";
  
  char ans;
  
  for (int i=0;i<before.size();++i){
    if (S[0] == before[i]) ans=after[i];
  }
  cout << ans << endl;
}
//直大さんの別解その1
    


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

int main(int argc, char const *argv[]) {
  int a, b, max;
  cin >> a >> b;
  if (a+b >= a-b) {
    max= a+b;
    if (a+b >= a*b) {
      /**DONOTHING**/
    } else {
      max = a*b;
    }
  } else if (a-b >= a+b) {
    max = a-b;
    if (a-b >= a*b) {
      /**DONOTHING**/
    } else {
      max=a*b;
    }
  }

  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def solve(H: int):
    n = 1
    attack = 0
    while H > 1:
        attack += n
        H = H // 2
        n *= 2
    attack += n
    return attack


def main():
    H = int(input())
    answer = solve(H)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9132
#include <iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int cnt;
string s,t;
cin>>s>>t;
int n= s.length();
int k= t.length();

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

     if(s[i]!=t[i])
        cnt++;

    }

cout<<cnt;
}



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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int k;cin>>k;
    string s;cin>>s;
    int n=SIZE(s);
    //dump(n)

    if(n<=k){
        cout<<s<<endl;
        return;
    }
    REP(i,k){
        cout<<s[i];
    }
    cout<<"..."<<endl;

	return;
}

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

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int arr[110];

int main(void) {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &arr[i]);
	}

	int min = 2000000000;
	for (int i = 1; i <= 100; i++) { // target
		int sum = 0;
		for (int j = 1;j <= n;j ++) { // source
			sum += ((i - arr[j]) * (i - arr[j]));
		}
		if (min > sum)
			min = sum;
	}

	printf("%d", min);

	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(20000)


def getMax(d, n):
    if len(d[n]) == 0:
        return 0
    if not dp[n] == -1:
      
        return dp[n]
    for k in d[n]:
        dp[n] = max(dp[n], 1 + getMax(d, k))
    return dp[n]


n, m = map(int, input().split())
d = {}
dp = [-1 for _ in range(n + 1)]
for j in range(1, n + 1):
    d[j] = []
for i in range(m):
    a, b = map(int, input().split())
    d[a].append(b)
bs = -1
for i in range(1, n + 1):
    bs = max(bs, getMax(d,i))
print(bs)


Measured memory_bytes: 158680
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))


(defun main (n play)
  (dp func (day last) '(100010 4)
    (if (eq day n) 0
        (apply #'max
               (loop for i from 0 to 2
                     when (not (eq i last))
                       collect(+ (aref play day i) (func (1+ day) i))))))
  (func 0 3))

(let* ((n (read))
       (play (make-array (list n 3) :initial-contents
                         (loop repeat n collect (loop repeat 3 collect (read))))))
  (princ (main n play)))



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

int main() {
    int K; cin >> K;
    int sum = 0;
    for(int a=1; a<=K; a++) {
        for(int b=1; b<=K; b++) {
            for(int c=1; c<=K; c++) {
                sum += gcd(gcd(a,b),c);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3652
from itertools import chain, product

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

a_abs_max = 0
for i in range(N):
    if a_abs_max < abs(a[i]):
        a_abs_max = abs(a[i])
        a_abs_max_index = i

result = []
if a_abs_max > 0:
    if a[a_abs_max_index] > 0:
        result = list(chain(iter([(a_abs_max_index + 1, a_abs_max_index + 1)]), product([a_abs_max_index + 1], range(1, N + 1)), map(lambda i: (i + 1, i + 2), range(N - 1)))) # 1-based indexing
    elif a[a_abs_max_index] < 0:
        result = list(chain(iter([(a_abs_max_index + 1, a_abs_max_index + 1)]), product([a_abs_max_index + 1], range(1, N + 1)), map(lambda i: (i + 1, i), range(N - 1, 0, -1)))) # 1-based indexing

print(len(result))
for x, y in result:
    print(x, y)

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

int main(){
  int n;
  cin >> n;
  vector<int> hoge(n);
  for (int i = 0; i < n; i++){
    cin >> hoge.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < n - 1; i++){
    for (int a = i + 1; a < n; a++){
      sum += (hoge[i]*hoge[a]);
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long c = sc.nextLong();
        long[] x = new long[n];
        int[] v = new int[n];
        long[] re = new long[n];
        long[] le = new long[n];
        long[] maxr = new long[n];
        long[] maxl = new long[n];
        for(int i=0; i<n; i++){
            x[i] = sc.nextLong();
            v[i] = sc.nextInt();
        }
        re[0] = v[0] - x[0];
        le[0] = v[n-1] - (c - x[n-1]);

        long max = Math.max(0, Math.max(re[0], le[0]));
        maxr[0] = Math.max(0, re[0]);
        maxl[0] = Math.max(0, le[0]);

        for(int i=1; i<n; i++){
            re[i] = re[i-1] + v[i] - (x[i] - x[i-1]);
            le[i] = le[i-1] + v[n-1-i] - (x[n-i] - x[n-1-i]);
            if(re[i] > max) max = re[i];
            if(le[i] > max) max = le[i];
            maxr[i] = Math.max(re[i], maxr[i-1]);
            maxl[i] = Math.max(le[i], maxl[i-1]);
        }

        for(int i=0; i<n-1; i++){
            long tmp = re[i] + maxl[n-2-i] - x[i];
            if(tmp > max) max = tmp;
            tmp = le[i] + maxr[n-2-i] - (c-x[n-1-i]);
            if(tmp > max) max = tmp;
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 96744
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main()
{
	string s;
	cin >> s;

	stack<char> c;
	int t = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'S') {
			c.push('S');
		} else {
			if (!c.empty()) {
				c.pop();
				t += 2;
			}
		}
	}
	cout << s.length() - t << endl;

	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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;
};

static const int MAX_VALUE = 100000;
static const int MAX_W = 10000;
static const int MAX_N = 100;
static const int INF = 1e9;

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> value(N+1);
    vector<int> weight(N+1);
    rep(i, 1, N+1) {
        cin >> value[i] >> weight[i];
    }
    vector<vector<int>> dp(N+1, vector<int> (W+1, 0));

    rep(i, 1, N+1) {
        int v = value[i];
        int w = weight[i];
        rep(j, 1, W+1) {
            if (j >= w) {
                dp[i][j] = max(dp[i - 1][j], dp[i-1][j-w]+v);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[N][W] << endl;
};



Measured memory_bytes: 6832
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll a,b,x;
            cin>>a>>b>>x;
            ld ans;
            ld h;
            h=(ld)1.0*x/((ld)1.0*a*a);
            //cout<<h<<" "<<b<<endl;
            if(h*2.0>=b)
            {
                ans=atan((ld)1.0*(a/2.0)/(b-h));
                ld pi=3.14159265359;
                //cout<<ans<<endl;
                ans=(ld)1.0*ans*180.0/pi;
                ans=90.0-ans;
                printf("%.9Lf\n",ans);
            }
            else
            {
                h=1.0*x/a;
                //cout<<h<<endl;
                //cout<<h<<" "<<b-h<<" "<<1.0*(b-h)/b<<endl;
                ans=atan((ld)1.0*(2*x)/(a*b*b));
                ld pi=3.14159265359;
                //cout<<ans<<endl;
                ans=(ld)1.0*ans*180.0/pi;
                ans=90.0-ans;
                printf("%.9Lf\n",ans);
            }
        }
        return 0;
    }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCoder.Probrems.Solvers.ABC127
{
    public class C
    {
        static void Main(string[] args)
        {
            var nm = ReadLine().Split().Select(int.Parse).ToArray();
            var gates = new int[nm[1]][];
            for (int i = 0; i < nm[1]; i++)
            {
                gates[i] = ReadLine().Split().Select(int.Parse).ToArray();
            }
            WriteLine(Solve(nm[0], nm[1], gates));
        }

        public static long Solve(int n, int m, int[][] gates)
        {
            int h = 0;
            int t = int.MaxValue;
            foreach (var gate in gates)
            {
                h = Math.Max(gate[0], h);
                t = Math.Min(gate[1], t);
                if (h > t)
                    return 0;
            }

            return t - h + 1;
        }

        private const int MOD = 1000000007;
    }
}


Measured memory_bytes: 23868
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int N;
    cin >> N;
    cout << (N + 110) / 111 * 111 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int>dp(1<<n, 1<<30);
    vector<int>a(m);
    vector<vector<int>>c(m);
    rep(i,m){
        int b;
        cin >> a[i] >> b;
        c[i].resize(b);
        rep(j,b){
            cin >> c[i][j];
        }
    }
    dp[0] = 0;
    rep(i,1<<n){
        if(dp[i] != 1<<30){
            rep(j,m){
                int t = i;
                
                rep(k,c[j].size()){
                    t |= 1<<(c[j][k]-1);
                }
                dp[t] = min(dp[t], dp[i] + a[j]);
            }
            
        }
    }
    if(dp.back() != 1<<30)cout << dp.back() << endl;
    else cout << - 1<< endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")
 
typedef pair <int, int> ii;
typedef pair <int, ii> iii;
 
const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";
 
int a[siz], b[siz];
 
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);
 
    int n, m, k;
    cin >> n >> m >> k;
 
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
 
        a[i] += a[i - 1];
    }
 
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
 
        b[i] += b[i - 1];
    }
 
    int ans = 0;
    for (int i = 0, j = m; i <= n; i++) {
        if (k - a[i] < 0) {
            break;
        }
 
        while (a[i] + b[j] > k) {
            j--;
        }
 
        ans = max(ans, i + j);
    }
 
    cout << ans << "\n";
 
//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
 
    return 0;
}

Measured memory_bytes: 6744
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 998244353
ll n,m,arr[sz],brr[sz],k,l,crr[sz],t,i,j,hi,lo,mi,q;
vector<ll>v;
char c[sz];
int main()
{
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
     scanf("%lld",&arr[i]);
     j^=arr[i];
 }
 for(i=1;i<=n;i++)
    printf("%d ",j^arr[i]);
}


Measured memory_bytes: 5252
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Lot
    {
        static void Main(string[] args)
        {
            int w = int.Parse(System.Console.ReadLine());
            int n = int.Parse(System.Console.ReadLine());
            var param = new List<int[]>();
            List<int> result = new List<int>();
            for (int pre = 1; pre <= w;pre++ )
            {
                result.Add(pre);
            }
            for (int i = 0; i < n; i++)
            {
                param.Add(Array.ConvertAll(System.Console.ReadLine().Split(','), new Converter<string, int>(s => int.Parse(s))));
            }
            for(int j=1;j<=w;j++)
            {
                int oldW = j;
                foreach(var elems in param)
                {
                    if(elems.Contains(j))
                    {
                        j = elems.Single(e=> e != j);
                    }
                }
                result[j-1]=oldW;
                j = oldW;
            }
            foreach (int x in result)
            {
                System.Console.WriteLine(x);
            }
        }
    }
}

Measured memory_bytes: 5988
#include <bits/stdc++.h>
#define ll long long int
#define f(i,a,n) for(i=a;i<n;i++)
#define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define test() ll tc;cin>>tc;while(tc--)

using namespace std;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

int main()
{
        fast();
        ll n,k,i,j;
        cin>>n>>k;
        ll a[n];
        vector<bool> dp(k+1);
        f(i,0,n)
        {
            cin>>a[i];
        }

        for(ll stones=0;stones<=k;++stones)
        {
            for(ll x:a)
            {
                if(stones>=x && !dp[stones-x])
                {
                    dp[stones]=true;
                }
            }
        }

        puts(dp[k] ? "First" : "Second");
        return 0;
}


Measured memory_bytes: 256
//#define ONLINE_JUDGE
#define rush()        \
    int MYTESTNUM;    \
    cin >> MYTESTNUM; \
    while (MYTESTNUM--)
#define FOR(i, s, t) for (int i = (s); i <= (t); ++i)
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1 << 30;
const double eps = 1e-8;
const int maxn = 1e5 + 10;
ll n, a, b;
ll l = 1, r;
vector<ll> h;
bool judge(ll x)
{
    //(x-ti)*B+ti*A = x*B+(A-B)ti
    ll sum = 0; //最少攻击次数
    ll temp = x * b;
    for (int i = 1; i <= n; i++) {
        if (h[i] > temp) {
            sum += (h[i] - temp) / (a - b) + ((h[i] - temp) % (a - b) == 0 ? 0 : 1);
        }
    }
    if (sum <= x) {
        return true;
    }
    return false;
}
int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> n >> a >> b;
    h.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
        r += h[i] / b + 1; //最多攻击次数
    }
    sort(h.begin() + 1, h.end());
    while (l < r) {
        ll mid = (l + r) >> 1;
        if (judge(mid)) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int size[300];
int size_depth[300];
int d[300];
int p[300];
vector<int> child[300];
int N, M, K;
int root = -1;


int main(){
    int N; cin >> N;
    ll a[201000], b[201000];
    ll res = 0;

    bool sam = true;
    ll mi = LONG_LONG_MAX;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
        if(a[i] != b[i]){
            sam = false;
        }
        if(a[i] > b[i]){
            mi = min(mi, b[i]);
        }
        res += b[i];
    }

    if(sam){
        cout << 0 << endl;
    }
    else{
        cout << res - mi << endl;
    }


    return 0;
}


Measured memory_bytes: 2432
class UFtree:
    def __init__(self,length):
        self.N=length
        self.tree=[-1 for i in range(length)]
        self.rank=[0 for i in range(length)]
    def find(self,X):
        if self.tree[X]<0:
            return X
        XX=self.find(self.tree[X])
        self.tree[X]=XX
        return XX

    def unite(self,X,Y):
        X=self.find(X)
        Y=self.find(Y)

        if Y==X:
            return

        if self.rank[X]>self.rank[Y]:
            self.tree[X]+=self.tree[Y]
            self.tree[Y]=X
        else:
            if self.rank[Y]==self.rank[X]:
                self.rank[Y]+=1
            self.tree[Y]+=self.tree[X]
            self.tree[X]=Y



def resolve():
    N,M = map(int,input().split())
    ut = UFtree(N)
    for i in range(M):
        A,B = map(int,input().split())
        ut.unite(A-1,B-1)

    print(-1*min(ut.tree))
resolve()


Measured memory_bytes: 93984
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
//const int maxn=;
typedef long long ll;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll sum=a+b+c;
	if (sum>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	LL vmax = 100000;
	LL n,W;
	cin >> n >> W;
	VL w(n+1), v(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	VVL dp(n+1,VL(vmax+1,MOD));
	for (int i = 0; i <= n; i++) {
		dp[i][0] = 0;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= vmax; j++) {
			if (j - v[i] < 0) {
				dp[i][j] = dp[i-1][j];
				continue;
			}
			dp[i][j] = min(dp[i-1][j - v[i]] + w[i], dp[i-1][j]);
		}
	}
	LL ans = 0;
	for (LL i = 1; i <= vmax; i++) {
		if (dp[n][i] <= W) {
			ans = max(ans,i);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    set<int> snack;
    rep(i, 0, k){
        int di, ai;
        cin >> di;
        rep(j, 0, di){
            cin >> ai;
            snack.insert(ai);
        }
    }
    cout << n - snack.size() << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stdio.h>
#include <string.h>

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

using namespace std;

int main(){
    ll H, W;
    cin >> H >> W;
    ll output = H * W / 2 + H * W % 2;
    if(H == 1){
        output = 1;
    }
    if(W == 1){
        output = 1;
    }

    cout << output << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int n,m;
    int s1[101];
    int s2[101];
    int s1_sum=0;
    int s2_sum=0;
    pair<int,int> p;
    while(1){
        p=make_pair(101,101);
        s1_sum=0;
        s2_sum=0;
        for(int i=0;i<101;i++){
            s1[i]=0;
            s2[i]=0;
        }
        cin >> n >>m;
        if(n==0||m==0){
            break;
        }
        for(int i=0;i<n;i++){
            cin >> s1[i];
            s1_sum+=s1[i];
        }
        for(int i=0;i<m;i++){
            cin >> s2[i];
            s2_sum+=s2[i];
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if((s1_sum-s1[i]+s2[j])==(s2_sum+s1[i]-s2[j])){
                    if((p.first+p.second)>s1[i]+s2[j]){
                        p=make_pair(s1[i],s2[j]);
                    }
                }
            }
        }
        if(p.first!=101&&p.second!=101){
            cout << p.first << " " << p.second << endl;
        }
        else{
            cout << -1 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3004
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
	vi v(3);
	REP(i, 3) cin >> v[i];
	sort(ALL(v));
	cout << v[0] + v[1] << endl;
}

Measured memory_bytes: 256
#include<iostream>

int main()
    {    
         int m, f, r;
         std::cin >> m >> f >> r;
         while(m != -1 ||  f != -1 || r != -1){
             if (m == -1 || f == -1){
                 std::cout << "F" << std::endl;
             } else if ((m + f) >= 80){
                 std::cout << "A" << std::endl;
             } else if ((m + f) >= 65){
                 std::cout << "B" << std::endl;
             } else if ((m + f) >= 50 || r >= 50){
                 std::cout << "C" << std::endl;
             } else if ((m + f) >= 30) {
                 std::cout << "D" << std::endl;
             } else {
                 std::cout << "F" << std::endl;
             }
             std::cin >> m >> f >> r;
         }
    return 0;
    }

Measured memory_bytes: 3068