akhauriyash/Code-Regression huggingface dataset:
N, A, B = map(int, input().split())
h_list = [int(input()) for _ in range(N)]
h_max = max(h_list)


def add_attack(t):
    attack = B * t
    for i in range(N):
        h = h_list[i]
        h -= attack
        if h > 0:
            t -= (h + (A - B) - 1) // (A - B)
            if t < 0:
                return False
    return True


t_min = 1
t_max = (h_max + B - 1) // B

while t_min < t_max - 1:
    t_mid = (t_min + t_max) // 2
    if add_attack(t_mid):
        t_max = t_mid
    else:
        t_min = t_mid
print(t_max)


Measured memory_bytes: 7072
/**/
#include<bits/stdc++.h>
using namespace std;
char a[100001];
int main(){
	ios::sync_with_stdio(false);
	gets(a);
	int len=strlen(a);
	for(int i=0;i<len;i++){
		if(!(a[i]=='p'&&a[len-i-1]=='q'||a[i]=='q'&&a[len-i-1]=='p'||a[i]=='b'&&a[len-i-1]=='d'||a[i]=='d'&&a[len-i-1]=='b')){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int n, d; 
    cin >> n >> d;
    int ans = 0;
    if (n%(2*d+1) == 0) ans = n / (2*d+1);
    else ans = n/(2*d+1) + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define int ll

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

const int N = 1e5 + 20, inf = 3e18 + 20;
int n, m;
vector <pii> g[N];

int dist[N];

int32_t main()
{
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> m;

	for (int i = 0; i < n - 1; i++)
		g[i + 1].pb({i, 0});

	for (int i = 0, l, r, c; i < m; i++)
	{
		cin >> l >> r >> c;
		l--, r--;
	
		g[l].pb({r, c});
	}
	
	set <pii> st;
	for (int i = 0; i < n; i++) dist[i] = inf;
	
	dist[0] = 0;
	st.insert({0, 0});

	while (_sz(st))
	{
		int v = st.begin() -> S;
		st.erase(st.begin());

		for (pii p : g[v])
		{
			int u = p.F, w = p.S;

			if (dist[v] + w < dist[u])
			{
				st.erase({dist[u], u});
				dist[u] = dist[v] + w;
				st.insert({dist[u], u});
			}
		}
	}

	if (dist[n - 1] == inf) dist[n - 1] = -1;

	cout << dist[n - 1] << '\n';
}


Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    int h,w;
    cin >> h >> w;
    vector<string> v(h);
    rep(i,h) cin >> v[i];
    vector<string> ans(h);
    ans = v;
    auto isbomb = [&](int i,int j) {
        if(i < 0 || i >= h || j < 0 || j >= w) return false;
        return v[i][j] == '#';
    };
    auto cnt = [&](int i,int j) {
        int ret = 0;
        rep2(m,i-1,i+2) rep2(n,j-1,j+2) {
            if(isbomb(m,n)) ret++;
        }
        return ret;
    };
    rep(i,h) rep(j,w) {
        if(v[i][j] == '#') continue;
        ans[i][j] = '0'+cnt(i,j);
    }
    rep(i,h) cout << ans[i] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main() {
	/*int N, A, B;
	cin >> N >> A >> B;
	cout << min(N * A, B);*/

	int N, D;
	cin >> N >> D;
	int x[15][15];
	int ans = 0;
	rep(i, N)rep(j, D)cin >> x[i + 1][j + 1];
	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j <= N; j++) {
			double d = 0;
			for (int k = 1; k <= D; k++) {
				d += pow(x[i][k] - x[j][k], 2);
			}
			d = sqrt(d);
			if (d == floor(d))ans++;
		}
	}
	cout << ans;
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

#define NUM 5

int main(void){

	ll N; cin >> N;
	vector<ll> A(NUM);

	REP(i,NUM) cin >> A[i];

	ll min_value = A[0];
	REP(i,NUM){
		min_value = min(A[i], min_value);
	}

	ll ans = (N + min_value - 1) / min_value;
	ans += 4;
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  	long long n;
  cin >> n;
  long long t = 100,dem = 0;
  while(t < n)
  {
    t += (t/100);
    dem ++;
  }
  cout << dem;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
  int x,y,z;
  cin >> x >> y >> z;
    for(int i=0; ; i++){
    if(x < z * (i+1) + y * i){
      cout << i - 1 << endl;
      return 0;
    }
    }
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>

typedef long long ll;
using namespace std;
int main()
{
    int n;
    cin>>n;
    int k=n/100;
    n=n%100;
    int c=n/10;
    int f=n%10;
    if(k==7||c==7||f==7)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }

    return 0;
}



Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;
            string[] str = Console.ReadLine().Split(' ');
            a = int.Parse(str[0]);
            b = int.Parse(str[1]);
            c = int.Parse(str[2]);
            if (a + b + c <=21)
                Console.WriteLine("win");
            if (a+b+c>=22)
                Console.WriteLine("bust");
            Console.ReadKey();

        }
    }
}



Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
template <class Key, class Compare = less<Key>> // find_by_order, order_of_key (for multiset: pair(val, time of insertion))
using Tree = tree<Key, null_type, Compare, rb_tree_tag, tree_order_statistics_node_update>;






void Solution() {
  ll n;
  ll a[200005];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(a, a+n);
  ll b1 = a[n/2], b2 = b1, ans1 = 0, ans2 = 0, ans3 = 0;
  if (n % 2 == 1) {
    b2 = a[n/2+1];
  }
  for (int i = 0;i < n; ++i) {
    ans1 += abs(a[i] - b1);
    ans2 += abs(a[i] - b2);
    ans3 += abs(a[i] - 0);
  }
  ll ans = min({ans1, ans2, ans3});
  cout << ans;
}


int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  #ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  #endif
  Solution();
}


Measured memory_bytes: 1792
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int n,p;
    cin>>n>>p;
    int ans=1;
    for(int i=2;i*i<=p;i++)
    {
        int ctr=0;
        while(p%i==0)
            p/=i,ctr++;
        for(int j=0;j<ctr/n;j++)
            ans*=i;
    }
    if(p!=1 && n==1)
        ans*=p;
    cout<<ans;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 998244353;

struct Edge{
  ll dst;
  Edge(ll t):dst(t){}
};

using Edges=vector<Edge>;
using Graph=vector<Edges>;

vector<vector<int>> SCC(const Graph& g,vector<int> &I) {
    ll n=g.size();
    vector<vector<int>> scc;
    vector<int> S, B;
    I.assign(n,0);
    function<void(int)> dfs = [&](int u) {
        B.push_back(I[u] = S.size());
        S.push_back(u);
        for(Edge e: g[u]) {
            int v=e.dst;
            if (!I[v]) dfs(v);
            else while (I[v] < B.back()) B.pop_back();
        }
        if (I[u] == B.back()) {
            scc.push_back({});
            B.pop_back();
            for (; I[u] < (int)S.size(); S.pop_back()) {
                scc.back().push_back(S.back());
                I[S.back()] = n + scc.size();
            }
        }
    };
    for(int u=0;u<n;u++)if (!I[u]) dfs(u);
    for(int u=0;u<n;u++)I[u] -= n+1;
    return scc;
}
Graph g;
void add(ll v,ll a,ll b,ll k=1,ll l=0,ll r=1<<16){
  if(a>=b)return;
  if(r<=a||b<=l)return;
  if(a<=l&&r<=b){
    g[v].emplace_back(k);
  }else{
    add(v,a,b,(k<<1)|0,l,(l+r)/2);
    add(v,a,b,(k<<1)|1,(l+r)/2,r);
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  vll x(N),y(N);
  vector<tuple<ll,ll>> id(N);
  vector<tuple<ll,ll> > V;
  for(ll i=0;i<N;i++){
    cin>>x[i]>>y[i];
    if(x[i]>y[i])swap(x[i],y[i]);
    V.emplace_back(x[i],i);
    V.emplace_back(y[i],i+(1<<14));
  }
  sort(V.begin(),V.end());
  for(ll i=0;i<N;i++){
    ll f=lower_bound(V.begin(),V.end(),make_tuple(x[i],i))-V.begin();
    ll s=lower_bound(V.begin(),V.end(),make_tuple(y[i],i+(1<<14)))-V.begin();
    id[i]=make_tuple(f,s);
  }
  ll A=1<<16,B=1<<15;
  ll low=0,high=1e9;
  while(high-low>1){
    ll mid=(high+low)/2;
    mid--;
    g.clear();
    g.resize(1<<17);
    for(ll i=2;i<1<<16;i++){
      g[i].emplace_back((i<<1)|0);
      g[i].emplace_back((i<<1)|1);
    }
    for(ll i=0;i<N;i++){
      g[A+B+get<0>(id[i])].push_back(A+get<1>(id[i]));
      g[A+B+get<1>(id[i])].push_back(A+get<0>(id[i]));
      ll a=lower_bound(V.begin(),V.end(),make_tuple(x[i]-mid,0))-V.begin();
      ll b=lower_bound(V.begin(),V.end(),make_tuple(x[i]+mid+1,0))-V.begin();
      add(A+get<0>(id[i]),a+B,get<0>(id[i])+B);
      add(A+get<0>(id[i]),get<0>(id[i])+1+B,b+B);
      a=lower_bound(V.begin(),V.end(),make_tuple(y[i]-mid,0))-V.begin();
      b=lower_bound(V.begin(),V.end(),make_tuple(y[i]+mid+1,0))-V.begin();
      add(A+get<1>(id[i]),a+B,get<1>(id[i])+B);
      add(A+get<1>(id[i]),get<1>(id[i])+1+B,b+B);
    }
    vector<int> idx;
    vector<vector<int>>scc=SCC(g,idx);
    bool isok=true;
    for(ll i=0;i<N*2;i++){
      isok &= idx[i+A]!=idx[i+A+B];
    }
    mid++;
    if(isok){
      low=mid;
    }else{
      high=mid;
    }
  }
  cout<<low<<endl;

  return 0;
}


Measured memory_bytes: 25516
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;

int main()
{
	in>>S;
	rep(i,S.length())
	{
		if(i%2==0){out<<S[i];}
	}
	out<<std::endl;
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cioacc();
  int n;
  cin >> n;
  bool ans = true;
  REP(i,n){
    int t,x,y;
    cin >> t >> x >> y;
    x += y;
    if(t<x||t%2!=x%2) ans = false;
  }
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
const int maxm=1e5+5;
char s[maxm];
int a[maxm];
int n;
signed main(){
    scanf("%s",s+1);
    n=strlen(s+1);
    int last=-1;
    for(int i=1;i<=n;i++){
        if(s[i]=='R')last=i;
        else{
            int t=(i-last)%2;
            if(t%2==0){
                a[last]++;
            }else{
                a[last+1]++;
            }
        }
    }
    last=-1;
    for(int i=n;i>=1;i--){
        if(s[i]=='L')last=i;
        else{
            int t=(last-i)%2;
            if(t%2==0){
                a[last]++;
            }else{
                a[last-1]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<' ';
    }
    return 0;
}
/*

*/


Measured memory_bytes: 4516
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll a;//, b,c;
    string S;
    //cin >> S;
    cin >> a;//>>b>>c;
    
    cout << 48 - a  << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

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

	int x = n * 800;
	int y = n / 15 * 200;

	cout << x - y << endl;

	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;

int main() {
    long double a, b, h, m;
    cin >> a >> b >> h >> m;
    long double p = M_PI;
    cout << fixed << setprecision(20)
         << sqrtl(a * a + b * b -
                  2 * a * b * cosl(2 * p * abs(m / 60 - h / 12 - m / 720)))
         << endl;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

vector<ll> G[100001];

signed main() {
	ll n, k, a, b;

	cin >> n >> k;

	REP(i, n - 1) {
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}

	ll start;

	REP(i, n) {
		if (G[i].size() == 1) {
			start = i;
			break;
		}
	}

	ll ans = k;

	queue<ll> q;
	q.push(start);

	vector<bool> used(n, false);
	used[start] = true;

	vector<pair<ll, ll>> col(n, make_pair(0, 0));
	col[start] = make_pair(0, 1);

	while (!q.empty()) {
		ll now = q.front();
		q.pop();
		REP(j, G[now].size()) {
			ll next = G[now][j];
			if (used[next]) {
				continue;
			}
			used[next] = true;
			ans *= k - col[now].first - col[now].second;
			ans %= MOD;
			col[next].first = col[now].second;
			col[next].second++;
			col[now].first++;
			q.push(next);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 8948
from collections import Counter
c = Counter()
for i in range(3):
    a,b = map(int, input().split())
    c[a] += 1
    c[b] += 1
if list(map(lambda x: x[1], c.most_common())) == [2,2,1,1]:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3444
n = int(input()) #問題数
t = list(map(int, input().split())) #問題
m = int(input()) #ドリンク数
p = [list(map(int, input().split())) for i in range(m)]

for i in range(m):
    sum = 0
    for j in range (n):
        if p[i][0] == j+1:
            sum += p[i][1]
        else:
            sum += t[j]
    print(int(sum))

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

int main(void) {
	int N;
	double Y;
	cin >> N >> Y;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N-i; j++) {
			for (int k = 0; k <= N-j-i; k++) {
				if (Y == 10000 * i + 5000 * j + 1000 * k && N==i+j+k) {
					cout << i << ' ' << j << ' ' << k << endl;
					return 0;
				}
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,m = map(int, input().split())
    res = []
    kisuu = n
    guusuu = n//2
    for i in range(1, m+1):
        if i%2 == 1:
            res.append([(kisuu+i)%n, kisuu])
            kisuu -= 1
        else:
            res.append([guusuu, guusuu+i])
            guusuu -= 1
    for a,b in res:
        print(a,b)


if __name__ == '__main__':
    main()

Measured memory_bytes: 22764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    int b=0,w=0;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='0'){
                b++;
            }
            if(s[i]=='1'){
                w++;
            }
        }else{
            if(s[i]=='0'){
                w++;
            }
            if(s[i]=='1'){
                b++;
            }
        }
    }
    cout<<min(b,w)<<endl;
    return 0;
}


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

struct task{
  int cost;
  int deadline;
};

int main(){
  int N;
  cin >> N;
  vector<task> tasks(N);
  for(int i=0; i<N; i++) cin >> tasks[i].cost >> tasks[i].deadline;
  sort(tasks.begin(), tasks.end(), [](const task& x, const task& y) { return x.deadline < y.deadline;});
  int now_time = 0;
  for(int i=0; i<N; i++){
    now_time += tasks[i].cost;
    if(now_time > tasks[i].deadline){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 1792
#
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

# Calculate count of combination
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b


def main():
    mod = 10 ** 9 + 7
    n, k = map(int, input().split())
    for i in range(1, k + 1):
        ans = combination(n - k + 1, i) * combination(k - 1, i - 1) % mod
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47324
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;

Int n, k;
vector<int> p, q;
vector<int> P, Q;

vector<int> permutate(vector<int> a, vector<int> b){
    int n = a.size();
    vector<int> res(n);
    for(int i = 0;i < n;i++){
        res[i] = b[a[i]];
    }
    return res;
}

vector<int> inverse(vector<int> a){
    int n = a.size();
    vector<int> res(n);
    for(int i = 0;i < n;i++){
        res[a[i]] = i;
    }
    return res;
}

vector<int> f(vector<int> a, vector<int> b){
    return permutate(inverse(a), b);
}

vector<int> id;

vector<int> power(vector<int> f, int x){
    vector<int> res = id;
    vector<int> tmp = f;
    for(int i = 0;i <= 30;i++){
        if((x >> i) % 2 == 1){
            res = permutate(res, tmp);
        }
        tmp = permutate(tmp, tmp);
    }
    return res;
}

void show(vector<int> a){

        for(int i = 0;i < n;i++){
            cout << a[i] + 1 << " ";
        }cout << endl;
}

int main(){
    cin >> n >> k;
    P.resize(n);
    Q.resize(n);
    for(int i = 0;i < n;i++)id.push_back(i);
    for(int i = 0;i < n;i++){cin >> P[i];P[i]--;}
    for(int i = 0;i < n;i++){cin >> Q[i];Q[i]--;}
    p = inverse(P);
    q = inverse(Q);

    vector<int> l = permutate(permutate(q, P), permutate(Q, p));
    vector<int> r = permutate(permutate(P, q), permutate(p, Q));

    vector<int> a = P;
    vector<int> b = Q;

    int ind = 1;
    while(ind < k && ind < 7){
        a = f(a, b);
        swap(a, b);
        ind++;
    }
    while((k - ind) % 6 != 0){
        a = f(a, b);
        swap(a, b);
        ind++;
    }
    if(k == ind){
        show(a);
        return 0;
    }
    a = permutate(power(l, (k-ind) / 6), a);
    a = permutate(a, power(r, (k-ind) / 6));
    show(a);
    return 0;
}

Measured memory_bytes: 7000
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		PrintStream out = null;
		try {
			sc = new Scanner(System.in);
			out = System.out;
			exec(sc, out);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			if(out != null) {
				out.close();
			}
			if(sc != null) {
				sc.close();
			}
		}
		System.exit(0);
	}
	public static void exec(final Scanner sc, final PrintStream out) throws Exception{
		final int N = sc.nextInt();
		final int Q = sc.nextInt();
		final int cnt[] = new int[N+1];
		final long link[] = new long[N*2-2];
		final int index[] = new int[N+2];
		final int val[] = new int[N+1];
		for(int i=0;i<N-1;i++) {
			final long a = sc.nextLong();
			final long b = sc.nextLong();
			link[i] =( a << 32 | b );
			link[i+(N-1)] =( b << 32 | a );
		}
		Arrays.sort(link);
		int head = 0;
		for(int i=0;i<link.length;i++) {
			final int src = (int)(link[i]>>32);
			if(src!=head) {
				head = src;
				index[head]=i;
			}
		}
		index[N+1]=link.length;
//		for(int i=0;i<link.length;i++) {
//			System.out.println(Long.toHexString(link[i]));
//		}
//		System.out.println(Arrays.toString(index));

		for(int i=0;i<Q;i++) {
			final int p = sc.nextInt();
			final int x = sc.nextInt();
			cnt[p]+=x;
		}
		search(val, cnt, link, index, 0, 1, 0);
//		out.println(Arrays.toString(cnt));
//		out.println(Arrays.toString(val));
//		out.println(Arrays.deepToString(link));
		out.print(val[1]);
		for(int i=2;i<val.length;i++) {
			out.print(" "+val[i]);
		}
		out.println();
	}
	public static void search(final int[] val, int[] cnt, long[] link, int[] index, int parent, int self, int sum) {
//		System.out.println(self);
		final int nextSum = sum + cnt[self];
		val[self] = nextSum;
		for(int i=index[self];i<index[self+1];i++) {
			final int next = (int)(link[i]&0xFFFFFFFF);
			if(parent!=next) {
				search(val, cnt, link, index, self, next, nextSum);
			}
		}
	}
}


Measured memory_bytes: 187616
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass


x = int(input())
d_l = divisor(x)

for d in d_l:
    for b in range(-1004,1004):
        if (b+d)**5 - b**5 == x:
            print(b+d,b)
            exit()
        if (b-d)**5 - b**5 == x:
            print(b-d,b)
            exit()

Measured memory_bytes: 68148
N = int(input())
S = input()

a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
dic = {a[i]:i for i in range(len(a))}
dic_ = {i:a[i] for i in range(len(a))}

len_a = len(dic)
ans = ""
for s in S:
    # print("iter alpha",s)
    num = dic[s]
    # print("alpha num",num)
    new_num = num + N
    # print("new_num",new_num)
    if new_num > 25:
        # print("here")
        new_num = new_num - 26
        # print("",new_num)
    else:
        pass
    ans += dic_[new_num]
    # print("temp ans",ans)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int a, b, x;

	cin >> a >> b >> x;
	if (a > x) {
		cout << "NO" << endl;
		return 0;
	}

	if ((a + b) >= x) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import math
N = int(input())

# (1, 1)から(a, b)に至るまでの移動回数は(a+b−2)であることに注意すると、
# a*b=N を満たす(a, b)について(a+b−2)の最小値を求めればよい
# 対称性より、O(√N)
# 今回はN=O(10^12)なので間に合う

# a+b-2の最小値を求める
ans = N-1
for i in range(1, int(math.sqrt(N))+1):
  if N % i == 0:
    ans = min(ans, (N//i)+i-2)
    
print(ans)

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


int main(){
  string s;
  cin >> s;
  int a = s.length();
  string ans="";
  REP(i,a) ans+='x';
  cout << ans << endl;
  return 0;
}


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


public class C
{
	public static void Main()	
	{
		string S = GetString();
		int numConnected = 0;
		char prev = '\0';
		for(int i = 0; i < S.Length; i++)
		{
			if((S[i] == 'B') && (prev != 'B'))
				numConnected++;
			else if((S[i] == 'W') && (prev != 'W'))
				numConnected++;
			prev = S[i];
		}
		Console.WriteLine(numConnected - 1);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 11988
#include<iostream>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(c - a) <= d) cout << "Yes" << endl;
    else if(abs(b - a) <= d && abs(c - b) <= d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

const int lim = 4000;
const int li = lim/4;
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
int memo[3][lim+1];

int solve(int i, int n){
    int r = 0;
    if(i < 3){
        for(int j = MAX(n-li,0); j <= n; j++){
            if(memo[i][j] < 0) memo[i][j] = solve(i+1,j);
            r += memo[i][j];
        }
    } else
        r = (n<=li)?1:0;
    return r;
}

int main(){
    int n;
    memset(memo,-1,sizeof(memo));
    while(scanf("%d",&n)>0) printf("%d\n", solve(0, n));
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    int n = S.length();
    bool judge = true;

    for (int i = 0; i < n ; i = i + 2)
    {
        if (S.at(i) == 'L')
        {
          judge = false;
        }
    }
    
       for (int j = 1; j < n ; j = j + 2)
            {
                if (S.at(j) == 'R')
                {
                    judge = false;
                }
            }
    if (judge)
    {
        cout << "Yes" << endl;
    }
    
    else
    {
        cout << "No" << endl;
    }
    
    
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  multiset<int, greater<int>> ms;
  rep(i, 1 << n) {
    in(int, s);
    ms.insert(s);
  }
  vector<int> v;
  v.push_back(*ms.begin());
  ms.erase(ms.begin());
  rep(i, n) {
    int J = v.size();
    rep(j, J) {
      const auto it = ms.lower_bound(v[j] - 1);
      // dbg(v[j], *it);
      if (it == ms.end()) {
        out("No");
        return 0;
      }
      v.push_back(*it);
      ms.erase(it);
    }
    // rep(i, v.size()) dbg(v[i]);
  }
  out("Yes");
}


Measured memory_bytes: 13692
#include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    string s;
    cin >> s;
    ll ans=0,T=0,S=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='T'){
            if(S>0){
                S--;
            }else{
                ans++;
            }
        }else{
            S++;
        }
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int n;

int main(){
	cin>>n;
	if(n<105){
		cout<<0<<endl;
	}else if(n<135){
		cout<<1<<endl;
	}else if(n<165){
		cout<<2<<endl;
	}else if(n<189){
		cout<<3<<endl;
	}else if(n<195){
		cout<<4<<endl;
	}else{
		cout<<5<<endl;
	}
	return 0;
}

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

int main() {
	double A, B;
	cin >> A >> B;
	double tax_8_1, tax_8_2, tax_10_1, tax_10_2;
	tax_8_1 = A / 0.08;
	tax_8_2 = (A + 1) / 0.08;
	tax_10_1 = B / 0.1;
	tax_10_2 = (B + 1) / 0.1;
	if (tax_8_1 != (int)tax_8_1) {
		tax_8_1 = (int)tax_8_1;
		tax_8_1 += 1;
	}
	if (tax_10_1 != (int)tax_10_1) {
		tax_10_1 = (int)tax_10_1;
		tax_10_1 += 1;
	}
	if (tax_8_2 == (int)tax_8_2) tax_8_2 -= 1;
	if (tax_10_2 == (int)tax_10_2) tax_10_2 -= 1;
	int ans = -1;
	if ((int)tax_8_2 >= (int)tax_10_1 && (int)tax_10_2 >= (int)tax_8_1) {
		ans = (int)max(tax_8_1, tax_10_1);
	}
	cout << ans << endl;
}

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

using namespace std;

const int oo = { 1000000010 };

int solve(const vector<int> xs) {
    int ans = oo;
    vector<int> order(5);
    iota(order.begin(), order.end(), 0);

    do {
        int t = 0;

        for (int i = 0; i < 4; i++) {
            t += 10 * ((xs[order[i]]+9)/10);
        }

        t += xs[order.back()];

        ans = min(ans, t);
    } while(next_permutation(order.begin(), order.end()));
    return ans;
}

int main(int argc, char const *argv[])
{
    vector<int> xs(5);

    for (int i = 0; i < 5; i++) {
        cin >> xs[i];
    }

    auto ans = solve(xs);

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


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;
}

Measured memory_bytes: 3608
c=int(input())
W=list(map(int,input().split()))

sum = 0

for i in range(c):
  sum += W[i]
  
prefix_sum = 0
prefix_min = 0
mini = 0

for i in range(c):
  prefix_sum += W[i]
  mini = abs(prefix_sum - (sum-prefix_sum))
  if i == 0:
    prefix_min = mini
  else:
    mini = min(prefix_min, mini)
  prefix_min = mini

print(mini)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
  double R;cin>>R;
  double pip =3.1415926535;
  cout<<(double)2*R*pip<<endl;
}





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

#define P(s) cout<<s<<endl
#define All(c) c.begin(),c.end()

using ll = int64_t;

int main() {
    map<char, queue<char>> card;
    for (auto c='a'; c<='c'; ++c) {
        string str;
        cin >> str;
        for(auto s:str) {
            card[c].push(s);
        }
    }
    
    auto c = 'a';
    for(;;) {
        if (card[c].empty()) {
            P(char(c-32));
            break;
        }
        auto ct = card[c].front();
        card[c].pop();
        c = ct;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo P
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001

vector<long long> dijkstra(int from,auto &E){
	vector<long long> ret(E.size(),Inf);
	ret[from]=0;
	priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> Q;
	Q.emplace(0,from);
	
	while(Q.size()!=0){
		long long D1 = Q.top().first;
		int from = Q.top().second;
		Q.pop();
		if(ret[from]!=D1)continue;
		for(int i=0;i<E[from].size();i++){
			int to = E[from][i].first;
			long long D2 = E[from][i].second;
			if(D1+D2<ret[to]){
				ret[to] = D1+D2;
				Q.emplace(ret[to],to);
			}
		}
	}
	
	return ret;
}

int main(){
	
	int N,M,S;
	cin>>N>>M>>S;
	
	S = min(S,3000);
	
	vector<vector<pair<int,long long>>> E(N*3001,vector<pair<int,long long>>());
	
	
	for(int i=0;i<M;i++){
		int U,V;
		cin>>U>>V;
		U--;V--;
		int A,B;
		cin>>A>>B;
		
		for(int j=0;j<=3000;j++){
			if(j-A<0)continue;
			
			E[U*3001+j].emplace_back(V*3001+j-A,B);
			E[V*3001+j].emplace_back(U*3001+j-A,B);
		}
	}
	
	for(int i=0;i<N;i++){
		int C,D;
		cin>>C>>D;
		
		for(int j=0;j<=3000;j++){
			int X = min(3000,j+C);
			E[i*3001+j].emplace_back(i*3001+X,D);
		}
	}
	
	auto D = dijkstra(S,E);
	
	for(int i=1;i<N;i++){
		long long ans  =Inf;
		for(int j=0;j<=3000;j++){
			ans = min(ans,D[i*3001+j]);
		}
		cout<<ans<<endl;
	}
		
	return 0;
}

Measured memory_bytes: 27380
import sys
from heapq import heappush, heappop, heappushpop, heapify, heapreplace
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

#ここから書き始める
n, m, k = map(int, input().split())
yes = False
for i in range(n + 1):
    for j in range(m + 1):
        if i * (m - j) + j * (n - i) == k:
            yes = True
            break
    if yes:
        break
if yes:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 5172
#include <cstdio>
#include <algorithm>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using P = std::pair<int, int>;

int N, M;
std::vector<P> vs;

int main()
{
  scanf( "%d%d", &N, &M );
  rep( i, M )
  {
    int a, b;
    scanf( "%d%d", &a, &b );
    vs.emplace_back( P( b, a ) );
  }
  
  std::sort( all(vs) );

  int prv = -1, ans = 0;

  rep( i, M )
  {
    if( prv == -1 || prv < vs[i].second )
      ++ans, prv = vs[i].first-1;
  }

  printf( "%d\n", ans );
  
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main()
{
    iso;
    int n,k;
    cin>>n>>k;
    cout<<n-k+1;

	 
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define pb push_back
#define rep(i, n) for(i=0; i<n; i++)
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	vector<int> se, ne;
	int i;
	rep(i, n){
		int x;
		cin >> x;
		se.pb(x);
		ne.pb(x);
	}
	//int j;
	sort(ne.begin(), ne.end(), greater<int>());
	rep(i, n){
		if(se[i]!=ne[0]){
			cout << ne[0] << endl;
		}
		else{
			cout << ne[1] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 5068
# frozen_string_literal: true

_, _, m = gets.split.map(&:to_i)
a = []
b = []
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

price = a.min + b.min
a = [nil] + a
b = [nil] + b

1.upto(m) do
  x, y, c = gets.split.map(&:to_i)
  price = a[x] + b[y] - c if a[x] + b[y] - c < price
end

puts price

Measured memory_bytes: 22284
#include <bits/stdc++.h>
using namespace std;
int main() {
 int N;
  cin >> N;
  
  int a,b,c,d;
  
  a=N/1000;
    b=N/100 - a*10;
    c=N/10 - a*100 - b*10;
    d= N%10;
  
  
  if (a==b && b==c){
    cout << "Yes" << endl;
  }
  
    else if (b==c && c==d) {
      cout << "Yes" << endl;
    }
  
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, m, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

for i in range(X+1, Y+1):
  if X < i <= Y and max(x) < i and min(y) >= i:
    print("No War")
    exit()

print("War")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int H,W,K;
int solve(vector<string> s){
//	show(s);
	int ret=0;
	rep(t,H*W){
		bool update=0;
		rep(i,H){
			int cont=0;
			char prev='0';
			int score=0;
			rep(j,W+1){
				if(j==W||s[i][j]=='0'||s[i][j]!=prev){
					if(cont>=K){
						score+=(prev-'0')*cont;
						update=1;
						rep(x,cont) s[i][j-1-x]='0';
					}
					cont=1;
				}else{
					cont++;
				}
				if(j==W) break;
				prev=s[i][j];
			}
			ret+=score<<t;
		}
		if(!update) break;
		vector<string> ns(H,string(W,'0'));
		rep(j,W){
			int x=H-1;
			for(int i=H-1;i>=0;i--) if(s[i][j]!='0'){
				ns[x--][j]=s[i][j];
			}
		}
		s=ns;
//		show(s);
	}
	return ret;
}
int main(){
	cin>>H>>W>>K;
	vector<string> s(H);
	rep(i,H) cin>>s[i];
	int ans=0;
	rep(i,H) rep(j,W){
		vector<string> ns=s;
		rep(x,i) ns[x+1][j]=s[x][j];
		ns[0][j]='0';
		chmax(ans,solve(ns));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256