akhauriyash/Code-Regression huggingface dataset:
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for i in range(d)]

ans = float("inf")

for bit in range(1 << d):
    count = 0
    sum = 0
    nokori = set(range(1, d + 1))

    for i in range(d):
        if bit & (1 << i):
            sum += pc[i][0] * (i + 1) * 100 + pc[i][1]
            count += pc[i][0]
            nokori.discard(i + 1)

    # G 点に満たなければ nokori のうち一番大きいものを解く
    if sum < g:
        use = max(nokori)
        n = min(pc[use - 1][0], -(-(g - sum) // (use * 100)))
        count += n
        sum += n * use * 100

    if sum >= g:
        ans = min(ans, count)

print(ans)

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

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a.at(i);
  }
  int ans = 400000000;
  for (int i = -100; i <= 100; i++)
  {
    int sum = 0;
    for (int j = 0; j < N; j++)
    {
      int cost = pow(abs(i - a.at(j)), 2);
      sum += cost;
    }
    ans = min(sum, ans);
  }
  cout << ans << endl;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;

int main()
{
    _FastIO;
    cin >> s;
    string ans = "Yes";
    for(int i = 0; i < s.size(); i++){
        if(i % 2 && s[i] == 'R')
            ans = "No";
        if(i % 2 == 0 && s[i] == 'L')
            ans = "No";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>                                                 //Include Libraries
#include <string>                                                   //Include Libraries
#include <vector>                                                   //Include Libraries
using namespace std;                                                //Bad practice


int main(int argc, char const *argv[]) {
	

	string Data;
	cin >> Data;

	bool IsPossible = true;

	if (Data.find("N") != string::npos and Data.find("S") == string::npos)
		IsPossible = false;

	if (Data.find("S") != string::npos and Data.find("N") == string::npos)
		IsPossible = false;

	if (Data.find("E") != string::npos and Data.find("W") == string::npos)
		IsPossible = false;

	if (Data.find("W") != string::npos and Data.find("E") == string::npos)
		IsPossible = false;

	if (IsPossible) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#import<cstdio>
#define r(a) for(int i=0;i++<a;)
#define s(a) scanf("%d",&a);
#define c(a,b) a=a<b?a:b
int w,n,m,d[999],p[999];main(){s(n)s(m)r(n)s(d[i-1])r(n)p[i-1]=1e9;r(m){s(w)r(n)c(p[i-1],p[i]+w*d[n-i]);}printf("%d\n",*p);}

Measured memory_bytes: 1032
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        long X = nextLong();
        
        int cnt = 0;
        long newBalance = 100;

        while(newBalance<X){
            cnt++;
            //newBalance = newBalance * 101 /100; // this will overflows
            newBalance= newBalance + newBalance/100;
        }

        System.out.println(cnt);

    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32824
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include<limits.h>


#define eps 1e-8
#define PI 3.141592653589793
#define bsize 512

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define bs 1000000007

using namespace std;

int longestCommonSubsequence(string s1, string s2, vector<vector<int>>& dp) 
{
    for (int i = 1; i <= s1.size(); i++) 
    {
        for (int j = 1; j <= s2.size(); j++) 
        {
            if (s1[i-1] == s2[j-1]) 
                dp[i][j] = dp[i-1][j-1] + 1;

            dp[i][j] = max({dp[i][j], dp[i][j-1], dp[i-1][j]});
        }
    }
    return dp[s1.size()][s2.size()];
}

int main()
{
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cout.tie(NULL) ;
    
    string s1, s2; 
    cin >> s1 >> s2;

    vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1, 0));
    int count = longestCommonSubsequence(s1, s2, dp);   // This will give count of lcs and change the dp vector

    string s = "";
    int i = s1.size(), j = s2.size();
    while (i > 0 && j > 0) 
    {
        if (dp[i-1][j-1] + 1 == dp[i][j] && dp[i-1][j] + 1 == dp[i][j] && dp[i][j-1] + 1 == dp[i][j]) 
        {
            i--; 
            j--; 
            s = s1[i] + s; //As we are travelling backward reverse the string
        }
        else if (dp[i][j-1] > dp[i-1][j]) 
            j--;
        else
            i--;
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 38992
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll N, K;
map<ll, ll> m;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> K;
	rep(i, 0, N) {
		ll a, b;
		cin >> a >> b;
		m[a] += b;
	}

	ll k = 0;

	for(auto itr = m.begin(); itr != m.end(); itr++) {
		k += itr->second;
		if(k >= K) {
			cout << itr->first << endl;
			return 0;
		}
	}


}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int N;
    double sum;
    cin>>N;
    for(int i=0;i<N;i++){
        double x;
        cin>>x;
        sum+=(1/x);
    }
    cout<<setprecision(10)<<(1/sum)<<endl;
}

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

using namespace std;

int main(){
	string s;
	cin >> s;
	int l = s.size();
	int ans = 0;
	for (int i = 0; i < l; i++)
		ans = ans + (s[i] - 48);
	if (ans % 9 == 0) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3728
C = input()
S = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
     'j', 'K', 'l', 'n', 'm', 'o', 'p', 'q', 'r',
     's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

print(S[S.index(C)+1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

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

	string a = "";
	for (int i = 0; i < s.size(); i++) {
		char c = s.at(i);
		//cout << "c:" << c << endl;

		if (a == "" && c == 'B') continue;
		switch (c) {
		case '0':
			//cout << "c==0" << endl;
			a.push_back('0');
			continue;
		case '1':
			//cout << "c==1" << endl;
			a.push_back('1');
			continue;
		case 'B':
			//cout << "c==B" << endl;
			a.pop_back();
			continue;
		}
	}

	cout << a << endl;
}

Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators 
//do not forget to change the sizes of arrays and value of contants and other things after debugging  
 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)
 
#define SZ(x)  (ll)(x.size())
 
//comment the below if not required
 

 
#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second

 
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//cout<<"Case #"<<c<<": "<<ans<<"\n" ;

int r,c,q,u,v,ans,mxr,mxc,i,Q;

const int N = 3e5+1;

int mu[N],mv[N];

map<pair<int,int>,int> m;

vector<int> vr,vc;

int main()
{
    IOS;

    cin>>r>>c>>q;

    Q=q;

    while(q--)
    {
        cin>>u>>v;
        ++mu[u],++mv[v];
        mxr=max(mxr,mu[u]);
        mxc=max(mxc,mv[v]);
        m[{u,v}]=1;
    }

    ans = mxr+mxc-1;

    for(i=1;i<=r;++i)
        if(mxr==mu[i])
            vr.pb(i);

    for(i=1;i<=c;++i)
        if(mxc==mv[i])
            vc.pb(i);

    if((SZ(vr)*SZ(vc))>Q)
            cout<<(ans+1);
    else
    {
        for(auto u : vr)
            for(auto v : vc)
            {
                if(!m[{u,v}])
                {
                    cout<<(ans+1);
                    return 0;
                }
            }

        cout<<ans;
    }
    
    return 0;
}

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

int mask[8]={0444,0222,0111,0700,070,07,0124,0421};
int create_mask(char c,char board[9]){
	int res=0;
	for(int i=0;i<9;i++){
		if(c==board[i])res |= 1<<i;
	}
	return res;
}
int main(){
	char board[9];
	int b,w;
	string win;
	while(cin>>board[0], board[0]!='0'){
		for(int i=1;i<9;i++)cin>>board[i];
		b = create_mask('b',board);
		w = create_mask('w',board);
		win = "NA";
		for(int i=0;i<8;i++){
			if((w&mask[i])==mask[i]){
				win="w";
				break;
			}
			else if((b&mask[i])==mask[i]){
				win="b";
				break;
			}
		}
		cout<<win<<endl;
	}
}

Measured memory_bytes: 0
def main():

    inf = 1000000007
    n = int(input())
    e = [[] for _ in range(n)]
    d = [inf]*n
    f = [inf]*n
    step = 1

    def dfs(v):
        nonlocal step
        d[v] = step
        step+=1
        for u in e[v]:
            if d[u] == inf:dfs(u)
        f[v] = step
        step +=1

    e = [[] for _ in range(n)]
    for i in range(n):
        m = list(map(int,input().split()))
        for j in range(2,len(m)):
            e[m[0]-1].append(m[j]-1)
    for i in range(n):
        if d[i]==inf:dfs(i)
    for i in range(n):
        print (i+1,d[i],f[i])

if __name__ == '__main__':
    main()




Measured memory_bytes: 5720
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int k, x;
  cin >> k >> x;
  
  for ( int i = x - (k-1); i < k + x; i++)
    cout << i << endl;
}

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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define pi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vl vector<ll>
#define vii vector<pair<int,int> >
#define vll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair3

const ll mod=1e9+7;
#define MAX 100000

int modulo = 420047;

ll binexpo(ll a,ll b,ll c){

    if(b==0) return 1;
    else if(b%2==0) return binexpo(((a%c)*(a%c))%c,b/2,c)%c;
    else return ((a%c)*(binexpo(((a%c)*(a%c))%c,b/2,c)%c))%c;
}

ll inf = (ll)1e12;

int main(){

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);

    string a,b;
    cin>>a>>b;

    vector<vector<pair<int,pi> > > dp((int)a.size() + 1, vector<pair<int,pi> >((int)b.size() + 1));

    dp[0][0].first = 0;
    dp[0][0].second.first = 0;
    dp[0][0].second.second = 0;
    FOR(j,1,(int)b.size() + 1){
        dp[0][j].first = 0;
        dp[0][j].second.first = 0;
        dp[0][j].second.second = j-1;
    }

    FOR(i,1,(int)a.size() + 1){
        dp[i][0].first = 0;
        dp[i][0].second.first = i-1;
        dp[i][0].second.second = 0;
    }


    int u = (int)a.size() + 1,v = (int)b.size() + 1;
    FOR(i,1,u){
        FOR(j,1,v){
            if(a[i-1] == b[j-1]){
                dp[i][j].first = dp[i-1][j-1].first + 1;
                dp[i][j].second.first = i-1;
                dp[i][j].second.second = j-1;
            }
            else{
                if(dp[i-1][j].first >= dp[i][j-1].first){
                    dp[i][j].first = dp[i-1][j].first;
                    dp[i][j].second.first = i-1;
                    dp[i][j].second.second = j;

                }
                else{
                    dp[i][j].first = dp[i][j-1].first;
                    dp[i][j].second.first = i;
                    dp[i][j].second.second = j-1;
                }
            }
        }
    }

    string ans = "";
    int s = (int)a.size();
    int e = (int)b.size();
    while(s!=0 && e!=0){
        int ns = dp[s][e].second.first;
        int ne = dp[s][e].second.second;
        if(dp[ns][ne].first < dp[s][e].first)
            ans = ans + a[s-1];
        s = ns;
        e = ne;
    }

    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 105984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ab = a+b;
    int cd = c+d;
    if(ab==cd){
        cout << "Balanced" << endl;
    }
    if(ab>cd){
        cout << "Left" << endl;
    }
    if(ab<cd){
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) return b; return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
    int x;
    int n;
    cin >> x;
    cin >> n;
    set <int > s;
    for (int i = 0; i <= 101; i++) {
        s.insert(i);
    }
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s.erase(s.find(x));
    }
    int ans = INT_MAX;
    int p = 100;
    for (auto i : s) {
        if (abs(i - x) < ans) {
            ans = abs(i - x);
            p = i;
        }
    }
    cout << p;
}
int  main()
{

    fastio;
    int t = 1;
    if (takeTestCases) cin >> t;
    int t_t = 1;
    while (t--) {
        if (printCaseNo)
        case (t_t);

        getac(t_t);
        t_t++;
    }
    cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(n&1){
    cout<<"No";
    return 0;
  }
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[i+n/2]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define F(i,L,R) for (ll i = L; i < R; i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define re(x) scanf("%lld",&x)
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s,t;
  cin>>s>>t;
  ll mini= INT_MAX;
  for(int i = 0;i<s.length()-t.length()+1;i++){
  	ll cnt  =0, k = i;
  	for(int j = 0;j<t.length();j++,k++) if(s[k]!=t[j]) cnt++;
  		//cout<<cnt<<endl;
 	mini = min(mini, cnt);
  }
  cout<<mini;
  return 0;
}

Measured memory_bytes: 3644
s1=raw_input().split(' ')
s2=raw_input().split(' ')
s3=raw_input().split(' ')
l=[0 for i in range(9)]
for i in range(3):
    l[i]=int(s1[i])
    l[i+3]=int(s2[i])
    l[i+6]=int(s3[i])
    
if l[2]-l[1]==l[5]-l[4]==l[8]-l[7] and l[1]-l[0]==l[4]-l[3]==l[7]-l[6] and l[6]-l[3]==l[7]-l[4]==l[8]-l[5] and l[3]-l[0]==l[4]-l[1]==l[5]-l[2]:
    print 'Yes'
else:
    print 'No'

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
string s,t;
int n,m;
vector<string> ans;

void check(int start){
    string res = "";
    rep(i,start){
        if(s[i] =='?' )res += 'a';
        else res += s[i];
        //cout << start << " " << res << endl;
    }
    if(start + m > n)return;
    for(int i = start;i < min(n,start + m);i++){
        if(s[i] == '?'|| s[i] == t[i-start])res += t[i-start];
        else return ;

    }
    for(int i = start + m;i < n;i++){
        if(s[i] == '?')res += 'a';
        else res += s[i];

    }
    ans.push_back(res);
}
signed main(){
    cin >> s;
    cin >> t;
    n = s.size(),m = t.size();
    rep(i,n){
        if(s[i] == t[0] || s[i] == '?'){
            check(i);
        }
    }
    if(ans.size() == 0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 


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

int K; cin >> K;
VI A(K); invec(A);
i64 maxA = *max_element(ALL(A));

i64 mini, maxi;
i64 l = 0, r = 2 + K * maxA;
while (r - l > 1){
    i64 mid = (r + l) / 2;
    i64 m = mid;
    for(i64 a: A) m -= m%a;

    if (m >= 2) r = mid;
    else l = mid;
}
mini = r;

l = 0, r = 2 + K * maxA;
while (r - l > 1){
    i64 mid = (r + l) / 2;
    i64 m = mid;
    for(i64 a: A) m -= m%a;

    if (m <= 2) l = mid;
    else r = mid;
}
maxi = l;

if (mini > maxi ) cout << "-1\n";
else cout << mini << ' ' << maxi << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;
using int64 = long long;
#define ForInt(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define ForIntInit(i, begin, end) for (int i = (begin); i < (end); ++i)
#define ForItr(it, itBegin, itEnd) for (auto (it) = (itBegin); (it) != (itEnd); ++(it))


int main()
{
	using Job = pair<int, int>;
	int n, m;
	cin >> n >> m;

	vector<vector<int>> jobs(m);
	int day, amount;
	ForInt(i, n)
	{
		cin >> day >> amount;
		if (day > m) continue;
		jobs[day - 1].push_back(amount);
	}

	priority_queue<int> targets;
	int64 sum = 0;
	ForInt(t, m)
	{
		ForItr(it, jobs[t].begin(), jobs[t].end())
		{
			targets.push(*it);
		}
		if (!targets.empty())
		{
			sum += targets.top();
			targets.pop();
		}
	}
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 5504
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)

func main() {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	a := make([]int, 5)
	for i := 0; i < 5; i++ {
		s.Scan()
		a[i], _ = strconv.Atoi(s.Text())
	}
	min := a[0]
	for i, _ := range a {
		if a[i] < min {
			min = a[i]
		}
	}
	ans := n / min
	if n%min != 0 {
		ans += 1
	}
	ans += 4
	fmt.Println(ans)
}

Measured memory_bytes: 640
N = input()
NN = int(N)


def p(x):
    if x == 3:
        print('bon')
    elif x == 0 or x == 1 or x == 6 or x == 8:
        print('pon')
    else:
        print('hon')


if NN >= 100:
    s = int(N[2])
    p(s)
elif NN >= 10:
    s = int(N[1])
    p(s)
else:
    s = int(N[0])
    p(s)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

int n, ma, mb;
int dp[401][401];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c, ans=INF;
    cin >> n >> mb >> ma;
    for(int i=1; i<=400; i++)
    {
        for(int j=1; j<=400; j++)
            dp[i][j] = INF;
    }
    for(int i=0; i<n; i++)
    {
        cin >> a >> b >> c;
        for(int j=400-a; j; j--)
        {
            for(int k=400-b; k; k--)
            {
                if(dp[j][k]!=INF) dp[j+a][k+b]=min(dp[j+a][k+b], dp[j][k]+c);
            }
        }
        dp[a][b]=min(dp[a][b], c);
    }
    for(int i=1; i<=400; i++)
    {
        if((i*ma)%mb==0&&(i*ma)/mb<=400&&dp[i][(i*ma)/mb])
        {
            ans=min(ans, dp[i][(i*ma)/mb]);
        }
    }
    cout << ((ans==INF) ? -1 : ans);
}
//TODO: 54
//come back to 50D,


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
struct edge{
    int from,to,cost;
    edge(int from,int to,int cost):from(from),to(to),cost(cost){};
};
ll d[2501];
int V,E;
vector<edge> es;
set<int> canGoal;
ll INF =ll(1e18)+1;

bool find_negative_loop(){
    memset(d,0,sizeof(d));

    for(int i=0;i<V;i++){
        if(canGoal.find(i) == canGoal.end()){
            continue;
        }
        for(int j=0;j<E;j++){
             edge e = es[j];
            if(canGoal.find(e.to) == canGoal.end()){
                continue;
            }
           
            if(d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i == V-1){
                    return true;
                }
            }
        }
    }
    return false;
}

bool shortest_path(int s){
    for(int i=0;i<V;i++){
        d[i] = INF;
    }
    d[s] =0;
    int j=0;
    while(true){
        if(j>=V){
            return true;
        }
        bool update = false;
        for(int i=0;i<es.size();i++){
            edge e = es[i];
            if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if(!update){
            break;
        }
        j++;
    }
    return false;
}

int main() {
    int P;
    cin >> V >>E >>P;
    vector<edge> es2;
    vector<vector<int>> toGraph(V);
    for(int i=0;i<E;i++){
        int a,b,c;
        cin >> a >> b >>c;
        --a;--b;
        c = (P-c);
        es2.emplace_back(a,b,c);
        if(a!=b){
            toGraph[a].push_back(b);
        }
        
    }
    
    for(int i=0;i<V;i++){
        queue<int> q;
        q.push(i);
        set<int> already;
        already.insert(i); 
        while(!q.empty()){
            int from = q.front();
            q.pop();
            for(int to:toGraph[from]){
                if(already.find(to) == already.end()){
                    q.push(to);
                    already.insert(to);
                }
            }
        }
        if(already.find(V-1) != already.end()){
            // cerr << i << endl;
            canGoal.insert(i);
        }
    }
    for(int i=0;i<E;i++){
        edge e = es2[i];
        if(canGoal.find(e.from) != canGoal.end() && canGoal.find(e.to) != canGoal.end()){
            es.emplace_back(e.from,e.to,e.cost);
        }
    }
    if(shortest_path(0)){
        cout << -1 << endl;
        return 0;
    }
    cout << max(-d[V-1],0LL) << endl;
    return 0;
}

Measured memory_bytes: 896
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09 + 7;

ll nCr(int n, int r);

ll nCr(int n, int r){
  if(r == 0) return 1;
  return nCr(n, r - 1) * (n - (r - 1)) / r;
}

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

  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  REP(i, n) cin >> v[i];

  sort(v.rbegin(), v.rend());

  ll sum = 0;
  REP(i, a) sum += v[i];
  double ave = (double)sum / a;
  cout << fixed << setprecision(10) << ave << endl;

  int p = 0, q = 0;

  for(int i = a - 1; i >= 0; i--){
    if(v[i] != v[a - 1]) break;
    p++;
  }
  for(int i = a; i < n; i++){
    if(v[i] != v[a - 1]) break;
    q++;
  }

  ll ans = 0;
  if(p == a){
    FOR(i, a, b + 1) ans += nCr(p + q, i);
  }
  else ans = nCr(p + q, p);
  cout << ans << endl;
}


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


int main()
{
    string str, order;
    int rpt, num1,num2;

    cin >> str;
    cin >> rpt;
    
    for(int i=0; i<rpt; i++)
    {
        cin >> order;
        if(order == "print")
        {
            cin >> num1 >> num2 ;
            for(int j=num1; j<=num2; j++)
            {
                cout << str[j];
            }
            cout << endl;
        }
        else if(order == "reverse")
        {
            cin >> num1 >> num2;
            string rev;
            rev = str;
            for(int j=0; j<num2-num1+1; j++)
            {
                str[num2-j] = rev[num1+j];
            }
        }
        else if(order == "replace")
        {
            string rpc;
            cin >> num1 >> num2 >> rpc;
            for(int j=0; j<num2-num1+1; j++)
            {
                str[num1+j] = rpc[j];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
using namespace std;
int main()
{
    char str1[4],str2[4];
    cin>>str1;
    cin>>str2;
    int coun=0;
    for(int i=0;i<3;i++){
        if(str1[i]==str2[i])
            coun++;
    }
    cout<<coun;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if( a < -1000 || 1000 < a){
        return -1;
    }else{
        if( b < -1000 || 1000 < b){
            return -1;
        }else{
            
            if( a < b ){
                printf("a < b\n");
            }else if( a > b ){
                printf("a > b\n");
            }else{
                printf("a == b\n");
            }
        }
    }
    
    return 0;

}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int N;

int main()
{
  cin >> N;
  cout << (N+999)/1000*1000-N << endl;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void){
    int a[3];
    int i;
    int max = 0;
    for(i=0;i<3;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<3;i++){
        if(a[i]>max){
            max =a[i];
        }
    }
    printf("%d",max*9+a[0]+a[1]+a[2]);
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
void SieveOfEratosthenes(ll n);
ll fastpowMOD(ll a, ll p,ll MOD);
ll lcm(ll a, ll b);
const int LIM = 1e5+5; //MOD = 998244353;
ll MOD =  1e9+7;
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
bool seive[LIM];
 
void SieveOfEratosthenes(ll n)
{ memset(seive, true, sizeof(seive));
seive[0] = false;
seive[1] = false;
 for (ll p=2; p*p<=n; p++) if (seive[p] == true) for (ll i=p*p; i<=n; i += p) seive[i] = false; }
 
 
 ll combo(ll n, ll k){
 	if(k==0) return 1;
 	ll N=1,D=1;
 	for(ll i = 1;i<=k;i++){
 		N = (((n-i+1)%MOD)*N)%MOD;
 		D = (D*i)%MOD;
	 }
	 
	 return (N*fastpowMOD(D,MOD-2,MOD))%MOD;
 }
 
 
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 } 
/*********************************************/





map<ll,ll> mp;
ll ans = 0;
void factr(ll t){
	if(t==1 || t==0){
		return;
	}
	if(t%2==0){
		ll lc = 0;
		while(t%2==0 && t>0){
			t /= 2;lc++;
		}
		if(mp[2]<lc) mp[2] = lc;
	}
	
	
	for(ll i=3;i*i<=t;i += 2){
		ll lc = 0;
		while(t%i==0 && t>0){
			t /= i;lc++;
		}
		if(mp[i]<lc) mp[i] = lc;
	}
	
	if(t>2){
		if(mp[t]<1) mp[t] = 1LL;
	}
	
	
}



int main(){
	fastio;
	ll n;
	cin>>n;
	vector<ll> a(n,0);
	for(ll i=0;i<n;i++){
		cin>>a[i];
		factr(a[i]);
	}
	ll lcmm = 1;
	for(auto it:mp){
	    if(it.second>0){
	        lcmm = ((lcmm%MOD)*fastpowMOD(it.first,it.second,MOD))%MOD;  
	    }
	    
	}
	
	//cout<<"lcm "<<lcmm<<"\n";
	
	for(ll i=0;i<n;i++){
	    //cout<<fastpowMOD(a[i],MOD-2,MOD)<<" ";
		ans = ((ans%MOD) + (lcmm*fastpowMOD(a[i],MOD-2,MOD))%MOD)%MOD;
	}
	//cout<<"\n";
	
	cout<<ans<<"\n";
	
}

















Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x);
        x=(x*x);
        n=n/2;
    }
    return result;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}


int main(){
   IOS;
ll t;t=1;//cin>>t;
while(t--){
ll n;cin>>n;
ll d;cin>>d;
 d=d*d;ll ans=0;
for(ll i=0;i<n;i++){
    ll x,y;
    cin>>x>>y;
    if(x*x+y*y<=d) ans++;
}
cout<<ans<<"\n";

}


    
    
    
    





return 0;}

Measured memory_bytes: 3632
from math import ceil
from decimal import *

N = int(input())
T, A = Decimal(1), Decimal(1)
for t, a in [map(int, input().split()) for _ in range(N)]:
    n = int(max(ceil(T / Decimal(t)), ceil(A / Decimal(a))))
    T, A = n * t, n * a
print(T + A)


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

int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  int ans;
  if (op == '+')
    ans = A + B;
  else
    ans = A - B;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;



void main() {
    long H;
    scan(H);
    long[long] memo;

    long dfs(long h) {
        if (h == 0) {
            return 0;
        }
        if (h in memo) {
            return memo[h];
        }
        return 2 * dfs(h / 2) + 1;
    }

    long ans = dfs(H);

    writeln(ans);
}
















void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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



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

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int x = cin.nextInt();
        int ans = 0;
        int[] ar = cin.ArrayInt(N);
        Array.Sort(ar);
        for (int i = 0; i < N; i++)
        {
            if(x >= ar[i])
            {
                ans++;
                x -= ar[i];
            }
        }
        if (x > 0 && ans == N) ans--;
        Console.WriteLine(ans);
    }
    
}






class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
  string s; cin >> s;
  int sn = s.size();
  int ans = 1;
  rep(i,sn-1) {
    int end = sn-1-i;
    if (end % 2 == 0) {
      string ss = s.substr(0,end);
      if (ss.substr(0, end/2) == ss.substr(end/2, end)) {
        ans = end;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n; cin >> n;
    vector<int> p(n+1, 0);
    repr(i, 1, n+1) cin >> p[i];

    int ans = 0;
    for(int i=1; i<=n; ++i){
        if(p[i] == i){
            int cnt = 0;
            while(i <= n && p[i] == i) { ++cnt; ++i; }
            ans += (cnt+1) / 2;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0 ; i < n ; i++){
            h[i] = sc.nextInt();
        }
        int[][] a = new int[2][m];
        for(int i = 0 ; i < m ; i++ ){
            a[0][i] = sc.nextInt() - 1;
            a[1][i] = sc.nextInt() - 1;
        }
        sc.close();
        int[] hi = new int[n];
        Arrays.fill(hi , 1);
        for(int i = 0 ; i < m ; i++){
            if(h[a[0][i]] > h[a[1][i]]){
                hi[a[1][i]] = 0;
            }else if(h[a[0][i]] < h[a[1][i]]){
                hi[a[0][i]] = 0;
            }else{
                hi[a[0][i]] = 0;
                hi[a[1][i]] = 0;
            }
        }
        int yono = 0;
        for(int i = 0 ; i < n ; i++){
            yono += hi[i];
        }
        System.out.println(yono);
    }
}

Measured memory_bytes: 61132
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <unistd.h>
using namespace std; 
using namespace std::chrono; 
using namespace __gnu_pbds;
#define ll long long int 
//mp.reserve(1024);
//mp.max_load_factor(0.25);
typedef tree<int, null_type, less<int>, rb_tree_tag,  
                 tree_order_statistics_node_update>  
          ordered_set;  
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
            x += 0x9e3779b97f4a7c15;
            x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
            x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
            return x ^ (x >> 31);
        }

        size_t operator()(uint64_t x) const {
            static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
            return splitmix64(x + FIXED_RANDOM);
        }
};
 
void addEdge(vector<ll> adj[], ll u, ll v) 
{ 
   adj[u].push_back(v); 
   adj[v].push_back(u); 
} 
vector<ll> z_function(string s) {
    ll n = s.length();
    vector<ll> z(n);
    for (ll i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}
ll m=998244353;
ll power(ll x,ll y) 
{ 
    ll res = 1; // Initialize result 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = ((res%m) * (x%m))%m; 
  
        // n must be even now 
        y = y >> 1; // y = y/2 
        x = ((x%m) * (x%m))%m; // Change x to x^2 
    } 
    return res; 
} 
int main() 
{ 
 	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
    //freopen("input.txt", "r", stdin); 
    //freopen("output1.txt", "w", stdout); 
	ll n;
	cin>>n;
	ll v[n][3],dp[n][3];
	for(ll i=0;i<n;i++){
		dp[i][0]=0;
		dp[i][1]=0;
		dp[i][2]=0;
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<3;j++){
			cin>>v[i][j];
		}
	}
	dp[0][0]=v[0][0],dp[0][1]=v[0][1],dp[0][2]=v[0][2];
//	cout<<dp[0][0]<<" "<<dp[1][1]<<" "<<dp[2][2]<<endl;
	for(ll i=0;i<n-1;i++){
		//cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
		dp[i+1][1]=max(dp[i][0]+v[i+1][1],dp[i][2]+v[i+1][1]);
		dp[i+1][0]=max(dp[i][1]+v[i+1][0],dp[i][2]+v[i+1][0]);
		dp[i+1][2]=max(dp[i][1]+v[i+1][2],dp[i][0]+v[i+1][2]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    return 0; 
} 


Measured memory_bytes: 4992
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table



def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

while 1:
    if is_prime(N) == True:
        print(N)
        exit()
    else:
        N += 1


Measured memory_bytes: 5168
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
        String weather = rd.readLine();
        String input = rd.readLine();

        int result = 0;
        for(int i=0; i<3; i++) {
            if(weather.charAt(i) == input.charAt(i)) {
                result++;
            }
        }
        System.out.print(result);
    }
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    Int y, x;
} p_t;

Int n, u, v;
vector<Int> G[100001];
vector<Int> G2[100001];
Int aoki_d[100001];
vector<Int> t;

void dfs(Int x) {
    for (Int i = 0; i < G[x].size(); i++) {
        Int to = G[x][i];
        if (aoki_d[to] < 0) {
            G2[x].push_back(to);
            aoki_d[to] = aoki_d[x] + 1;
            dfs(to);
        }
    }
}

bool dfs2(Int x) {
    if (x == u) {
        t.push_back(x);
        return true;
    }
    bool check = false;
    for (Int i = 0; i < G2[x].size(); i++) {
        Int to = G2[x][i];
        check = check or dfs2(to);
    }
    if (check) {
        t.push_back(x);
    }
    return check;
}

Int d_ma;

void dfs3(Int x) {
    d_ma = max(d_ma, aoki_d[x]);
    for (Int i = 0; i < G2[x].size(); i++) {
        Int to = G2[x][i];
        dfs3(to);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> u >> v;
    for (Int i = 0; i < n - 1; i++) {
        Int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (Int i = 1; i <= n; i++) {
        aoki_d[i] = -1;
    }
    aoki_d[v] = 0;
    dfs(v);
    dfs2(v);
    Int root = t[(aoki_d[u] + 1) / 2 - 1];
    Int res = aoki_d[root] - aoki_d[u];
    dfs3(root);
    res += d_ma;
    dump(d_ma - 1);
    return 0;
}

Measured memory_bytes: 17280
use POSIX qw(ceil);
my ($N,$K) =split(/ /,<>);
my $s = <>; chomp $s;
my @dat = split(/ /,$s);
my $ok =10**9;
my $ng =0; 
while( $ok-$ng>1){
    my $md =int(($ok+$ng)/2);
    my $sum=0;
    for(my $i=0;$i<=$#dat;$i++){
        $sum = $sum + (ceil($dat[$i]/$md)-1);
    }
    if($sum <= $K){
        $ok = $md;
    }else{
        $ng = $md;
    }
}
print "$ok\n";

Measured memory_bytes: 30300