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

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<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define deb(x)     cout << #x << " = "<<x<<endl

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)

int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;


ll gcd(ll  a , ll b) {
	return (b == 0) ? a : gcd(b, a % b);
}
ll binpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll powmod(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinv(ll n, ll p)
{
	return powmod(n, MOD - 2, MOD);
}
void max_self(ll &a, ll b) {
	a = max(a, b);
}


int main(int argc, char const *argv[])
{
	// two magical lines to speed up IO
	cin.tie(0);
	ios_base::sync_with_stdio(false);
// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// #endif
	ll n, w;
	cin >> n >> w;
	ll mx = 1000 * n;
	vl dp(mx + 1, w + 1);
	dp[0] = 0;
	while (n--) {
		ll wt , v;
		cin >> wt >> v;
		for ( int i = mx - v; i >= 0; --i) {
			dp[i + v] = min(dp[i + v], dp[i] + wt);
		}

	}
	for (int i = mx ; i >= 0; i--) {
		if ( dp[i] <= w) {
			cout << i << endl;
			break;
		}
	}
	return 0;


}










Measured memory_bytes: 3972
#include "bits/stdc++.h"
using namespace std;

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

const int dx[9] = { 1,1,1,0,0,0,-1,-1,-1 }, dy[9] = { 1,0,-1,1,0,-1,1,0,-1 };

int h, w, n, a, b, cnt, j, k, x, y, nx, ny, nnx, nny, sum;
vector<int>v;
unordered_map<int, bool>mp;
int ans[10];
signed main() {
	scanf("%lld %lld %lld", &h, &w, &n);
	rep(i, n) {
		scanf("%lld %lld", &a, &b);
		--a; --b;
		v.emplace_back(w * a + b);
	}
	sort(all(v));
	for (int i : v) {
		y = i / w, x = i % w;
		for (j = 0; j < 9; ++j) {
			nx = x + dx[j], ny = y + dy[j];
			if (0 < nx && nx < w - 1 && 0 < ny && ny < h - 1) {
				if (!mp[w * ny + nx]) {
					mp[w * ny + nx] = true;
					for (k = 0; k < 9; ++k) {
						nnx = nx + dx[k], nny = ny + dy[k];
						if (binary_search(all(v), w * nny + nnx)) {
							++cnt;
						}
					}
					++ans[cnt];
					++sum;
					cnt = 0;
				}
			}
		}
	}
	ans[0] += (h - 2) * (w - 2) - sum;
	for (int i : ans) {
		printf("%lld\n", i);
	}
}


Measured memory_bytes: 37344
def Exponential():
    X = int(input())
    if X<1 or X>1000:
        return ("Oops! X is out of the range!")
    res=[1]
    for b in range(1, X+1):
        for p in range(2, X+1, 1): 
            if b**p <=X:
                res.append(b**p)
            else: break
    print(max(res))
    
Exponential()

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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a < (A+1); ++a){
    for (int b = 0; b < (B+1); ++b){
      for (int c = 0; c < (C+1); ++c){
        int total = 500*a + 100*b + 50*c;
        if (total == X) ++res;
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N, K;
	static ll A[200001];
	cin >> N >> K;
	for(int i = 1; i <= N; i++){
		cin >> A[i];
	}
	static ll Add[200001];
	static ll AddSum[200001];
	static ll Sub[200001];
	static ll SubSum[200001];
	
	for(int n = 0; n < min(K, 50); n++){
		fill(Add, Add+N+1, 0);
		fill(AddSum, AddSum+N+1, 0);
		fill(Sub, Sub+N+1, 0);
		fill(SubSum, SubSum+N+1, 0);
		for(int i = 1; i <= N; i++){
			Add[max(0, int(i-1-A[i]))]++;
			Sub[min(N, int(i+A[i]))]++;
		}
		AddSum[0] = Add[0];
		SubSum[0] = Sub[0];
		for(int i = 1; i <= N; i++){
			AddSum[i] = AddSum[i-1] + Add[i];
			SubSum[i] = SubSum[i-1] + Sub[i];
		}
		
		for(int i = 1; i <= N; i++){
			A[i] = AddSum[i-1];
			A[i] -= SubSum[i-1];
		}
	}
	
	for(int i = 1; i <= N; i++){
		cout << A[i] << " ";
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;


int main(){
  int n;
  cin >> n;
  pair<ll, ll> p;
  p.fi = 0;
  p.se = INFll;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (p.fi<a) {
      p.fi = a;
      p.se = b;
    }
  }
  ll ans = p.fi + p.se;
  pr(ans);
  return 0;
}

Measured memory_bytes: 3672
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, K; cin >> A >> B >> K;

    vi ans;    
    if (B-A+1 >= K*2) {
        for(int i=0; i<K; i++) {
            ans.push_back(A+i);
        }    
        for(int i=K-1; i>=0; i--) {
            ans.push_back(B-i);
        }
    } else {
        for(int i=A; i<=B; i++) {            
            ans.push_back(i);
        }
    }

    for(int i : ans) cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S,T;
    cin >> S >> T;
    vector<string> ans;
    if(S.length() < T.length()){cout << "UNRESTORABLE" << endl;return 0;}
    for(int i = 0;i <= S.length()-T.length();i++){
        for(int j = 0;j < T.length();j++){
            if(S[i+j] != '?' && S[i+j] != T[j])break;
            if(j+1 == T.length()){
                string str = S;
                str.replace(i,j+1,T);
                ans.push_back(str);
            }
        }
    }
    for(auto &str:ans){
        for(auto &c:str)if(c=='?')c = 'a';
    }
    sort(ans.begin(),ans.end());
    cout << (ans.size()?ans[0]:"UNRESTORABLE") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	long long int A[310][310] = {}; 
	long long int D[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cin >> A[i][j]; 
			D[i][j] = A[i][j]; 
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			for(int k = 0; k < N; k++){
				if(D[i][k] == 0){
					continue; 
				}
				else if(i != j && j != k && A[i][k] == A[i][j] + A[j][k]){
					D[i][k] = 0, D[k][i] = 0; 
				}
			}
		}
	}
	long long int ans = 0; 
	for(int i = 0; i < N; i++){
		for(int j = i+1; j < N; j++){
			ans += D[i][j]; 
		}
	}
	long long int B[310][310] = {}; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i == j) B[i][j] = 0; 
            else if(D[i][j] > 0) B[i][j] = D[i][j]; 
			else B[i][j] = 1e15; 
		}
	}
	for(int k = 0; k < N; k++){
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				B[i][j] = min(B[i][j], B[i][k] + B[k][j]); 
			}
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(B[i][j] != A[i][j]) ans = -1;  
		}
	}
	cout << ans << endl; 
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<char> v;
  bool isFour = false;
  for (int i = 0; i < n; ++i) {
    char a;
    cin >> a;
    if(a == 'Y') {
        isFour = true;
        cout << "Four" << endl;
        break;
    }
   } 
   if(!isFour) {
    cout << "Three" << endl;
   }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int x = (j < a) ^ (i < b);
      cout << x;
    }
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
long long int dp[1000][1000];
long long int combination(int n, int r)
{
       if(n==r) return dp[n][r] = 1;
       if(r==0) return dp[n][r] = 1;
       if(r==1) return dp[n][r] = n;
       if(dp[n][r]) return dp[n][r];
       return dp[n][r] = combination(n-1,r) + combination(n-1,r-1);
}
int main(){
        int n,p;
        cin >> n >>p;
        int a[n]; int b[n]; int c[n];
        int j=0;int k=0;
        for(int i=0; i<n; i++) {
                cin >> a[i];
                if(a[i]%2==0) {
                        b[j]=a[i]; j++;
                }
                else {
                        c[k]=a[i]; k++;
                }
        }
      long long int ans=0; long long int g=0; long long int o=0;
        if(p==0) {
                for(int i=1; i<=j; i++) {
                        g+=combination(j,i);
                }
                for(int i=1;i<=k;i++){
                  if((i%2)==0) {
                    o+=combination(k,i);
                  }
                }
                ans=(g+o+(g*o)+1);
                cout <<ans <<endl;
        }
        else{
                for(int i=1; i<=k; i++) {
                        if((i%2)==1) o+=combination(k,i);
                }
                for(int i=1;i<=j;i++){
                  g+=combination(j,i);
                }
                ans=o+(g*o);
                cout << ans <<endl;
        }
}


Measured memory_bytes: 512
#include<algorithm>
#include<cstdio>
#include<utility>
#include<queue>
using namespace std;

const int MAX_N = 1e5;
int n;
int a[3 * MAX_N];
priority_queue<int, vector<int>, greater<int>> qg;
priority_queue<int> ql;
long sum1[MAX_N + 1], sum2[MAX_N + 1];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < 3 * n; i++) scanf("%d", &a[i]);
    
    for (int i = 0; i < n; i++) {
        sum1[0] += a[i];
        qg.push(a[i]);
        sum2[0] += a[3 * n - i - 1];
        ql.push(a[3 * n - i - 1]);
    }
    
    for (int i = 0; i < n; i++) {
        qg.push(a[n + i]);
        int g = qg.top(); qg.pop();
        sum1[i + 1] = sum1[i] + a[n + i] - g;
        ql.push(a[2 * n - i - 1]);
        int l = ql.top(); ql.pop();
        sum2[i + 1] = sum2[i] + a[2 * n - i - 1] - l;
    }
    
    long ans = -1e14;
    for (int i = 0; i <= n; i++) ans = max(ans, sum1[i] - sum2[n - i]);
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 4084
from fractions import gcd
# def gcd(x, y):
#     while(y != 0):
#         temp = y
#         y = x%y
#         x = temp
#     return y

def getMultiCount(start, end, times):
    if end < times: return 0
    s = start-(start%times)
    if s != start: s += times
    e = end-(end%times)
    if s > e: return 0
    return ((e-s)//times)+1
    
def answer(a, b, c, d):
    cCount = getMultiCount(a, b, c)
    dCount = getMultiCount(a, b, d)
    cdCount = getMultiCount(a, b, c*d//gcd(c,d))
    return (b-a+1)-(cCount + dCount - cdCount)

a, b, c, d = map(int, input().split())
print(answer(a, b, c, d))

Measured memory_bytes: 5304
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;
    cout << 60 * c + d - 60 * a - b - k;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3672
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define fill(x,y) memset(x,y,sizeof(x))
#define size(x) ((int)(x).size())
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define EPS 1e-7

int main2(){
  ll n;
  ll a[100];
  cin>>n;
  rep(i,n){ cin>>a[i]; }
  dump(a);

  sort(a, end(a), [](int x, int y) -> int { return (x < y); });

  dump(a);

  return 0;
}

int main(){
  ll n;
  vector<ll> a,b,c;
  cin>>n;
  ll t;
  rep(i,n){ cin>>t; a.push_back(t); }
  rep(i,n){ cin>>t; b.push_back(t); }
  rep(i,n){ cin>>t; c.push_back(t); }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  ll aRs[100001];
  ll cLs[100001];
  rep(i,n){
    aRs[i] = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    cLs[i] = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
  }
  ll s = 0;  // 場合の数
  rep(i,n){
    s+=(aRs[i]*(n-cLs[i]));
  }
  cout<<s<<endl;
  return 0;
}



Measured memory_bytes: 4340
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define bcount __builtin_popcount
#define mbit __builtin_ctz
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<long,null_type,less<long>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const long long mod=1e9+7;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll b,c,d,i,l,r,j;
	ll ans=0;
	cin>>b;
	vector<ll> arr(b);
	for(i=0;i<b;i++)
    {
        cin>>arr[i];
    }
    for(i=0;i<60;i++)
    {
        vector<ll> mas(2,0);
        for(j=0;j<b;j++)
        {
            if(arr[j]&(1LL<<i)) mas[1]++;
            else mas[0]++;
        }
        ll cnt=mas[0]*mas[1];
        for(j=0;j<i;j++)
        {
            cnt*=2;
            cnt%=mod;
        }
        ans+=cnt;
        ans%=mod;
    }
    cout<<ans%mod;
	return 0;
}


Measured memory_bytes: 2560
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int h,n;
int a[1005],b[1005];

int cache[10005][1005];

int dp(int health, int idx){
    if(idx>n && health) return inf;
    if(health<=0) return 0;
    //trace(health,idx);
    int &ans=cache[health][idx];
    if(ans!=-1) return ans;
    ans=min(dp(health-a[idx],idx)+b[idx],dp(health,idx+1));
    return ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> h >> n;
    rep(i,1,n+1){
        cin >> a[i] >> b[i];
    }
    mst(cache,-1);
    ll res=dp(h,1);
    cout << res;
    return 0;
}

Measured memory_bytes: 79232
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class RangeMinimumQuery:
    def __init__(self, n, func=min, inf=float("inf")):
        self.n0 = 2**(n-1).bit_length()
        self.op = func
        self.inf = inf
        self.data = [self.inf]*(2*self.n0)

    def construct(self, lis):
        for i, x in enumerate(lis):
            self.data[i+self.n0-1] = x
        for i in range(self.n0-2, -1, -1):
            self.data[i] = self.op(self.data[2*i+1], self.data[2*i+2])

    def query(self, l,r):
        l += self.n0
        r += self.n0
        res = self.inf
        while l < r:
            if r&1:
                r -= 1
                res = self.op(res, self.data[r-1])
            if l&1:
                res = self.op(res, self.data[l-1])
                l += 1
            l >>=1
            r >>=1
        return res

    def update(self, i, x):
        i += self.n0-1
        self.data[i] = x
        while i+1:
            i = ~-i//2
            self.data[i] = self.op(self.data[2*i+1], self.data[2*i+2])

h,n = map(int, input().split())
bag = []
for i in range(n):
    a,b = map(int, input().split())
    bag.append((a,b))

dp = [[float("inf")]*(h+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0

for i in range(n):
    damage, mana = bag[i]
    for w in range(h+1):
        dp[i+1][w] = min(dp[i+1][w], dp[i][w])
        if w >= damage:
            dp[i+1][w] = min(dp[i+1][w], dp[i+1][w-damage]+mana)

data = dp[-1]
rmq = RangeMinimumQuery(len(data))
rmq.construct(data)
ans = data[-1]
for a,b in bag:
    if a >= h:
        ans = min(ans, b)
    else:
        tmp = rmq.query(h-a, h) + b
        ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 366616
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = {1171, 3307}, Mod = {1e9 + 7, 1e9 + 9};
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, m, p[N], dp[N];
string s;
set < pii > q, qq;		
	
main () {
	cin >> n >> m >> s;
	q.insert({0, n});	
	qq.insert({n, 0});
	forev (i, n - 1, 0) {
		if (s[i] == '1')
			continue;
		
		while (sz(qq) && qq.rbegin()->f - m > i) {
			pii tmp = *qq.rbegin();
			qq.erase(tmp);
			q.erase({tmp.s, tmp.f});			
		}			 	
		
		if (!sz(q)) {
			cout << -1;
			return 0;
		}			

		p[i] = q.begin()->s;
		dp[i] = dp[p[i]] + 1;
		q.insert({dp[i], i});
		qq.insert({i, dp[i]});
	}

	int x = 0;
	vi ans;
	while (1) {
		ans.pb(x);
		if (x == n)
			break;
		x = p[x];
	}
	forn (i, 0, sz(ans) - 2)
		cout << ans[i + 1] - ans[i] << ' ';

}


Measured memory_bytes: 8960
N,M,X=map(int,input().split())

C=[0] * N
A=[0] * N

for i in range(N):
  tmp=list(map(int,input().split()))
  C[i]=tmp[0]
  A[i]=tmp[1:M+1]

n=0
s=100000000

for i in range(2**N):
  score=[0]*M
  s_tmp=0
  for j in range(N):
    if ((1 << j) & i) >> j == 1:
      s_tmp+=C[j]
      for k in range(M):
        score[k]+=A[j][k]
  flg=1
  for k in range(M):
    if score[k] < X:
      flg=0
      break
  if flg==1:
    if s_tmp < s:
      s=s_tmp
if s == 100000000:
  print(-1)
else:
  print(s)

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

int main() {
  long long A, B;
  int K;
  cin >> A >> B >> K;
  for (int i = A; i <= B; i++) {
    if ((A <= i && i < A + K) || (B - K < i && i <= B)) {
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
s, = gets.split
a = s[0]
b = s[1]
c = s[2]
d = s[3]

count_a = 0
count_a += 1 if a == b
count_a += 1 if a == c
count_a += 1 if a == d

count_b = 0
count_b += 1 if b == a
count_b += 1 if b == c
count_b += 1 if b == d

count_c = 0
count_c += 1 if c == a
count_c += 1 if c == b
count_c += 1 if c == d

count_d = 0
count_d += 1 if d == a
count_d += 1 if d == b
count_d += 1 if d == c

ok = count_a == 1 && count_b == 1 && count_c == 1 && count_d == 1

puts ok ? 'Yes' : 'No'


Measured memory_bytes: 1788
require 'matrix'

n, m, x = gets.split.map(&:to_i)
a = Matrix.zero(n, m + 1)
n.times do |i|
  b = gets.split.map(&:to_i)
  0.upto(m) do |j|
    a[i, j] = b[j]
  end
end
1.upto(m) do |j|
  if (a.column(j).covector * Vector.elements(Array.new(n, 1)))[0] < x
        puts "-1"
    exit
  end
end
min = Float::INFINITY
1.upto(2 ** n - 1) do |bit|
  ans = 0
  sum = 0
  1.upto(m) do |j|
    sum = 0
    n.times do |i|
      if bit[i] == 1
        sum += a[i, j]
      end
    end
    break if sum < x
  end
  if sum >= x
    n.times do |i|
      if bit[i] == 1
        ans += a[i, 0]
      end
    end
    min = ans if min > ans
  end
end
puts min

Measured memory_bytes: 15112
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0) (__VA_ARGS__)
#define rep_0(i, end) for (int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for (int i = (fr); i <= (ba); ++i)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

constexpr int inf = (1 << 30) - 1;

int main() {

  int N;
  std::cin >> N;
  std::vector<std::pair<int, int>> vec;
  rep (i, N) {
    int x, l;
    std::cin >> x >> l;
    vec.emplace_back(x + l, x - l);
  }

  std::sort(all(vec));
  int now = -inf, ans = 0;
  rep (i, N) {
    if (vec[i].second >= now) {
      ans++;
      now = vec[i].first;
    }
  }

  std::cout << ans << '\n';
  return 0;

}


Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int K;
  string S;
  cin>>K>>S;
  if(S.length()>K){
    cout<<S.substr(0,K)+"..."<<endl;
  }else{
    cout<<S<<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, a, n) for ( i = a; i < (n); i++)
#define fill(a,v)                    memset(a, v, sizeof(a))
#define sz(a)                       ((int)(a.size()))
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 1e9+7
int main(){
	fast;
	ll i,j,W,k,tc,q,m,n,flag;	
	cin>>n>>m;
	string a[n];
	rep(i,0,n){
		cin>>a[i];
	}
	ll dp[1005][1005]={};
	dp[0][0]=1;
	rep(i,0	,n){
		rep(j,0,m){
			if(a[i][j]=='.'){
				if(j<m-1&&a[i][j+1]=='.'){
					dp[i][j+1] += dp[i][j];
					dp[i][j+1] %=(ll)MOD;
				}
				if(i<n-1&&a[i+1][j]=='.'){
					dp[i+1][j]+=dp[i][j];
					dp[i+1][j] %=(ll)MOD;
				}
			}

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

	rep(i,0,n){
		rep(j,0,m){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back 
#define endl '\n'
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define int long long

#define bug(x) cout << #x << " = " << x << '\n'
const int MAXN = 200050;

int32_t main()
{
	int x, y; cin >> x >> y;
  	cout << x + y/2;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<functional>//greaterの使用
using namespace std;
#define MAX_LIST 50000

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	int primelist[MAX_LIST];
	int j=0;
	for(int i=0;i<MAX_LIST;i++){
		if(prime[i]==1){
			primelist[j]=i;
			j++;
			if(j>MAX_LIST){
				break;
			}
		}
	}
	int in;
	while(cin>>in,in){
		int ans=0;
		for(int i=0;primelist[i]*2<=in;i++){
			if(prime[in-primelist[i]]==1){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
  int n;cin>>n;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  int ans=0,cnt=0;
  rep(i,n-1){
    if(h[i]<h[i+1])cnt=0;
    else cnt++;
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

ld memo[500][500][500];
ld rec(ll i,ll j,ll k,const ll& N){
	if(i<0||j<0||k<0)return 0;
	if(!i&&!j&&!k)return 0;
	if(memo[i][j][k])return memo[i][j][k];
	if(i == 1 && !j && !k)return (ld)N/i;
	return memo[i][j][k] = 
	(ld)(i*rec(i-1,j,k,N)+j*rec(i+1,j-1,k,N)+k*rec(i,j+1,k-1,N)+N)/(i+j+k);
}

/*
memo[i][j][k] =
((N-i-j-k)/N)*memo[i][j][k]+
(i/N)*memo[i-1][j][k]+
(j/N)*memo[i+1][j-1][k]+
(k/N)*memo[i][j+1][k-1]+
1
*/

signed main(){
	ll N;
	cin >> N;
	vl a(N);
	ll counter[3] = {0};
	FOR(i,0,N){
		ll tmp;
		cin >> tmp;
		if(tmp)counter[tmp-1]++;
	}
	cout << rec(counter[0],counter[1],counter[2],N) << endl;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

signed main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0; i < n; ++i){
        for(int j = i; j < n + 1; ++j){
            string t = s.substr(0, i) + s.substr(j);
            if(t == "keyence"){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T gcd(T u, T v) {
    ll r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T lcm(T u, T v) {
    return u * v / gcd(u, v);
}

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

    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<pair<int, int>> lr(Q);
    cin >> lr;

    vector<int> s(N + 1);
    s[0] = 0;
    REP(i, N) {
        s[i + 1] = s[i];
        if (S[i] == 'C') {
            if (i - 1 >= 0 && S[i - 1] == 'A') {
                s[i + 1]++;
            }
        }
    }

    REP(i, Q) {
        cout << s[lr[i].second] - s[lr[i].first] << endl;;
    }
    return 0;

}

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

vector<int> con[10];
int p[10];
int main()
{
	int n,m;
	cin >> n >> m;
	for(int i = 0;i<m;i++)
	{
		int k;
		cin >> k;
		for(int j = 0;j<k;j++)
		{
			int s;
			cin >> s;
			s--;
			con[i].push_back(s);
		}
	}
	for(int i =0;i<m;i++)cin >> p[i];
	int ans = 0;
	for(int i = 0;i<(1<<n);i++)
	{
		int on = 0;
		for(int j = 0;j<m;j++)
		{
			int cnt = 0;
			for(auto k:con[j])
			{
				if(i&(1<<k))
				{
					cnt++;
				}
			}
			if(p[j]==cnt%2)on++;
		}
		if(on==m)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n == 0 && m == 0)
			{
				break;
			}
			List<Integer> taro = new ArrayList<Integer>();
			List<Integer> hanako = new ArrayList<Integer>();
			int sumTaro = 0;
			int sumHanako = 0;
			for(int i = 0; i < n; ++i)
			{
				int a = stdIn.nextInt();
				taro.add(a);
				sumTaro += a;
			}
			for(int i = 0; i < m; ++i)
			{
				int a = stdIn.nextInt();
				hanako.add(a);
				sumHanako += a;
			}
			int diff = sumTaro - sumHanako;
			int min = 999999999;
			int[] ans = new int[2];
			boolean okFlag = false;
			for(int i = 0; i < n; ++i)
			{
				for(int j = 0; j < m; ++j)
				{
					if((taro.get(i) - hanako.get(j) == diff / 2.0) && (taro.get(i) + hanako.get(j) < min))
					{
						okFlag = true;
						min = taro.get(i) + hanako.get(j);
						ans[0] = taro.get(i);
						ans[1] = hanako.get(j);
					}
				}
			}
			if(okFlag)
			{
				System.out.println(ans[0] + " " + ans[1]);
			}
			else
			{
				System.out.println(-1);
			}
		}
	}
}

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

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

using namespace std;
using ll = long long;

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

ll dp[100100][3];

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  rep(i, n) cin >> a[i] >> b[i] >> c[i];
  rep(i, n) rep(j, 3) dp[i][j] = 0;

  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  rep(i, n) rep(j, 3) rep(k, 3) {
    if (j != k) {
      if (j == 0) {
        dp[i + 1][j] = max(dp[i][k] + a[i + 1], dp[i + 1][j]);
      } else if (j == 1) {
        dp[i + 1][j] = max(dp[i][k] + b[i + 1], dp[i + 1][j]);
      } else {
        dp[i + 1][j] = max(dp[i][k] + c[i + 1], dp[i + 1][j]);
      }
    }
  }
  ll ans = 0;
  rep(i, 3) ans = max(ans, dp[n - 1][i]);
  cout << ans << endl;
}

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

struct Edge{
    ll target;
    ll weight;
};

struct State{
    ll node;
    ll sum_of_weight;

    bool operator < (const State& s)  const {
        return sum_of_weight > s.sum_of_weight;
    }
};

typedef vector<vector<Edge> > graph;

void dijkstra(graph &g, vector<ll>&d, ll start){

    priority_queue<State> pq;
    pq.push(State{start,0});

    while( pq.size() ){

        State s = pq.top(); pq.pop();

        if( d[s.node] != -1 ) continue;
        d[s.node] = s.sum_of_weight;

        for(auto edge: g[s.node]) {
            if( d[edge.target] != -1 ) continue;
            pq.push(State{edge.target, s.sum_of_weight + edge.weight});

        }
    }

}


int main(){

    ll N;
    cin >> N;

    graph G(N);
    for (int i = 0; i < N; i++)
    {
        ll u,k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            ll v,c;
            cin >> v >> c;
            G[u].push_back(Edge{v,c});
        }
    }

    vector<ll> d(N,-1);

    ll count = 1;
    dijkstra(G,d,0);

    for (int i = 0; i < N; i++)
    {
        cout << i << " " << d[i] << endl;
    }
    
}


Measured memory_bytes: 15796
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back

main() {
	int n, k;
	cin>>n>>k;
	vector<int>a;
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	vector<int>f;
	for(int i=0; i<n; i++){
		int x;
		cin>>x;
		f.pb(x);
	}
	sort(a.begin(), a.end());
	sort(f.begin(), f.end());
	reverse(f.begin(), f.end());
	int hi=1e13;
	int lo=0;
	int ans=-1;
	while(lo<=hi){
		int mid=(lo+hi)/2;
		int num=0;
		for(int i=0; i<n; i++){
			int shou=(mid)/f[i];
			if(shou>=a[i]){
				continue;
			}
			num+=(a[i]-shou);
		}
		if(num<=k){
			hi=mid-1;
			ans=mid;
		}
		else{
			lo=mid+1;
		}
	}
	cout<<ans;
	return 0;
}

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

int main(){
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	vector<int> a(n+1),b(m+1);
	a[0] = x;
	b[0] = y;
	int t;
	rep(i,n)cin >> a[i+1];
	rep(i,m)cin >> b[i+1];
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	if(a[n] < b[0]) cout << "No War" << endl;
	else cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<ctime>
using namespace std;
#define INF (1<<29)



class PMA{//Aho-Corasick
	struct Node{
		bool match;
		int failure;
		int len;
		int next[256];
		Node(int len):failure(-1),len(len),match(false){memset(next,-1,sizeof(next));}
	};
	vector<Node> node;

	void precompute(){
		for(int i=1;i<(int)node.size();i++){
			for(int j=0;j<256;j++){
				node[i].next[j]=_step(i,j);
			}
		}
	}
	int _step(int t,char c)const{
		while(node[t].next[c]==-1)t=node[t].failure;
		return node[t].next[c];
	}
public:
	PMA(){}
	~PMA(){
		node.clear();
	}
	int size()const{return node.size();}
	bool matched(int id)const{return node[id].match;}
	void build(const vector<string> &p){
		node.clear();
		node.push_back(Node(0));
		for(int i=0;i<(int)p.size();i++){
			const string &s=p[i];
			int t=0;
			for(int j=0;j<(int)s.size();j++){
				if(node[t].next[s[j]]==-1){
					node[t].next[s[j]]=node.size();
					node.push_back(Node(j+1));				
				}
				t=node[t].next[s[j]];
			}
			node[t].match=true;
		}
		queue<int> q;
		for(int i=0;i<256;i++){
			Node &root=node[0];
			if(root.next[i]!=-1){
				q.push(root.next[i]);
				node[root.next[i]].failure=0;
			}else root.next[i]=0;
		}
		while(!q.empty()){
			int t=q.front();q.pop();
			for(int i=0;i<256;i++){
				if(node[t].next[i]!=-1){
					q.push(node[t].next[i]);
					int r=_step(node[t].failure,i);
					int v=node[t].next[i];
					node[v].failure = r;
					if(r!=-1)node[v].match |= node[r].match;
				}
			}
		}
		precompute();
	}
	int step(int t,char c)const{
		return node[t].next[c];
	}
	int length(int t)const{
		return node[t].len;
	}
};




PMA pma;
vector<string> piece;
int pLen;
vector<string> ans;
const char C[28]=".ABCDEFGHIJKLMNOPQRSTUVWXYZ";


bool match(string &s){
	int node=0;
	int cover=-1;
	for(int i=0;i<s.size();i++){
		node=pma.step(node,s[i]);
		if(pma.matched(node))cover = i;
		else if(i-cover>pma.length(node))return false;
		//else if(pLen==i-cover)return false;
	}
	return cover==s.size()-1;
}
void search(string &s,int d){
	if(d==0){
		//cout<<s<<endl;
		if(match(s))ans.push_back(s);
		return;
	}
	//search(s,d-1);
	string t(s.begin(),s.end());
	t+=' ';
	for(int i=s.size();;i--){//insert
		for(int j=0;j<27;j++){
			t[i]=C[j];
			search(t,d-1);
		}
		if(i==0)break;
		t[i]=t[i-1];
	}
	for(int i=0;i<s.size();i++){//replace
		for(int j=0;j<27;j++){
			char c=s[i];
			s[i]=C[j];
			search(s,d-1);
			s[i]=c;
		}
	}
	t.assign(s,1,s.size()-1);
	char c = s[0];
	for(int i=0;i<t.size();i++){//remove
		search(t,d-1);
		swap(c,t[i]);
	}
	search(t,d-1);
}
int main(){
	//clock_t t=clock();
	int d,n;
	while(cin>>d>>n,d|n){
		string alter;
		cin>>alter;
		piece.clear();
		for(int i=0;i<n;i++){
			string t;
			cin>>t;
			piece.push_back(t);
			pLen=t.size();
		}
		pma.build(piece);
		ans.clear();
		search(alter,d);
		sort(ans.begin(),ans.end());
		ans.erase(unique(ans.begin(),ans.end()),ans.end());
		cout<<ans.size()<<endl;
		if(ans.size()<=5){
			for(int i=0;i<ans.size();i++)cout<<ans[i]<<endl;
		}
	}
	//cout<<((double)(clock()-t)/CLOCKS_PER_SEC)<<endl;
	return 0;
}

Measured memory_bytes: 34704
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/02/20 20:07:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll x; cin>>x;
  int ans = 0;
  ll m = 100;
  while (m < x) {
    ans++;
    m += m/100;
  }
  cout << ans << endl;

  return 0;
}


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


int main(){
  int a,b;
  cin >> a >> b;
  if ( a %3 == 0 || b %3 == 0){ cout << "Possible" << endl;
    return 0;
  }else if( (a+b) %3 == 0){
    cout << "Possible" << endl;
    return 0;
  }else{
    cout << "Impossible" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		String now = "A";
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty())
				break;
			String[] lines = line.split(",");
			if(lines[0].equals(now)){
				now = lines[1];
			}else if(lines[1].equals(now)){
				now = lines[0];
			}
		}
		System.out.println(now);
	}
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
  
signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  rep(i,n) {
    cin>>a[i];
    if((i+1)%2==1 && a[i]%2==1) ans++;
  }
cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3624
import java.util.*;
import java.util.stream.*;
import java.util.function.*;

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println(new Main().solve());
    }
    
    
    int solve() {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        
        int times = b / a;
        return times >= c ? c : times;
    }
}


Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main(){
	int a=0,b=0;
	for(int i=0;i<4;i++){
		int t;
		cin>>t;
		a+=t;
	}
	for(int i=0;i<4;i++){
		int t;
		cin>>t;
		b+=t;
	}
	cout<<max(a,b)<<endl;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
#include <iostream>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
 
#define debug(format, ...) printf(format, __VA_ARGS__);
 
const int K_ = int(1e5), B = 50;
 
int K;
bool vis[K_][B+1];

int main() {
#ifdef IN_MY_COMPUTER
  freopen("d.in", "r", stdin);
#endif
  scanf("%d", &K);

  int ub = 0;
  for(int k = K; k > 0; k /= 10) ub += k % 10;
  
  priority_queue< pii, vector<pii>, greater<pii> > pq;
  pq.emplace(0, 0);
  vis[0][0] = true;

  while(!pq.empty()) {
    int u, s; tie(s, u) = pq.top(); pq.pop();
    if(u == 0 && s > 0) {
      printf("%d\n", s);
      return 0;
    }
    for(int d = 0; d < 10; d++) {
      int v = (u * 10 + d) % K;
      int t = s + d;
      if(t <= B && !vis[v][t]) {
        vis[v][t] = true;
        pq.emplace(t, v);
      }
    }
  }
  
  return 0;
}

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

int main(){
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n] = {0};
	dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 1024