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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  ll sum=0;
  vll a(n);
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  
  ll ans=LINF;
  ll tmp=0;
  rep(i,n-1){
    tmp+=a[i];
    chmin(ans,abs(tmp-sum+tmp));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, N;
    cin >> H >> N;
    VL A(N), B(N);
    rep(i, 0, N) cin >> A[i] >> B[i];

    // dp[i][j] := The minimum MPs to achieve j damage where 0 to i magic are able to use. 
    VVL dp(N+1, VL(H+1, 1e18));

    dp[0][0] = 0;
    rep(i, 0, N){
        rep(j, 0, H+1){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(j+A[i], H)] = min(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }
    }

    cout << dp[N][H] << endl;
    return 0;
}

Measured memory_bytes: 78976
#include<bits/stdc++.h>
using namespace std;
int isprime[100005];
int pri(){
	memset(isprime,0,sizeof(isprime));
	for(int i=2;i<=100100;i++){
		if(isprime[i]==0){
			for(int j=i*2;j<=100100;j+=i)
				isprime[j]=1;
		}
	}
}
int main(){
	pri();
//	long long a,b,k;
//	cin>>a>>b>>k;
//	if(a<=k){
//		k-=a;
//		a=0;
//		
//	}
//	else {
//		a-=k;
//		k=0;
//	}
//	//cout<<a<<" "<<k<<"\n";
//	if(b<=k){
//		b=0;
//	}
//	else{
//		b-=k;
//	}
//	cout<<a<<" "<<b<<"\n";
	int x;
	cin>>x;
	for(int i=x;i<=100100;i++){
		if(isprime[i]==0){
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

// #include <unordered_set>
// #include <unordered_map>

#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

#define pb push_back
#define mp make_pair

int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}

typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;

const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;

// #define int long long

int main(){
  

    ios::sync_with_stdio(false);
    cin.tie(0);
	//cin高速化

    int a,b,c,x;
    cin>>a>>b>>c>>x;

    int ans=0;
    REP(i,a+1){
    	REP(j,b+1){
    		REP(k,c+1){
    			if(i*500+j*100+k*50==x){
    				ans++;
    			}
    		}
    	}
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//useful library
int long long gcd(int long long a, int long long b){
    return b?gcd(b,a%b):a;
} //最大公約数
int long long lcm(int long long a, int long long b){
    return a/gcd(a,b)*b;
} //最小公倍数
int long long GetDigit(int long long num){
    int long long digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
} //桁数
int long long GetDigitN(int long long num, int long long N){
    int long long digit=0;
    while(num!=0){
        num /= N;
        digit++;
    }
    return digit;
} //十進数でnumの際のN進数における桁数

int main(){
    int K;
    cin >> K;
    int long long ans = 0;
    for(int i = 0; i < K; i++){
        for(int j = 0; j < K; j++){
            for(int l = 0; l < K; l++){
                ans = ans + gcd(gcd(i + 1,j + 1),l + 1);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());

    int ans=0;

    for(int i=0;i<K;i++){
        ans=ans+p[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin (aka white_space)
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int n;
    cin>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    ll times=0;
    for(int i=n-1;i>=0;i--){
        a[i]+=times;
        if(a[i]%b[i]==0)continue;
        ll div=a[i]/b[i];
        div++;
        times+=(div*b[i])-a[i];
    }
    cout << times <<endl;
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 
int main() {    
    int n, k, ans = 1;
    cin >> n >> k;

    for(int i = 0; i < n; ++i) {
        if(ans*2 - ans < k) {
            ans *= 2;
        } else {
            ans += k;
        }
    }

    cout << ans << "\n";
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <limits>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric> // 最大公約数が使える
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;
const int inf = 1000000000; //10^9

int main()
{
    ll X;
    cin >> X;
    ll A=100;
    ll ans=0;
    while (A<X)
    {
        A*=1.01;
        ans++;
    }

    cout << ans << endl;
    
    
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int D;
bool check(VI y, VI z) {
    LL dist2 = 0;
    REP(i, D) {
        dist2 += (y[i] - z[i]) * (y[i] - z[i]);
    }
    LL dist = sqrt(dist2);
    return dist * dist == dist2;
}

int main(void) {
    int N;
    cin >> N >> D;
    VVI X(N, VI(D));
    REP(i, N) REP(j, D) cin >> X[i][j];

    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            if (check(X[i], X[j])) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        if(s.charAt(2) ==s.charAt(3) && s.charAt(4) == s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21716
#include <stdio.h>

int main(){
    int a,b,c;

    scanf("%d %d %d",&a,&b,&c);
    if( (a==5 && b == 5 && c == 7) || (a==5 && b == 7 && c == 5) || (a==7 && b == 5 && c == 5) )
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}


Measured memory_bytes: 128
import numpy as np

def in_map(x,y,map_str):
    if 0<=x and x <map_str.shape[1] and 0<=y and y<map_str.shape[0]:
        result=True
    else:
        result=False
    return result

def bom_count(bom,map_str,bom_map):
    # print(bom)
    for h in range(-1,2):
        for w in range(-1,2):
            # print(h,w)
            y = bom[0]+h
            x = bom[1]+w
            if h==0 and w==0:
                bom_map[y,x]=9
            if not in_map(x,y,map_str):
                continue
            if not map_str[y,x]=="#":
                bom_map[y,x]+=1

    # print(bom_map)
    return bom_map

if __name__ =="__main__":
    H,W=input_list=[int(i) for i in input().split()]
    map_str=np.empty((H,W),dtype=np.str_)
    for h in range(H):
        map_str[h] = np.array([i for i in input()])
    boms=np.where(map_str=="#")
    # print(boms)
    bom_map=np.zeros((H,W),dtype=np.int16)
    for i in range(len(boms[0])):
        bom=[boms[0][i],boms[1][i]]
        # print(bom)
        bom_map=bom_count(bom,map_str,bom_map)
    for h in range(H):
        print_str=""
        for w in range(W):
            if bom_map[h,w]==9:
                print_str+="#"
            else:
                print_str+=str(bom_map[h,w])
        print(print_str)


Measured memory_bytes: 12436
#include<bits/stdc++.h>
#define N 100100
using namespace std;
int ans=0,k;
vector<int> g[N];
int a[N];
int dep(int u){
	int cur=0;
	for(int i=0;i<g[u].size();i++){
		cur=max(cur,dep(g[u][i]));
	}
	if(a[u]==1) return 0;
	if(cur==k-1){
		ans++;
		return 0;
	}
	return cur+1;
}
int main(){
	int n;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	if(a[1]!=1) a[1]=1,ans++;
	for(int i=2;i<=n;i++) g[a[i]].push_back(i);
	dep(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10752
N, M = gets.split.map(&:to_i)
Hs = [nil] + gets.split.map(&:to_i)
ABs = readlines.map{|l| l.split.map(&:to_i)}

@g = ABs.each_with_object(Array.new(N + 1){[]}){|(a, b), o| o[a] << b; o[b] << a}
puts [*1 .. N].count{|u| @g[u].map{Hs[_1]}.all?{|h| h < Hs[u]}}

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

using namespace std;

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

	string s;
	cin >> s;
	int a = (s[0] - '0') * 10 + (s[1] - '0');
	int b = (s[2] - '0') * 10 + (s[3] - '0');
    bool ma = false, mb = false;
	if (a >= 1 && a <= 12)
		ma = true;
	if (b >= 1 && b <= 12)
		mb = true;
	if (ma && mb)
		cout << "AMBIGUOUS" << endl;
	else if (ma && !mb)
		cout << "MMYY" << endl;
	else if (!ma && mb)
		cout << "YYMM" << endl;
	else
		cout << "NA" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int di[4] = {-1, 0, 1, 0}, dj[4] = {0, 1, 0, -1}, MAX = 800, INF = 1e9;

int n, m, k, ans = INF, d[MAX][MAX];
string s[MAX];
pair<int,int> startPos;
inline bool valid(int i, int j) {
	return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) d[i][j] = INF;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		for(int j = 0; j < m; j++) if(s[i][j] == 'S') startPos = {i, j};
	}
	queue<pair<int,int> > q;
	q.push(startPos);
	d[startPos.first][startPos.second] = 0;
	while(!q.empty()) {
		int i, j;
		tie(i, j) = q.front();
		q.pop();
		for(int z = 0; z < 4; z++) {
			if(valid(i+di[z], j+dj[z]) and d[i+di[z]][j+dj[z]] == INF and s[i+di[z]][j+dj[z]] != '#'){
				q.emplace(i+di[z], j+dj[z]);
				d[i+di[z]][j+dj[z]] = d[i][j]+1;
			}
		}
	}
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) if(d[i][j] <= k) {
		ans = min((min(min(i, n-1-i), min(j, m-1-j))+k-1)/k+1, ans);
	}
	cout << ans;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define pb push_back
#define INF 1<<30
#define all(x) x.begin(),x.end()
#define ms(a,v) memset(a,v,sizeof a)
#define II ({int a; scanf("%d", &a); a;})
#define LL  ({ll  a; scanf("%lld", &a); a;})
#define EPS 1e-10
#define pi acos(0.0)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<int> vi ;
typedef vector<ll>vl;

#define FOR(i,n) for( __typeof(n)i = 0 ; i < n ; i++)
#define FORL(i,a, b) for( __typeof(n)i = a ; i <= b ; i++)
#define FORR(i,a, b) for( __typeof(n)i = a ; i >= b ; i--)
#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++)
#define forstl(i,n) for(__typeof(n.begin())i = n.begin();i!=n.end();i++)
#define forab(i,a,b) for( __typeof(b) i = a ; i <= (b) ; i++ )
#define forba(i,b,a) for( __typeof(b) i = b ; i >= (a) ; i-- )

int x[4] = {0 , 0 , -1, 1};
int y[4] = {1, -1, 0  , 0};



void solve()
{
	ll x, k , d;
	cin >> x >> k >> d;

	x = abs(x);

	ll t = x / d;
	if (t > k)
	{
		cout << (x - k * d) << endl;
	}
	else
	{
		k -= t;
		t = x - t * d;
		if (k % 2 == 0)
		{
			cout << t << endl;
		}
		else
		{
			cout << abs(t - d) << endl;
		}
	}
}

int main()
{


	int T = 1;
	//cin >> T;
	// cin.ignore(); must be there when using getline(cin, s)

	//freopen("input.txt", "r", stdin);

	// Printing the Output to output.txt file
	//freopen("output.txt", "w", stdout);

	while (T--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <bitset>
#include <stack>
//#include <atcoder/all>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
//using namespace atcoder;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
}

lli gcd2(lli x, lli y)
{
    lli t;
    while (y != 0)
        t = x % y, x = y, y = t;
    return (x);
}

lli lcm2(lli x, lli y)
{
    lli xy = x * y;
    if (xy < 0)
        xy = -xy;
    return (xy / gcd2(x, y));
}
lli m = 1e9 + 7;
int main(void)
{
    char x, y;
    cin >> x >> y;
    if (x < y)
    {
        cout << "<" << endl;
    }
    else if (x > y)
    {
        cout << ">" << endl;
    }
    else
    {
        cout << "=" << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;
                                                          
template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

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

const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);                                
    int n, W;
    cin >> n >> W;
    vector<int> w(n + 1), c(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> c[i];
    }
    vector<vector<int>> dp(n + 1, vector<int>(1e5 + 1e2, INF32));
    for (int i = 0; i <= n; i++)
        dp[i][0] = 0;
    for (int i = 1; i <= n; i++) 
        for (int j = 1; j <= 1e5; j++) {
            dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if (j - c[i] >= 0)
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - c[i]] + w[i]);
        }
    for (int j = 1e5; ~j; j--)
        if (dp[n][j] <= W)
            cout << j, exit(0);   
    return false;                                                       
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  string s;

  cin>>s;

  if(s.length()!=2){
    reverse(s.begin(),s.end());
  }
  
  cout<<s<<endl;

  return 0;

}


Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
l = list(map(int,input().split()))
l.sort()

ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        ans += bisect_left(l,l[i]+l[j])-j-1

print(ans)

Measured memory_bytes: 3188
#include<stdio.h>

int main(){
  int i,n,A[10001],q,key,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(linearSearch(A,n,key)!=n)sum++;
  }
  printf("%d\n",sum);
  return 0;
}

int linearSearch(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key)i++;
  if(i==n)return n;
  else return i;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std ;
const int N = 2e5 + 10 ;
typedef long long ll ;
pair<ll , ll> a[N] ;
ll c[N] ;
ll dp[32] ;
bool cmp(pair<ll , ll> a , pair<ll , ll> b)
{
  return a.first * (b.second + 1) > b.first * (a.second + 1) ;
}
int main()
{
  ll n , t ;
  scanf("%lld%lld" , &n , &t) ;
  ll cnt1 = 0 , cnt2 = 0 ;
  for(ll i = 1 , x , y ; i <= n ;i ++)
   {
     scanf("%lld%lld" , &x , &y) ;
     if(x == 0) c[++ cnt2] = y + 1;
     else a[++ cnt1] = {x , y} ;
   }
   sort(c + 1 , c + cnt2 + 1) ;
   sort(a + 1 , a + cnt1 + 1 , cmp) ;
   for(int i = 1; i <= 30 ;i ++) dp[i] = t + 1 ;
   dp[0] = 0 ;
   for(int i = 1; i <= cnt1 ;i ++)
   {
     for(int j = 30 ;j >= 1 ;j --)
      dp[j] = min(dp[j] , (dp[j - 1] + 1) * (a[i].first + 1)+ a[i].second) ;
   }
   int cnt = 0 ;
   for(int i = 1; i <= cnt2 ;i ++) c[i] += c[i - 1] ;
   int ans = 0 ;
   for(int i = 0 ;i <= 30 ;i ++)
    {
      if(dp[i] > t) continue ;
      int j = 0 ;
      if(cnt2)
       j = upper_bound(c + 1 , c + cnt2 + 1 , t - dp[i]) - c - 1;
      ans = max(ans , i + j) ;
    }
  cout << ans << endl ;
  return 0 ;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
    {
    	cin.tie(0);
        ios::sync_with_stdio(0);
        string s,S;cin>>s;
    	for (int i = 0; i <s.size() ; ++i)
    	{
    		if(i%2==0){
    			S+=s[i];
    		}
    	}
        cout<<S;
    	return 0;
    }


Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
long long h,w;
char s[1000][1000];
long long mem[1000][1000];
long long mod=1000000007;
long long dp(long long i,long long j)
{
    if(i==-1||j==-1||i==h||j==w)
        return 0;

    if(s[i][j]=='#')
            return 0;
    if(mem[i][j]!=-1)
        return mem[i][j];
    if(i==h-1&&j==w-1)
        return 1;

    mem[i][j]=(dp(i+1,j)%mod+dp(i,j+1)%mod)%mod;

    return mem[i][j];
}
int main()
{
    memset(mem,-1,sizeof(mem));
    cin>>h>>w;
    long long i,j;
    for(i=0;i<h;i++)
        for(j=0;j<w;j++)
        cin>>s[i][j];
    cout<<dp(0,0);
    return 0;
}


Measured memory_bytes: 9088
package main

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

func main() {
	N, M, C := ReadInt(), ReadInt(), ReadInt()
	B := ReadInts(M)
	ans := 0
	for i := 0; i < N; i++ {
		A := ReadInts(M)
		sum := C
		for j, aij := range A {
			sum += aij * B[j]
		}
		if sum > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1848
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n, q;
        int com, x, y;
        UnionFind uf;

        n = sc.nextInt();
        q = sc.nextInt();

        uf = new UnionFind(n);

        for (int i = 0; i < q; i++) {
            com = sc.nextInt();
            x = sc.nextInt();
            y = sc.nextInt();

            if (com == 0) {
                uf.unite(x, y);
            }
            else {
                if (uf.isSameGroup(x, y)) {
                    System.out.println('1');
                }
                else {
                    System.out.println('0');
                }
            }
        }
    }
}

/**
 * 素集合データ構造.<br>
 * 各操作O(a(n))程度(a() はアッカーマン関数の逆関数)
 * @see <a href="https://abc097.contest.atcoder.jp/submissions/5437889">検証</a>
 */
class UnionFind {

    /**
     * 添字の示すノードの親.<br>
     * 親がない = 自身が根のとき、-1 * (集合の大きさ)をもつ
     */
    int[] parent;

    /**
     * 木の大きさ.<br>
     * あまり速くならなかった<br>
     * 計算量は O(log n) から O(a(n))くらいまで落ちるはずなのに
     */
    int[] rank;

    /** nmemb個の要素からなる UnionFind */
    public UnionFind(int nmemb) {
        parent = new int[nmemb];
        rank = new int[nmemb];
        
        Arrays.fill(parent, -1);
        Arrays.fill(rank, 0);
    }

    /**
     * 根を求める
     * @param x 根を求めるノードの番号
     */
    protected int root(int x) {
        if (parent[x] < 0) {
            return x;
        }
        
        parent[x] = root(parent[x]);
        return parent[x];
    }

    /** ノードx, yが同じ集合であるかを確かめる */
    public boolean isSameGroup(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * ノードx, y を併合.
     * x, yがすでに同じ集合にあるときは何もしない
     */
    public void unite(int x, int y) {

        x = root(x);
        y = root(y);

        if (x == y) {
            return;
        }

        //小さい木を大きい方へマージ(木の高さを抑えられるので)
        if (rank[x] > rank[y]) {
            parent[x] += parent[y];
            parent[y] = x;
        }
        else {
            parent[y] += parent[x];
            parent[x] = y;

            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        
        return;
    }

    /** グループの大きさ(=要素数)を調べる */
    public int groupSize(int x) {
        return -1 * parent[root(x)];
    }
}



Measured memory_bytes: 98684
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 

int main()
{
	int k;
	cin>>k;
	int cnt=1;
	if(k%2==0||k%5==0)puts("-1");
	else
	{
		int n=7%k;
		while(n)
		{
			n=(n*10+7)%k;
			cnt++;
		}
        cout<<cnt<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3640
import sys
import math
import itertools


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    K = [[] for _ in range(M)]

    for j in range(M):
        k = list(map(int, input().split()))
        K[j] = set(k[1:])
    P = list(map(int, input().split()))
    count = 0
    l = list(range(1, N + 1))
    for i in range(0, N + 1):
        for comb in itertools.combinations(l, i):
            flag =0
            for j in range(M):  # denkyu
                temp = set(comb)
                if len(temp.intersection(K[j]) )% 2 != P[j]:
                    flag = 1
                    break
            if flag ==0:
                count +=1
    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 73692
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll m,ll n){
  if(m%n==0)
    return n;
  else 
    return gcd(n,m%n);
}
int main() {
  ll a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  vl W(31,-1),S(3001,-1);
  ll GS=gcd(c,d);
  ll k;
  FOR(i,c*d,3001){
    if(i%GS==0){
      S[i]=1;
    }
  }
  rep(i,d){
    rep(j,c){
      k=c*i+j*d;
      if(k<c*d)
        S[k]=1;
    }
  }
  rep(i,31){
    rep(j,31){
      k=a*i+b*j;
      if(k<=30)
        W[k]=1;
    }
  }
  ll w=10000,s=0;
  FOR(i,1,f/100+1){
    if(W[i]==1){
      k=min(f-100*i,e*i);
      while(S[k]==-1){
        k--;
      }
      ll WA=100*i,SU=k;
      if(SU*w>WA*s){
        w=WA,s=SU;
      }
    }
  }
  if(s!=0){
    cout << w+s << " " << s << endl;
  }
  else
    cout << 100*a << " " << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,m;
	int hum[101];
	cin>>n>>m;
	int i,j;
	for(i=0;i<n;i++){
		cin>>hum[i];
	}
	for(i=2;i<=m;i++){
		for(j=0;j<n-1;j++){
			if((hum[j]%i)>(hum[j+1]%i)){
				swap(hum[j],hum[j+1]);
			}
		}
	}
	for(i=0;i<n;i++){
		cout<<hum[i]<<endl;
	}
	return 0;
}
				


Measured memory_bytes: 3096
from collections import deque
N,M = map(int,input().split())
G = {}
for i in range(1,N+1):
    L = list(map(int,input().split()))
    G[i] = [L[j]+10**5 for j in range(1,L[0]+1)]
    for j in range(1,L[0]+1):
        if L[j]+10**5 not in G:
            G[L[j]+10**5] = []
        G[L[j]+10**5].append(i)
hist = [0 for _ in range(2*10**5+1)]
hist[1] = 1
que = deque([1])
while que:
    x = que.popleft()
    for y in G[x]:
        if hist[y]==0:
            que.append(y)
            hist[y] = 1
flag = 1
for i in range(1,N+1):
    if hist[i]==0:
        flag = 0
        break
if flag==1:
    print("YES")
else:
    print("NO")
        

Measured memory_bytes: 94956
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import java.util.regex.Matcher;


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

		// 1行、2つ(複数)数字
		String[] ss0 = br.readLine().trim().split(" ", 0);
		int N = Integer.parseInt(ss0[0]);
		int T = Integer.parseInt(ss0[1]);

		// 1行目個数、2行目以降文字列を配列に格納
		ss0 = br.readLine().trim().split(" ", 0);
		Integer[] ii0 = new Integer[N];
		for(int i = 0; i < N; i++){
			ii0[i] = Integer.parseInt(ss0[i]);
		}


		int iCount = 0;
		int iSa = 0;
		int iN = 0;
		boolean b = true;
		for(int i = 1; i < N; i++){
			//差がより大きいなら、
			if ( (ii0[i] - ii0[iN]) > iSa){
				iSa = ii0[i] - ii0[iN];
				iCount = 1;
				continue;
			}
			
			//差が同じなら、カウントを増やす
			if ( (ii0[i] - ii0[iN]) == iSa){
				if (b) {
					iCount = iCount + 1;
					b = false;
				}
				continue;
			}
			
			//最小値が小さくなったら、位置情報を変える
			if (ii0[iN] > ii0[i]) {
				iN = i;
				b = true;
				continue;
			}

		}
		
		
		System.out.println(iCount);
		
		
    }
    // Debug.Print
    static void dp(String s) {
		System.out.println(s);
	}
    static void dp(StringBuilder s) { dp(s.toString()); }
    static void dp(int i) { dp(String.valueOf(i)); }
    static void dp(long i) { dp(String.valueOf(i)); }

}


Measured memory_bytes: 33676
#include <iostream>
using namespace std;
bool is_prime[247000];

void sieve() {
  for(int i=0;i<247000;i++) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for(int i=2;i*i<247000;i++) {
    if(is_prime[i]) {
      for(int j=2*i;j<247000;j+=i) {
        is_prime[j] = false;
      }
    }
  }

}

int main() {
  int n;
  sieve();
  while(cin >> n) {
    if(n==0) break;
    int ans = 0;
    for(int i=1;i<=n;i++) {
      if(is_prime[n+i]) ans++;
    }
    cout << ans << endl;
  }
}

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

int main(){
    int H,W;

    while(1){
        cin >> H >> W ;
        if(H == 0 && W == 0){
            break;
        }else{
            for(int i=0;i<H;i++){
                //一番上の列にW個＃を書いた。
                for(int k=0;k<W;k++){
                    cout << "#" ;
                }
                cout << endl;
    
            }

        }
        cout << endl;
    }
    
    return 0;

}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a,b;
  int count = 0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    int j=i;
    int s=0;
    while(j>0){
      s += j%10;
      j /= 10;
    }
    if(a <= s && s <= b){
      count += i;
    }
  }
  cout << count <<endl;
}
      
      

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

string S;
bool mjudge1, yjudge1, mjudge2, yjudge2;

int main() {
    cin >> S;
    string s1 = S.substr(0, 2);
    string s2 = S.substr(2, 2);
    if(stoi(s1) >= 1 && stoi(s1) <= 12) mjudge1 = true;
    if(stoi(s2) >= 1 && stoi(s2) <= 12) mjudge2 = true;
    if(mjudge2 && mjudge1) {
        cout << "AMBIGUOUS"
             << "\n";
    } else if(mjudge2 && !mjudge1) {
        cout << "YYMM"
             << "\n";
    } else if(!mjudge2 && mjudge1) {
        cout << "MMYY"
             << "\n";
    } else if(!mjudge2 && !mjudge1) {
        cout << "NA"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

#define PII pair<int,int>
#define LLI long long int

using namespace std;

int main(){
	int N;cin>>N;
	vector<int>B(N);
	for(int i=0;i<N-1;i++)cin>>B[i];
	vector<int>A(N);
	A[0]=B[0];
	B[N-1]=10000000;
	for(int i=1;i<N;i++){
		A[i]=min(B[i-1],B[i]);
	}
	int ans=0;
	for(int i=0;i<N;i++)ans+=A[i];
	cout<<ans<<endl;
	return 0;
}



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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

i64 mod_pow(i64 x, i64 y, i64 mod){
    i64 res=1;
    while(y){
        if(y&1) res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}

void solve(){
    i64 S;
    cin >> S;

    i64 mod=1000000007,ans=0,r=1,ld=0,rd=1,nl=1,nr=10,sum=1;
    rep(l,1,100000000){
        sum-=ld;
        if(l==nl){
            nl*=10;
            ++ld;
        }
        while(sum<S){
            ++r;
            if(r==nr){
                nr*=10;
                ++rd;
            }
            sum+=rd;
        }
        if(sum==S) ++ans;
    }

    rep(d,1,S+1){
        if(S/d<=8) continue;
        if(S%d==0){
            i64 tmp=(9*mod_pow(10,S/d-1,mod)-d+1+mod)%mod;
            ans+=tmp;
            ans%=mod;
        }else{
            ++ans;
            ans%=mod;
        }
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	int a,b,d,r;
	double f;
	cin>>a>>b;
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;
	cout<<d<<' '<<r<<' ';
	printf("%f",f);
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1228
#include<stdio.h>
#include<math.h>
int main ()
{
    int a,b,c,d=0,e=0;
    scanf ("%d %d %d",&a,&b,&c);
    if (a>=1&&a<=100&&b>=1&&b<=100&&c>=1&&c<=100)
    {
        d=(a+b+c)/2;
        e=sqrt((d-a)*(d-b)*(d-c)*d);
        printf ("%d\n",e);
    }
    return 0;
}



Measured memory_bytes: 2120
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int A, B, C;
  while (cin >> A >> B >> C) {
    bool res = false;
    res |= (A == B) && (A != C);
    res |= (A == C) && (A != B);
    res |= (B == C) && (A != B);
    cout << (res ? "Yes" : "No") << endl;
  }
  return 0;
}


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

int num=0;
bool data[10]={};

int fac(int n){
	if(n==1)return 1;
	return n*fac(n-1);
}

int func(int n,int s){
	if(s<0 || n<0){
		return 0;
	}
	if(s==0){
		if(n==0){return 1;}
		else if(n>=2){return 0;}
	}
	if(n==1){
		for(int j=0;j<10;j++){
			if(s==j && data[j]==0){
				return 1;
			}
		}
	}
	for(int i=0;i<10;i++){
		if(data[i]==0){
			data[i]=1;
			num+=func(n-1,s-i);
			data[i]=0;
		}
	}
	int nn=num;
	num=0;
	return nn;
}

int main(){
	int n,s;
	while(1){
		cin>>n>>s;
		if(n==0 && s==0)break;
		num=0;
		cout<<func(n,s)/fac(n)<<endl;
	}
	return 0;
}

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

int main( int argc, char *argv[] )
{
const int iMod = 1000000007;
int i;
int j;
int N;
int M;
int *X;
int *Y;
long long iVal;
long long iSum;
long long iH;
long long iW;

	// 入力
	cin >> N;
	cin >> M;

	// メモリ確保
	X = new int[ N + 5 ];
	Y = new int[ M + 5 ];

	// 入力
	for( i = 0; i < N; i++ )
	{
		cin >> X[ i ];
	}

	for( i = 0; i < M; i++ )
	{
		cin >> Y[ i ];
	}

	// 算出
	iSum = 0;
	iW = 0;
	for( i = 1; i < N; i++ )
	{
		iVal = X[ i ] - X[ i - 1 ];
		iVal %= iMod;
		iVal *= i;
		iVal %= iMod;
		iVal *= N - i;
		iVal %= iMod;
		iW += iVal;
		iW %= iMod;
	}

	for( j = 1; j < M; j++ )
	{
		iH = Y[ j ] - Y[ j - 1 ];
		iH %= iMod;
		iVal = iW * iH;
		iVal %= iMod;
		iVal *= j;
		iVal %= iMod;
		iVal *= M - j;
		iVal %= iMod;

		iSum += iVal;
		iSum %= iMod;
	}

	// 出力
	cout << iSum << endl;

	return 0;
}





Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>

using namespace std;

int main()
{
    int r,d,x;
    cin>>r>>d>>x;
    for(int i=0;i<10;i++)
    {
        static int x_new=x;
        x_new=(r*x_new)-d;
        cout<<x_new<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(0,n)[::-1]:
  if a[i+1]+a[i]<=b[i]:
    ans+=a[i+1]+a[i]
    a[i+1]=0;a[i]=0
  elif a[i+1]<=b[i]<a[i]+a[i+1]:
    ans+=b[i]
    a[i]-=(b[i]-a[i+1]);a[i+1]=0
  elif a[i+1]>b[i]:
    ans+=b[i]
    a[i+1]-=b[i]
print(ans)


Measured memory_bytes: 18476
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
const int N=200007;
int n;
struct P {
	int x,y;
	bool operator < (const P &_) const {
		return y<_.y;
	}
}A[N];
int main() {
	scanf("%d",&n);
	For(i,1,n) scanf("%d%d",&A[i].x,&A[i].y);
	sort(A+1,A+1+n);
	long long s=0;
	For(i,1,n) {
		s+=A[i].x;
		if(s>A[i].y) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	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 Na = sc.nextInt();
    int Nb = sc.nextInt();
    int Nc = sc.nextInt();
    int Nd = sc.nextInt();
    int Ne = sc.nextInt();
    
    int count = 0;
    int[] N1 = new int[5];
    N1[0] = Na%10;
    N1[1] = Nb%10;
    N1[2] = Nc%10;
    N1[3] = Nd%10;
    N1[4] = Ne%10;
    
    int sum = Na-N1[0]+Nb-N1[1]+Nc-N1[2]+Nd-N1[3]+Ne-N1[4]+40;
    
    Arrays.sort(N1);
    int min = 0;
    for(int i = 0; i<5;i++)
    {
    	if(N1[i] == 0) count++;
      	else 
        {
          min = N1[i];
          break;
        }
    }
    if(count == 5) count = 4;
   	System.out.println(sum - 10 * count +min);
 }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
inline ll Pow(ll A, ll B, ll M) { ll Y = 1; while (B > 0) { if (B & 1)Y = Y * A % M; A = A * A % M; B >>= 1; }return Y; }

ll M = 1;

int Process() {
  if (M % 2 == 0)
    return -1;
  int ans = 1;
  ll n = 7 % M, expo = 1;
  vector<bool> vis(M, 0);
  while (n) {
    n = (n + (7 * Pow(10, expo, M))) % M;
    ans++;
    expo++;
    if (vis[n])
      return -1;
    vis[n] = 1;
  }
  return ans;
}

void Output() { cout << Process() << "\n"; }

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

  while (cin >> M)
    Output();

  return 0;
}

Measured memory_bytes: 3736
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = copy.deepcopy(A)
	tmp.sort()
	
	m1_p = (len(tmp) / 2) - 1
	m1 = tmp[int(m1_p)]
	m2_p = (len(tmp) / 2)
	m2 = tmp[int(m2_p)]
	
	ans = []
	for i, val in enumerate(A):
		if val <= m1:
			ans.append(m2)
		else:
			ans.append(m1)
			
	for i in ans:
		print(i)
			
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 35304
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = [0] * 200000
for i in range(M):
    a, b = map(int, input().split())
    A[a] = max([H[b-1], A[a]])
    A[b] = max([H[a-1], A[b]])
ans = 0
for i in range(N):
    if A[i+1] < H[i]:
        ans += 1
print(ans)

Measured memory_bytes: 84748
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll int
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=1e6+500;
const ll mod=1e9+7;

ll zarb(long long a,long long b){return (a*b)%mod;}

ll fac[maxn];
ll rfac[maxn];

ll poww(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1){
			ans=zarb(ans,a);
		}
		a=zarb(a,a);
		b>>=1;
	}
	return ans;
}

ll juy(ll n,ll k){
	if(k>n || k<0)return 0;
	return zarb(fac[n],rfac[n-k]);
}	

ll a[maxn];
ll b[maxn];
ll n,m;

ll findAns(ll x,ll y,ll c){
	ll ax=a[x]-c;
	ll by=b[y]-c;
	ll tolx=n-x;
	ll toly=m-y;
	ll s=tolx*toly;
	if(s==0)return 1;
	if(ax==by){
		return  zarb(findAns(x+1,y+1,c+tolx+toly-1),juy(ax-1,tolx+toly-2));
	}
	if(ax<by){
		return  zarb(zarb(findAns(x+1,y,c+toly),juy(ax-1,toly-1)),toly);
	}
	if(ax>by){
		return  zarb(zarb(findAns(x,y+1,c+tolx),juy(by-1,tolx-1)),tolx);
	}
}
int main(){
	fac[0]=1;
	for(ll i=1;i<maxn;i++){
		fac[i]=zarb(fac[i-1],i);
	}
	for(ll i=0;i<maxn;i++){
		rfac[i]=poww(fac[i],mod-2);
	}

	cin>>n>>m;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	for(ll i=0;i<m;i++){
		cin>>b[i];
	}
	sort(a,a+n);
	sort(b,b+m);
	for(ll i=0;i+1<n;i++){
		if(a[i]==a[i+1]){
			cout<<0;
			return 0;
		}
	}
	for(ll i=0;i+1<m;i++){
		if(b[i]==b[i+1]){
			cout<<0;
			return 0;
		}
	}

	cout<<findAns(0,0,0);
}




















Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) (v.begin(),v.end())
#define vi vector<int>
int ans = 0;
vi xa = {0,-1,1,0};
vi ya = {1,0,0,-1};
int h,w;
vector<vector<char>> s;
 
 
void dfs(int x,int y){
    vector<vector<bool>> vis(h,vector<bool>(w));
    queue<pair<int,pair<int,int>>> q;
    q.push({0,{x,y}});
    while(!q.empty()){
        x = q.front().second.first;
        y = q.front().second.second;
        int dist = q.front().first;
        vis[x][y] = true;
        q.pop();
        for(int i = 0;i < 4; ++i){
            int nx = x + xa[i];
            int ny = y + ya[i];
            if((nx < h) && (ny < w) && (nx >= 0 && ny >= 0) && (!vis[nx][ny]) && (s[nx][ny] != '#')){
                q.push({dist + 1,{nx,ny}});
				vis[nx][ny] = true;
                ans = max(ans,dist + 1);
            }
        }
    }
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin >> h >> w;
    s.resize(h,vector<char>(w));
    ffor(i,h){
        ffor(j,w){
            cin >> s[i][j];
        }
    }
 
    for(int i = 0;i < h;++i){
        for(int j = 0;j < w; ++j){
            if(s[i][j] == '#') continue;
            dfs(i,j);
        }
    }
 
    cout << ans;
}


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

int n,k;
vector<int> l;
vector<int> r;
int ans = 1;

void input(){
    cin >> n >> k;
}

void solve(){
    rep(i,n){
        if (ans+k <= ans*2){
            ans += k;
        } else {
            ans *= 2;
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;

const int M = 1e3;
int n, m, arr[M], cost[M], memo[M][4096], big = 5e8;

int solve(int i, int taken) {
    if (i == m)
        if (taken ^ ((1 << n) - 1))
            return big;
        else
            return 0;

    int &r = memo[i][taken];

    if (r == -1)
        r = min(solve(i + 1, taken), cost[i] + solve(i + 1, taken | arr[i]));
    return r;
}

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

    memset(memo, -1, sizeof memo);
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        int x;
        cin >> cost[i] >> x;

        while (x--) {
            int tmp;
            cin >> tmp;
            tmp--;
            arr[i] |= (1 << tmp);
        }
    }

    cout << (solve(0, 0) == big ? -1 : solve(0, 0)) << '\n';

    return 0;
}

Measured memory_bytes: 16256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[][] map = new int[n][n];
			
			map[n/2+1][n/2] = 1;
			int y = n/2+1;
			int x = n/2;
			for(int i=2;i<=n*n;i++){
				x++;
				y++;
				while(true){
					if(x==n)x=0;
					if(x==-1)x=n-1;
					if(y==n)y=0;
					if(map[y][x]!=0){
						x--;
						y++;
					}else{
						break;
					}
				}
				map[y][x] = i;
			}
			
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					System.out.printf("%4d", map[i][j]);
				}
				System.out.println();
			}
				
		}
	}	
}

Measured memory_bytes: 20076
def main():
    target = input()
    string = ["eraser", "dreamer", "erase", "dream"]
    for i in range(len(target)):
        for s in string:
            if target[-len(s):] == s:
                target = target[:-len(s)]
        if target == "":
            break
    print("YES" if target == "" else "NO")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3188