akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<math.h>
using namespace std;

int main(void)
{
	int N, *A , *B;
	int MAX, MAX2;
	cin >> N;

	A = new int[N];
	B = new int[N];
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		B[i] = A[i];
	}
	stable_sort(A, A + N);
	MAX = A[N - 1];
	MAX2 = A[N - 2];

	for (int i = 0; i < N; i++)
	{
		if (B[i] == MAX)
			cout << MAX2 << endl;
		else
			cout << MAX << endl;
	}
	delete A,B;

	return 0;
}

Measured memory_bytes: 3192
import scala.io.StdIn.readLine

object Main extends App {

  for (_ <- 0 to 20000) {
    val line = readLine().split(" ")
    val (a, b) = (line(0).toInt, line(2).toInt)
    val op = line(1)
    var ans = 0

    op match {
      case "+" => ans = a + b
      case "-" => ans = a - b
      case "*" => ans = a * b
      case "/" => ans = a / b
      case "?" => sys.exit()
    }

    println(ans)
  }

}



Measured memory_bytes: 43880
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < max(n, m); i++) cout << min(n, m);
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);
typedef pair<int,int> pii;
///------------------------------------------------------------------------
const int inf=1e18;
const int mod=1e9+7;
ifstream in("input.txt");
ofstream out("output.txt");
struct item
{
    int c,w;
    item(){c=0;w=0;}
};
vector<vector<int> > dp;
signed main()
{
    int n;
    cin>>n;
    int w;
    cin>>w;
    vector<item> vec(n);
    for(int i=0;i<n;i++)
        cin>>vec[i].w>>vec[i].c;
    dp.resize(n+1,vector<int>(w+1,-inf));
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j-vec[i-1].w>=0)
                dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i-1][j-vec[i-1].w]+vec[i-1].c));
//            cerr<<"dp["<<i<<"]["<<j<<"]= ";
//            if(dp[i][j]==-inf)
//                cerr<<"inf";
//            else
//                cerr<<dp[i][j];
//            cerr<<"\n";
        }
    }
    int maxi=0;
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
            maxi=max(maxi,dp[i][j]);
    }
    cout<<maxi;
    return 0;
}
























Measured memory_bytes: 80256
n=int(input())
ans=0
#完全非連結の場合
for i in range(1,n+1):
    ans+=i*(n-i+1)
#解説参照
#木
#辺が使われるたびに連結成分数が1減る
for i in range(n-1):
    v,w=map(int,input().split())
    if v>w:
        v,w=w,v
    ans-= v*(n-w+1)
print(ans)

Measured memory_bytes: 74376
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#define INF 1<<28
#define F first
#define S second
using namespace std;
 

typedef pair < int, int > P;
vector < P > p[5];
int sx, sy, gx, gy;
int memo[5][5][1111];

int solve(int k, int t, int q){
  
  if(k == 4) return abs(p[t][q].F-gx) + abs(p[t][q].S-gy);
  if(~memo[k][t][q]) return memo[k][t][q];
  
  int ans = INF, d = (t+1)%5, c;
  for(int i=0;i<p[d].size();i++){
    c = k?abs(p[t][q].F-p[d][i].F) + abs(p[t][q].S-p[d][i].S):abs(sx-p[d][i].F) + abs(sy-p[d][i].S);
    ans = min(ans, solve(k+1, d, i) + c);
  }
 
  return memo[k][t][q] = ans;
}
 
int main(){
 
  int w, h;
  char c;
 
  while(cin >> w >> h, w){
 
    for(int i=0;i<5;i++) p[i].clear();
     
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> c;
	if(c == '.') continue;
	else if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else  p[c-'1'].push_back( P(j,i) );
      }
    }
    
    P q = P(0, INF);
    for(int i=0;i<5;i++){
      memset(memo, -1, sizeof(memo));
      if(q.S > solve(0,i,0)) q.F = i+1, q.S = solve(0,i,0);
    }
    
    if(q.S == INF) cout << "NA\n";
    else cout << q.F << " " << q.S << endl;
    
  }
}

Measured memory_bytes: 1360
import javax.swing.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.*;

public class Main {
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }


    }

    public static void main(String[] args) {
        FastReader s = new FastReader();
        Main obj = new Main();
        int h=s.nextInt();
        int n=s.nextInt();
        int arr[][] = new int[n][2];
        for(int i=0;i<n;i++)
        {
            arr[i][0]=s.nextInt();
            arr[i][1]=s.nextInt();
        }
        long[] dp=new long[h+1];
        Arrays.fill(dp,Long.MAX_VALUE);
        for(int i=0;i<n;i++)
        {
            if(h-arr[i][0]>0)
            {
                dp[h-arr[i][0]] = Math.min(dp[h-arr[i][0]],arr[i][1]);
            }
            else
            {
                dp[0] =Math.min(dp[0],arr[i][1]);
            }
        }

        for(int i=h;i>0;i--)
        {
            if(dp[i]!=Long.MAX_VALUE)
            {
                for(int j=0;j<n;j++)
                {
                    if(i-arr[j][0]>0)
                    dp[i-arr[j][0]] = Math.min(dp[i-arr[j][0]],dp[i]+arr[j][1]);
                    else
                    {
                        dp[0]=Math.min(dp[0],dp[i]+arr[j][1]);
                    }
                }

            }

        }
        System.out.println(dp[0]);



    }


}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  if (n*a > b) {
    cout << b << endl;
  }
  else if (n*a < b) {
    cout << n*a << endl;
  }
  else {
    cout << b << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#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 MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	double d;
	cin >> d;
	cout << fixed << setprecision(10) << max(sqrt(2)*d, (double)((int)(d)+1)) << endl;

	return 0;
}

Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  string mon="RYGB";
  cin>>a>>b>>c;
  for(int i=0;i<a;++i){
    for(int j=0;j<b;++j){
      int m=((i+j)%(c*2)+(c*2))%(c*2)/c,n=((i-j)%(c*2)+(c*2))%(c*2)/c;
      cout<<mon[m*2+n];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 512
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int h, w, m;
    cin >> h >> w >> m;
    vpi t(m);
    for (auto &x : t)
        cin >> x.fi >> x.se;
    unordered_map<int, vi> data;
    unordered_map<int, int> col_cnt;
    set<pii> max_col_cnt;

    for (auto x : t) {
        data[x.fi].push_back(x.se);
        col_cnt[x.se]++;
    }
    for (auto x : col_cnt) {
        max_col_cnt.insert({x.se, x.fi});
    }
    int ans = 0;
    for (auto x : data) {
        int rc = sz(x.se);
        for (auto y : x.se) {
            max_col_cnt.erase({col_cnt[y], y});
            col_cnt[y]--;
            max_col_cnt.insert({col_cnt[y], y});
        }
        int maxc = 0;
        if (!max_col_cnt.empty()) {
            maxc = max_col_cnt.rbegin()->fi;
        }
        ans = max(ans, rc + maxc);
        for (auto y : x.se) {
            max_col_cnt.erase({col_cnt[y], y});
            col_cnt[y]++;
            max_col_cnt.insert({col_cnt[y], y});
        }
    }
    cout << ans << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 60612
// C - Chocolate Bar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);++i)

ll check(int Y, int X){
	ll s1,s2,s3;
	ll minDiff = LLONG_MAX;
	ll e = (Y+2-1)/2;
	for(ll x1=X, y1=1; y1<=e; ++y1){//-: vertical division
		ll y2,y3,x2,x3;
		// T: horizontal division
		y2 = Y-y1;
		x2 = X/2;
		x3 = X-x2;

		s1 = y1 * x1;
		s2 = y2 * x2;
		s3 = y2 * x3;
		ll diff = max({s1, s2, s3}) - min({s1, s2, s3});
		minDiff = min(minDiff, diff);

		//-: vertical division
		y2 = y2/2;
		y3 = Y - y1 - y2;

		s1 = y1 * x1;
		s2 = y2 * x1;
		s3 = y3 * x1;
		diff = max({s1, s2, s3}) - min({s1, s2, s3});
		minDiff = min(minDiff, diff);

	}
	return minDiff;
}

int main(){
	int H,W; cin>>H>>W;
	ll ans = min(check(H, W), check(W, H));
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import math
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i < k:
        ans += 1/2**math.ceil(math.log(k/i,2))
        #print(2**math.ceil(math.log(k/i,2)))
    else:
        ans += 1
print(ans/n)

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, a, b, c, d, e, k);
  OUTL((e - a <= k) ? "Yay!" : ":(");
  return 0;
}


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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    vi X;
    for (int i = 0; i < 31; i++) {
        for (int j = 0; j < 31; j++) {
            int w = 100 * A * i + 100 * B * j;
            if (w > F) continue;
            X.push_back(w);
        }
    }

    vi Y;
    for (int i = 0; i < 101; i++) {
        for (int j = 0; j < 101; j++) {
            int s = C * i + D * j;
            if (s > F) continue;
            Y.push_back(s);
        }
    }

    int ares = 0;
    int bres = 0;
    double maxcon = -1;
    double econ = (double) E / ((double) 100 + (double) E);
    for (int i = 0; i < X.size(); i++) {
        for (int j = 0; j < Y.size(); j++) {
            int a = X[i];
            int b = Y[j];
            if (a + b > F) continue;

            double ncon = (double) b / ((double) a + (double) b);

            if (ncon <= econ) {
                if (maxcon < ncon) {
                    maxcon = ncon;
                    ares = a;
                    bres = b;
                }
            }
        }
    }
    cout << (ares + bres) << " " << bres << endl;
}

Measured memory_bytes: 3744
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    double ans = 0;
    double y = 380000.0;
    rep(i, n) {
        double x;
        string s;
        cin >> x >> s;
        if(s == "JPY") {
            ans += x;
        }
        else {
            ans +=x*y;
        }
    }

    exout(ans);
    re0;
}

Measured memory_bytes: 256
use proconio::input;

fn is_ok(mut n: usize) -> bool {
  let mut m = 0;
  while n != 0 {
    n /= 10;
    m += 1;
  }
  if m % 2 == 0 { false } else { true }
}

fn main() {
    input! {
        n: usize,
    }

    let mut count = 0;
    for i in 1..=n {
      if is_ok(i) {
        count += 1;
      }
    }

    println!("{}", count);
}


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

int main(){
  int n;
  rep(i, 5){
    cin >> n;
    if(n == 0)
      cout << i + 1 << endl;
  }
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    lli n;
    vector<lli> vect(100010);
    cin >> n;

    for(lli i=1; i<=n; i++){
        cin >> vect.at(i);
    }

    lli pos = 1;
    for(lli i=0; i<=n; i++){
        if(vect.at(pos)==2){
            cout << i+1 << endl;
            break;
        }
        if(i==n){
            cout << -1 << endl;
            break;
        }
        pos = vect.at(pos);
    }
    return 0;
}

Measured memory_bytes: 1024
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    count = 1
    for i in range(N-1):
        if A[i] == A[i+1]:
            count += 1
        else:
            if count > 1:
                ans += count//2
            count = 1
    if count > 1:
        ans += count//2
    print(ans)
resolve()

Measured memory_bytes: 8964
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
vector<vector<ll> > ans(100010,vector<ll>(0));

int main(){
    ll n;
    cin>>n;
    ll num=1;
    ll m=1;
    while(m<=n){
        for(ll i=0;i<num;i++){
            ans[i].push_back(m);
            ans[num].push_back(m);
            m++;
        }
        num++;
        if(m>n+1){
            cout<<"No" <<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    cout<<num<<endl;
    for(ll i=0;i<num;i++){
        cout<<ans[i].size()<<" ";
        for(ll u:ans[i]){
            cout<<u<<" ";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

ll x;
cin>>x;
for(int i=0;i<=120;i++)
{
    for(int j=-64;j<=i;j++)
    {
        if(po(i,5)-po(j,5)==x)
        {
            cout<<i<<" "<<j<<endl;
            return 0;
        }
    }
}

return 0;
}



Measured memory_bytes: 3612
#include <cstdio>
bool search(int A[],int n,int key){
  int left = 0;
  int right = n;
  int mid;
  while(left < right){
    mid = (right + left)/2;
    if(A[mid] == key)return true;
    else if(A[mid] < key){
      left = mid + 1;
    }
    else right = mid;
  }
  return false;
}
int main (){
  int n,S[100000],q;
  int i;
  scanf("%d",&n);
  for(i = 0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  int sum = 0;
  int key;
  for(i = 0;i < q;i++){
    scanf("%d",&key);
    if(search(S,n,key))sum++;
  }
  printf("%d\n",sum);
}



Measured memory_bytes: 2956
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, h, w;
    cin >> n >> h >> w;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush
import sys


class SSSP:
    """Given weighted graph, find Single Sorce Shortest Path from node 0.

    >>> st = SSSP([[(2, 3), (3, 1), (1, 2)], \
                   [(0, 2), (3, 4)], \
                   [(0, 3), (3, 1), (4, 1)], \
                   [(2, 1), (0, 1), (1, 4), (4, 3)], \
                   [(2, 1), (3, 3)]])
    >>> [st.weight(n) for n in range(5)]
    [0, 2, 2, 1, 3]
    """
    def __init__(self, graph):
        self.size = len(graph)
        self.tree = []
        self.weights = [-1] * self.size
        self._search(graph)

    def weight(self, n):
        return self.weights[n]

    def _search(self, graph):
        h = []
        self.weights[0] = 0
        count = 1
        for i, w in graph[0]:
            heappush(h, (w, 0, i))

        while count < self.size:
            while len(h) > 0:
                weight, src, dst = heappop(h)
                if self.weights[dst] < 0:
                    self.weights[dst] = weight
                    count += 1
                    self.tree.append((src, dst))
                    for i, w in graph[dst]:
                        if self.weights[i] < 0:
                            heappush(h, (w+weight, dst, i))
                    break


def run():
    n = int(input())

    nodes = [None] * n
    for line in sys.stdin:
        id_, deg, *edges = [int(i) for i in line.split()]
        nodes[id_] = []
        for _ in range(deg):
            tgt, wgt, *edges = edges
            nodes[id_].append((tgt, wgt))

    st = SSSP(nodes)
    for node in range(n):
        print('{} {}'.format(node, st.weight(node)))


if __name__ == '__main__':
    run()



Measured memory_bytes: 94528
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N, T;
    cin >> N >> T;
    if(N == 1) {
        cout << T << endl;
        return 0;
    }
    else {
        int t[N], u[N-1];
        rep(i, N) {
            cin >> t[i];
        }
        rep(i, N-1) {
            u[i] = t[i+1] - t[i];
        }

        ll ans = 0;
        rep(i, N-1) {
            if(T <= u[i]) {
                ans += T;
            }
            else {
                ans += u[i];
            }
        }
        ans += T;

        cout << ans;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
 
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    String s[] = new String[n];
    for(int i = 0; i < n; i++){
    	s[i] = sc.next();
    }
    Arrays.sort(s);
    for(int i=0;i<n;i++){
    	System.out.print(s[i]);
    }     
  }
}

Measured memory_bytes: 24148
#include<stdio.h>
#include<limits.h>

#define MAX 101

void MatrixChain();

int n,p[MAX],M[MAX][MAX];

int main(){

  int i;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  MatrixChain();
  
  printf("%d\n",M[1][n]);

  return 0;
}

void MatrixChain(){
  int i,j,k,l,q;

  for(i=1;i<n;i++) M[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j] = INT_MAX;
      for(k=i;k<j;k++){
	q=M[i][k]+M[k+1][j]+p[i-1]*p[k]*p[j];
	if(q<M[i][j]) M[i][j]=q;
      }
    }
  }
}

Measured memory_bytes: 636
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back 
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int> 
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second 
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0); 
const int32_t mod = 1e9+7;
const int32_t maxn=2e5+5;

void solve(){
    int n;cin>>n;
    int a[n][3],d[n][3];
    rep(i,0,n) rep(j,0,3) cin>>a[i][j];
    rep(i,0,3) d[0][i]=a[0][i];

    rep(i,1,n){
        d[i][0]=max(d[i-1][1],d[i-1][2])+a[i][0];
        d[i][1]=max(d[i-1][0],d[i-1][2])+a[i][1];
        d[i][2]=max(d[i-1][0],d[i-1][1])+a[i][2];
    }    
    cout<<max({d[n-1][0],d[n-1][1],d[n-1][2]});
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;                                                                                                                  
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

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

int INF=0x3f3f3f3f;


int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	if(n/10==9||n%10==9) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long int
#define debug cout<<"debug";
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 998244353
#define ll_MAX 19223372036859
#define endl "\n"
inline ll absdiff(ll a,ll b){ return (a>b)?a-b:b-a;}
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main(){
    ll n,k;cin>>n>>k;
    ll arr[n];
    for(auto& i:arr) cin>>i;

    ll dp[n];
    fill_n(dp,n,ll_MAX);
    dp[0]=0;

    for(ll i=1;i<min(n,k);++i){
        dp[i]=absdiff(arr[i],arr[0]);
    }

    for(ll i=k;i<n;++i){
        for(ll j=1;j<=k;++j) dp[i]=min(dp[i],dp[i-j]+absdiff(arr[i],arr[i-j]));
    }

    cout<<dp[n-1];
    return 0;   
}

Measured memory_bytes: 1792
package main
import "fmt"

func main() {
  var n int
  fmt.Scanf("%d", &n)

  sum := 0
  ti := make([]int, n)
  for i := range ti {
    fmt.Scanf("%d", &ti[i])
    sum += ti[i]
  }

  var m int
  fmt.Scanf("%d", &m)

  for i := 0; i < m; i++ {
    var p, x int
    fmt.Scanf("%d %d", &p, &x)
    fmt.Println(sum - ti[p-1] + x)
  }
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

template<typename T>
long long pow(T n, T x, T MOD=(T)(1e9)+7){
    long long res = 1LL;
    while(x){
        if(x%2==1) res = (res*n) % MOD;
        x = x>>1;
        n= (n*n) % MOD;
    }
    return res%MOD;
}

template<typename T>
long long factorial(T n, T MOD=(T)(1e9)+7) {
    if(n<=1) return 1LL;
    long long res = 1LL;
    while(n>1){
        res = (res*n)%MOD;
        n--;
    }
    return res;
}

template<typename T>
long long cmb(T n, T r, T MOD=(T)(1e9)+7){
    long long res = 1LL;
    if(r<0 or r>n) return res;
    r = (r<n-r? r: n-r);
    for(ll i=n-r+1; i<=n; i++) res = (res*i)%MOD;
    res *= pow(factorial(r), MOD-2, MOD);
    return res % MOD;
}

template<typename T>
long long pmt(T n, T r, T MOD=(T)(1e9)+7LL){
    if(r<=0 or r>n) return 1LL;
    long long res = 1LL;
    for(long long i=0; i<r; i++) res = (res * (n-i))%MOD;
    return res%MOD;
}
void factoring(ll N, vector<pair<ll, ll> > &res) {
    ll n=N;
    for(int i=2; i*i<N; i++) {
        if(n%i!=0) continue;
        pair<long long, long long> p = make_pair(i, 0);
        while(n%i==0){
            p.second++;
            n /= i;
        }
        res.push_back(p);
    }
    if(n>1) res.push_back(P(n, 1));
    return;
}

int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<P> fac;
    factoring(M, fac);
    ll res = 1LL;
    for(auto p: fac){
        res = (res * cmb(N-1+p.second, p.second)) % MOD;
    }
    cout << res << endl;
    return 0;
}

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
#define show(...) cerr << #__VA_ARGS__ << " = ",debug(__VA_ARGS__);
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...);
}
ll mod=1000000007;
ll combi(ll N_, ll C_) {
    const int NUM_=400001;
    static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
    if (fact[0]==0) {
        inv[1]=fact[0]=factr[0]=1;
        for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
        for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
    }
    if(C_<0 || C_>N_) return 0;
    return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}
ll hcomb(ll P_, ll Q_) { return (P_==0&&Q_==0)?1:combi(P_+Q_-1,Q_);}

ll modpow(ll a, ll n = mod-2) {
    ll r=1;
    while(n) r=r*((n%2)?a:1)%mod,a=a*a%mod,n>>=1;
    return r;
}
int main(){
    int n;
    string s;
    cin >> n >> s;
    ll cnt[26] = {};
    rep(i,n)cnt[s[i]-'a']++;
    int num = 0;
    rep(i,26)cnt[i]++;
    ll ans = 1;
    rep(i,26){
        ans = (ans * cnt[i]) % mod;
    }
    cout << (ans -1 + mod)%mod << endl;
    
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>

using namespace std;

#define fs first
#define sc second

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

const ll mod = 1e9+7;
ll fact[200200];
ll invfact[200200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a-b);
}


inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

vector<int> edge[101000];
ll dp[101000][2];

void dfs(int s, int prev){
    ll res0 = 1, res1 = 1;
    for(auto v: edge[s]){
        if(v == prev){
            continue;
        }
        dfs(v, s);
        res0 = mul(res0, add(dp[v][0], dp[v][1]));
        res1 = mul(res1, dp[v][0]);
    }
    dp[s][0] = res0;
    dp[s][1] = res1;
}


int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N-1; i++){
        int x, y;
        cin >> x >> y;
         x--;
         y--;
         edge[x].push_back(y);
         edge[y].push_back(x);
    }

    for(int i = 0; i < N; i++){
        dp[i][0] = dp[i][1] = 0;
    }

    dfs(0, 0);
    cout << add(dp[0][0], dp[0][1]) << endl;



    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
typedef pair<int, int> P;

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

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

struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};
int GCD(int a, int b){
    if(b==0) return a;
    return GCD(b, a%b);
}

int main() {
    vector<pair<string, int> > vp;
    string s; int n;
    while(cin >> s >> n){
        vp.push_back({s, n});
    }
    
    sort(vp.begin(), vp.end(), Less());
    vp.push_back({"BANPEI", 1});
    string ss=vp[0].first;
    cout << ss << endl;
    for(int i=1; i<vp.size(); ++i){
        if(vp[i].first==ss){
            cout << vp[i-1].second << " ";
        }else{
            cout << vp[i-1].second << endl;
            if(i==vp.size()-1) break;
            ss = vp[i].first;
            cout << ss << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 3176
# -*- coding:utf-8 -*-
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

counter = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        e = 0
        for xi, xj in zip(X[i], X[j]):
            e += (xj - xi)**2
        e = e**0.5
        counter += 1 if float.is_integer(e) else 0

print(counter)

Measured memory_bytes: 3188
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

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

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

int main()
{
    int x[5], y[5];
    cin >> x[1] >> y[1] >> x[2] >> y[2];
    int dx = x[2] - x[1];
    int dy = y[2] - y[1];

    int dx23 = -dy;
    int dy23 = dx;
    x[3] = x[2] + dx23;
    y[3] = y[2] + dy23;

    int dx34 = -dy23;
    int dy34 = dx23;
    x[4] = x[3] + dx34;
    y[4] = y[3] + dy34;

    cout << x[3] << " " << y[3] << " " << x[4] << " " << y[4] << endl;
}

Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int a, b, c;

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> a >> b >> c;
   if (a + b + c >= 22) cout << "bust";
   else cout << "win";
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

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

int main(){
    int n;
    cin>>n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(long long int k=0;;){
        bool isok=true;
        auto it=max_element(a.begin(),a.end());
        if(*it<n){
            cout<<k<<endl;
            return 0;
        }
        long long int cnt=(*it)/n;
        k+=cnt;
        for(int i=0;i<n;i++){
            if(i!=it-a.begin()) a[i]+=cnt;
            else a[i]%=n;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
namespace pro
{
    class MainClass
    {
        public static void Main()
        {
            int n0 = int.Parse(Console.ReadLine());
            int n1 = n0;
            int count0 = 0;
            int count1 = 0;
            while (n0 >= 10)
            {
                n0 /= 10;
                count0++;
            }

          
            if (n1 < 10)
            {
                count1 = n1;
            }
            else if (count0 % 2 == 0)
            {

                int d = (int)Math.Pow(10, count0 + 1) - 1 - n1;
                while (count0 >= 0)
                {
                    count1 = count1 + (int)Math.Pow(10, count0+1) - (int)Math.Pow(10, count0);
                    count0 = count0 - 2;
                }
                count1= count1-d;
            }
            else
            {
                count0 = count0 - 1;
                while (count0 >= 0)
                {
                    count1 = count1 + (int)Math.Pow(10,count0+1) - (int)Math.Pow(10, count0);
                    count0 = count0 - 2;
                }

            }
            Console.WriteLine(count1);
        }
    }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define int long long

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

// UnionFindTree begin
class UnionFindTree {
 public:
  int size_;
  vector<int> parent_, rank_;

  UnionFindTree() : size_(0), parent_(), rank_() {}
  UnionFindTree(int size) : size_(size), parent_(size), rank_(size, 0) {
    REP(i, size) { parent_[i] = i; }
  }

  int Find(int x) {
   if (parent_[x] == x) {
     return x;
   } else {
     int f = Find(parent_[x]);
     parent_[x] = f;
     return f;
   }
  }
  void Unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) { return; }
    if (rank_[x] < rank_[y]) {
      parent_[x] = y;
    } else if (rank_[x] > rank_[y]) {
      parent_[y] = x;
    } else {
      parent_[x] = y;
      rank_[y] += 1;
    }
  }
  bool Same(int x, int y) { return (Find(x) == Find(y)); }

};
// UnionFindTree end

const int kMaxN = 100000;
const int kMaxM = 100000;

int N, M;
int A[kMaxN], B[kMaxN];
int U[kMaxM], V[kMaxM];
int ans = 0;

signed main() {
  cin >> N >> M;
  REP(i, N) { cin >> A[i] >> B[i]; }
  REP(i, M) {
    int u, v;
    cin >> u >> v;
    U[i] = u-1; V[i] = v-1;
  }

  int C[kMaxN];
  REP(i, N) { C[i] = MAX(A[i]-B[i], 0); }
  int es[kMaxM];
  REP(i, M) { es[i] = i; }
  auto comp = [&C](int i, int j) {
    return MAX(C[U[i]], C[V[i]]) < MAX(C[U[j]], C[V[j]]);
  };
  sort(es, es+M, comp);
  // REP(i, M) { cout << U[es[i]] << " " << V[es[i]] << endl; }
  UnionFindTree uft(N);
  int money[kMaxN];
  REP(i, N) { money[i] = C[i] + B[i]; }
  int bsum[kMaxN];
  REP(i, N) { bsum[i] = B[i]; }

  REP(i, M) {
    int u = U[es[i]], v = V[es[i]];
    if (!uft.Same(u, v)) {
      int uu = uft.Find(u), vv = uft.Find(v);
      uft.Unite(u, v);
      int uv = uft.Find(u);
      money[uv] = MIN(
        MAX(money[uu], C[v])+bsum[vv], MAX(money[vv], C[u])+bsum[uu]);
      bsum[uv] = bsum[uu]+bsum[vv];
    }
    // REP(i, N) { cout << money[i] << " "; }
    // cout << endl;
  }
  ans = money[uft.Find(0)];

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


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {

	long long int n;
	cin >> n;

	string s = "";


	if (n == 0) {
		s = "0";
	}


	while (n != 0) {
		long long int a = n / (-2);
		long long int b = n - a * (-2);
		if (b == -1) {
			a++;
			s = "1" + s;
		}
		else if (b == 1) {
			s = "1" + s;
		}
		else {
			s = "0" + s;
		}
		n = a;
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int k,s,x,y,z;
	scanf("%d %d",&k,&s);
	long long ans = 0;
	for(x = 0; x <= k; x++){
		for(y = 0; y <= k; y++){
			if((s - x - y) <= k && (s - x - y) >= 0) ans++;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	while(N--)
	{
		int count = 3;
		int digit = 0;
		int score = 0;
		while(count)
		{
			string str;
			cin >> str;
			if(str == "HIT")
			{
				digit <<= 1;
				if(digit >= 8)
				{
					++score;
					digit -= 8;
				}
				++digit;
			}
			else if(str == "HOMERUN")
			{
				++score;
				for(int i = 0; i < 3; ++i)
				{
					if(digit & 1)
					{
						++score;
					}
					digit >>= 1;
				}
			}
			else if(str == "OUT")
			{
				--count;
			}
		}
		cout << score << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    queue<int> four;
    queue<int> two;
    queue<int> one;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a%4==0)four.push(a);
        else if(a%2==0)two.push(a);
        else one.push(a);
    }
    long long int x[n];
    for(int i=0;i<n;i++){
        if(i%2==0 && !one.empty()){
            x[i]=one.front();
            one.pop();
        }
        else if(i%2==0 && !two.empty()){
            x[i]=two.front();
            two.pop();
        }
        else if(i%2==0 && !four.empty()){
            x[i]=four.front();
            four.pop();
        }
        else if(i%2==1 && !four.empty()){
            x[i]=four.front();
            four.pop();
        }
        else if(i%2==1 && !two.empty()){
            x[i]=two.front();
            two.pop();
        }
        else if(i%2==1 && !two.empty()){
            x[i]=one.front();
            one.pop();
        }
    }
    for(int i=0;i<n-1;i++){
        if((x[i]*x[i+1])%4!=0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

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

signed main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n;
    string s;
    cin >> n >> s;

    int a = 0,b = 0;


    for(int x = 0;x < 300;x ++){
        a = 0;
        b = 0;
        for(int i = 0;i < s.size();i ++){
        
            if(s.at(i) == '(') a ++;
            else b ++;

            if(a < b){
                s = '(' + s;
                break;
            }
        }
    }

    for(int x = 0;x < 300;x ++){
        a = 0;
        b = 0;
        for(int i = s.size()-1;i >= 0;i --){

            if(s.at(i) == '(') a ++;
            else b ++;

            if(a > b){
                s = s + ')';
                break;
            }
        }
    }

    cout << s << endl;
}

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

const int N3 = 6005;
const int N4 = 8005;
int inv2;
int n, n3, n4, mod;
int f[N3][N4];

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

int main()
{
	scanf("%d%d", &n, &mod);
	f[0][n] = 1;
	n3 = n * 3;
	n4 = n * 4;
	inv2 = mod + 1 >> 1;
	for (int i = 0; i < n3; ++i)
		for (int j = 0; j <= n4; ++j)
		if (f[i][j])
		{
			if (i + 1 <= n3 && j + 1 <= n4)
				add(f[i + 1][j + 1], f[i][j]);
			if (i + 2 <= n3 && j - 1 >= 0)
				f[i + 2][j - 1] = (1ll * f[i][j] * (i + 1) + f[i + 2][j - 1]) % mod;
			if (i + 3 <= n3)
				f[i + 3][j] = (1ll * f[i][j] * (i + 1) * (i + 2) + f[i + 3][j]) % mod;
		}
	int ans = 0;
	for (int j = n; j <= n4; ++j)
		add(ans, f[n3][j]);
	printf("%d\n", ans);
}

Measured memory_bytes: 186112