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

using ll = long long;

//constant
const ll MOD = 1e+9 + 7;
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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

// ***************************************

const ll inf = 1LL << 60;

struct Mint {
    ll v;
    ll _mod;
    Mint() : v(0) {}
    Mint(signed v, ll _mod = MOD) : v(v), _mod(_mod) {}
    Mint(ll t, ll _mod = MOD) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    Mint pow(ll k) {
        Mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static Mint add_identity() { return Mint(0); }
    static Mint mul_identity() { return Mint(1); }
    Mint inv() { return pow(_mod - 2); }

    Mint& operator+=(Mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    Mint& operator-=(Mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    Mint& operator*=(Mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    Mint& operator/=(Mint a) { return (*this) *= a.inv(); }

    Mint operator+(Mint a) const { return Mint(v) += a; };
    Mint operator-(Mint a) const { return Mint(v) -= a; };
    Mint operator*(Mint a) const { return Mint(v) *= a; };
    Mint operator/(Mint a) const { return Mint(v) /= a; };

    Mint operator-() const { return v ? Mint(_mod - v) : Mint(v); }

    bool operator==(const Mint a) const { return v == a.v; }
    bool operator!=(const Mint a) const { return v != a.v; }
    bool operator<(const Mint a) const { return v < a.v; }
};
ostream& operator<<(ostream& os, Mint m) { return os << m.v; }


int main(void) {

	int N, K;
	cin >> N >> K;

	vector<ll> A(N);
	for (auto& a : A) {
		cin >> a;
	}
	vector<vector<Mint>> dp(N + 1, vector<Mint>(K + 1));
	REP(i, N+1) {
		dp[i][0] = Mint(1);
	}

	FOR(i, 1, N+1) {
		FOR(j, 1, K + 1) {
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            if (j - A[i - 1] - 1 >= 0) {
                dp[i][j] = dp[i][j] - dp[i - 1][j - A[i - 1] - 1];
            }
		}
	}

    cout << dp[N][K].v << endl;

	return 0;
}

Measured memory_bytes: 159744
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int N;
  cin>>N;
  
  vector<int>ans(100000);
  for(int i=1;i*i<=N;i++){
    for(int j=1;j*j<=N;j++){
      for(int k=1;k*k<=N;k++){
        int n=i*i+j*j+k*k+i*j+j*k+k*i;
        ans[n]++;
      }
    }
  }
  for(int i=1;i<=N;i++){
    cout<<ans[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3780
/* lca_doubling.cpp
    最近共通祖先(LCA:Lowest Common Ancestor)をダブリングにより求める
    (u,v の2^k先の親が同じかどうかを二分探索で調べる)

    verified: AOJ GRL_5_C
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C
 */

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    long long to;
};
using Graph = vector<vector<Edge>>;

/* LCA(G, root): 木 G に対する根を root として Lowest Common Ancestor を求める構造体
    query(u,v): u と v の LCA を求める。計算量 O(logn)
    dist(u,v): u と v の距離を求める。計算量 O(logn)
    is_on_path(u,v,a): u, v を繋ぐパス上に a が存在するかを判定する。計算量 O(logn)
    前処理: O(nlogn)時間, O(nlogn)空間
*/
struct LCA {
    vector<vector<int>> parent;  // parent[k][u]:= u の 2^k 先の親
    vector<int> depth;           // root からの深さ
    LCA(const Graph &G, int root = 0) { init(G, root); }
    void init(const Graph &G, int root = 0) {
        int V = G.size();
        int K = 1;
        while ((1 << K) < V) K++;
        parent.assign(K, vector<int>(V, -1));
        depth.assign(V, -1);
        dfs(G, root, -1, 0);  // initialization of parent[0] & depth
        // initialization of parent
        for (int k = 0; k + 1 < K; k++) {
            for (int v = 0; v < V; v++) {
                if (parent[k][v] < 0) {
                    parent[k + 1][v] = -1;
                } else {
                    parent[k + 1][v] = parent[k][parent[k][v]];
                }
            }
        }
    }
    void dfs(const Graph &G, int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;
        for (auto e : G[v]) {
            if (e.to != p) dfs(G, e.to, v, d + 1);
        }
    }
    int query(int u, int v) {
        if (depth[u] < depth[v]) swap(u, v);
        int K = parent.size();
        for (int k = 0; k < K; k++) {
            if ((depth[u] - depth[v]) >> k & 1) {
                u = parent[k][u];
            }
        }
        if (u == v) return u;
        for (int k = K - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }
    int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[query(u, v)]; }
    bool is_on_path(int u, int v, int a) { return dist(u, a) + dist(a, v) == dist(u, v); }
};

int main() {
    int n;
    cin >> n;
    Graph G(n);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            G[i].push_back({c});
            G[c].push_back({i});
        }
    }
    int q;
    cin >> q;
    vector<int> u(q), v(q);
    for (int i = 0; i < q; i++) {
        cin >> u.at(i) >> v.at(i);
    }

    LCA lca(G, 0);

    for (int i = 0; i < q; i++) {
        cout << lca.query(u[i], v[i]) << endl;
    }
}



Measured memory_bytes: 19792
N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(min(K, 50)):
    lamp = [0 for i in range(N + 1)]
    for i in range(N):
        lamp[max(0, i - A[i])] += 1
        lamp[min(N, i + A[i] + 1)] -= 1

    for i in range(1, N + 1):
        lamp[i] += lamp[i - 1]
    A = lamp

[print(A[i], end=' ') for i in range(N)]
print()


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

using namespace std;

typedef long long ll;

ll N, K, L, R;
ll a[40];

auto enumerate(int sidx, int size) {
  vector<pair<ll, ll>> ret;
  for(int i=0; i<1<<size; i++) {
    int cnt = 0; ll sum = 0;
    for(int j=0; j<size; j++)
      if(i >> j & 1) cnt++, sum += a[sidx + j];
    ret.emplace_back(cnt, sum);
  }
  return move(ret);
}

ll solve() {
  auto v0 = enumerate(0, N / 2);
  auto v1 = enumerate(N / 2, (N + 1) / 2);
  sort(v0.begin(), v0.end());
  ll ret = 0;
  for(int i=0; i<(int)v1.size(); i++)
    ret +=  upper_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, R - v1[i].second))
          - lower_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, L - v1[i].second));
  return ret;
}

int main() {
  cin >> N >> K >> L >> R;
  for(int i=0; i<N; i++) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

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

using ll = long long;

int main() {
    string N;
    int K;
    cin >> N >> K;
    int l = N.size();
    // dp[i][j][0] 上からi+1桁で０でない数がj個でN未満確定
    // dp[i][j][1] 上からi+1桁で０でない数がj個でNと一致
    vector<vector<vector<int>>> dp(l, vector<vector<int>>(K + 2, vector<int>(2, 0)));
    dp[0][0][0] = 1;
    dp[0][1][0] = N[0] - '1';
    dp[0][1][1] = 1;
    rep(i, l - 1) {
        rep(j, K + 1) {
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j + 1][0] += dp[i][j][0] * 9;
            if (N[i + 1] == '0') {
                dp[i + 1][j][1] += dp[i][j][1];
            } else {
                dp[i + 1][j + 1][1] += dp[i][j][1];
                dp[i + 1][j + 1][0] += dp[i][j][1] * (N[i + 1] - '1') + dp[i][j + 1][1];
            }
        }
    }
    cout << dp[l - 1][K][0] + dp[l - 1][K][1] << "\n";
    /*
    rep(i, l) {
        rep(j, K + 2) {
            rep(k, 2) {
                cout << " dp[" << i << "][" << j << "][" << k << "]=" << dp[i][j][k]; 
            }
        }
        cout << "\n";
    }
    */
}

Measured memory_bytes: 256
#include<iostream>
#include <utility>
#include<bits/stdc++.h>
#define ull unsigned long long int
#define ll int
#define ld long double
// #define loop(i,a,b) for(ll i=a;i<b;i++)
// #define inll(n) ll n;cin>>n;
// #define instr(s)  string s;cin>>s;
// #define inarr(a,n)  ll*a = new ll[n];loop(i,0,n)cin>>a[i]; 
// #define invec(v,n)  vector<ll> v(n);loop(i,0,n)inll(v[i])
// #define arr(a,n) ll*a = new ll[n];
// #define outarr(a,n) loop(i,0,n)cout<<a[i]<<" ";cout<<endl;
#define pb push_back
#define mp make_pair
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector <int>
#define vb vector <bool>
#define vll vector <ll>
#define vc vector <char>
#define clr(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define infd 1e+18
#define inf 101901199101
#define mod 1000000007

inline ll min(ll a,ll b)
{
    return (a<b?a:b);
}
inline ll max(ll a,ll b)
{
    return (a<b?b:a);
}

using namespace std;
int main()
{fastio
    ll n;cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    for(ll i = 0;i<s1.length();i++)
    {
        cout<<s1[i]<<s2[i];
    }

    cout<<endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int main(){
	int n;cin>>n;
	map<P,int>mp;
	ll cnt=0;
	rep(i,n){
		ll a,b;cin>>a>>b;
		if(a==0&&b==0){
			cnt++;
			continue;
		}
		if(a==0){
			b=abs(b);
		}
		if(a<0){
			a=-a;b=-b;
		}
		ll g=gcd(a,abs(b));
		a/=g;b/=g;
		mp[{a,b}]++;
	}
	set<P>used;
	ll ans=1;
	for(auto p:mp){
		if(used.count(p.first))continue;
		P q=P(p.first.second,-p.first.first);
		if(p.first.second<0){
			q=P(-p.first.second,p.first.first);
		}
		if(!mp.count(q)){
			(ans*=ppow(2,p.second))%=MOD;
			continue;
		}
		(ans*=(ppow(2,p.second)+ppow(2,mp[q])+MOD-1)%MOD)%=MOD;
		used.insert(q);
	}
	cout<<((ans+MOD-1)+cnt)%MOD<<endl;
}

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

int main()
{
	string s;

	cin >> s;

	while (s != "#") {
		int p;
		if (s[0] == '0')
			p = 0;
		else
			p = 1;

		for (int i = 1; i < s.size(); i++) {
			if (p == 0) {
				if (s[i] == '1')
					p = 2;
				else
					p = 5;
			}
			else if (p == 1) {
				if (s[i] == '0')
					p = 0;
				else
					p = 5;
			}
			else if (p == 2) {
				if (s[i] == '1')
					p = 4;
				else
					p = 3;
			}
			else if (p == 3) {
				if (s[i] == '1')
					p = 1;
				else
					p = 4;
			}
			else if (p == 4) {
				if (s[i] == '1')
					p = 0;
				else
					p = 1;
			}
		}

		if (p == 4)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

		cin >> s;
	}

	return 0;
}



Measured memory_bytes: 3160
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 0;
	if (*ci == '-') {
		pn = 1;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	if (pn) tmp = -tmp;
	return tmp;
}

ll A[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	rep1(i, N) {
		A[i] = getint() + A[i - 1];
	}

	pakuri_sort(N + 1, A);

	ll kotae = 0;
	int kazu = 1;
	rep(i, N) {
		if (A[i + 1] != A[i]) kazu = 1;
		else kotae += kazu++;
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 6452
a=int(input())
b=int(input())
c=int(input())
x=int(input())

max500=min(a,x//500)
max100=min(b,(x-max500*500)//100)
max50=min(c,(x-max500*500-max100*100)//50)
count=0

# print(max500,max100,max50)
for num500 in range(a+1):
    for num100 in range(b+1):
        remain=x-num500*500-num100*100
        if remain>=0:
            if remain//50<=c:
#                 print(num500,num100,remain//50)
                count+=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;

int main() {
	int N, M; cin>>N>>M;
	vector<int> r(N,0);
	for(int i = 0; i < M;i++) {
		int a, b; cin>>a>>b;
		r[a-1] ++;
		r[b-1]++;
	}
	for(int i = 0; i < N; i++) {
		cout << r[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int dp[100][2][2];
int main(){
    string s;
    cin>>s;
    int n=s.size();
    bool flag9=true;
    for(int i=1;i<n;i++){
        if(s[i]!='9'){
            flag9=false;
        }
    }
    if(flag9){
        cout<<9*(n-1)+(s[0]-'0')<<endl;return 0;
    }
    ll ans=9*(n-1)+(s[0]-'0')-1;
    cout<<ans<<endl;
    return 0;
}


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

int n, m;

int main() {
	cin >> n >> m;
	int x = 1900 * m + 100 * (n - m);
	int p = 1; for (int ite = 1; ite <= m; ite++)p <<= 1;
	cout << x*p;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;

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

#define P (1'000'000'007)

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

    int ans = 0;
    int con = 0;
    rep(i, 3) {
        if (s[i] == 'R'){ ++con;
        } else {
            chmax(ans, con);
            con = 0;
        }
    }

    cout << max(ans, con);

    return 0;
}

Measured memory_bytes: 3196
import itertools

N = int(input())

l = list()
lm = list()
for i in range(N):
    x = int(input())
    l.append(x)
    if x % 10 != 0:
        lm.append(x)

lm = sorted(lm)

a = sum(l)
if a % 10 == 0:
    if lm == []:
        print(0)
    else:
        print(a - lm[0])
else:
    print(a)

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){
		String buffer =sc.nextLine();
		Scanner sc2 = new Scanner(buffer);
		int h = sc2.nextInt();
		int w = sc2.nextInt();
		int[][] map = new int[h][w];
		for(int i = 0 ; i < h ; i++){
			buffer =sc.nextLine();
			for(int j = 0; j < w; j++){
				map[i][j] = buffer.charAt(j) - '0';
			}
		}
		
		int[][] dp = new int[h][w];
		for(int i = 0; i < h ; i++){
			Arrays.fill(dp[i] , Integer.MAX_VALUE >> 2);
		}
		dp[0][0] = map[0][0];
		
		for(int i =0 ; i < h ; i ++){
			for(int j = 0; j < w ; j++){
				if(i==0 && j == 0){
					continue;
				}
				if(i == 0){
					dp[i][j] = Math.min(dp[i][j-1] + map[i][j] , dp[i][j]);
					continue;
				}
				if(j == 0){
					dp[i][j] = Math.min(dp[i-1][j] + map[i][j] , dp[i][j]);
					continue;
				}
				dp[i][j] = Math.min(Math.min(dp[i][j-1] + map[i][j] , dp[i-1][j] + map[i][j] ),dp[i][j]);
			}
		}
		System.out.println(dp[h-1][w-1]);
	}
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}
int n;
string s;
bool dfs(int p){
    //printf("dfs(%d)\n",p);
    if(p>n) return 0;
    if(p==n) return 1;
    bool res=0;
    if(p+4<n&&s.substr(p,5)=="dream") res|=dfs(p+5);
    if(p+4<n&&s.substr(p,5)=="erase") res|=dfs(p+5);
    if(p+5<n&&s.substr(p,6)=="eraser") res|=dfs(p+6);
    if(p+6<n&&s.substr(p,7)=="dreamer") res|=dfs(p+7);
    return res;
}
int main(){
    cin>>s;
    n=s.size();
    /*
    for(int i=0;i<n;){
        if(s.substr(i,5)=="dream"){
            i+=5;
            continue;
        }
        if(s.substr(i,6)=="eraser"){
            i+=6;
            continue;
        }   
        if(s.substr(i,5)=="erase"){
            i+=5;
            continue;
        }
        if(s.substr(i,7)=="dreamer"){
            i+=7;
            continue;
        }
        puts("NO");
        return 0;
    }
    puts("YES");
    */
    cout<<(dfs(0)?"YES":"NO")<<'\n';
}

Measured memory_bytes: 5364
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VI A(N); REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    vector<PLL> ans;
    //REP(i,N-1){
    //    if(i != N-2){
    //        ans.eb(A[0],A[i+1]);
    //    }
    //    else{
    //        ans.eb(A[i+1],A[0]);
    //    }

    //    A[0] -= A[i+1];
    //}
    REP(i,N-2){
        if(A[i+1] < 0){
            ans.eb(A[N-1],A[i+1]);
            A[N-1] -= A[i+1];
        }
        else{
            ans.eb(A[0],A[i+1]);
            A[0] -= A[i+1];
        }
    }
    ans.eb(A[N-1],A[0]);
    cout << A[N-1]-A[0] << endl;
    REP(i,N-1){
        LL x = ans[i].first;
        LL y = ans[i].second;
        cout << x << " " << y << endl;
    }

}

Measured memory_bytes: 3952
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <string.h>

using namespace std;

long long X,Y;
long long cnt;

int main(){
    cin >> X >> Y;
    while(X <= Y){
        X*=2;
        cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
*P, = map(int,input().split())

Q = [p+1 for p in P]

S = [sum(Q[:K])]
for m,p in zip(Q[:N-K],Q[K:]):
    S.append(S[-1]+p-m)
ans = max(S)/2
print(ans)

Measured memory_bytes: 26692
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define fori(a, b, step) for (int i = a; i < b; i += step)
#define forj(a, b, step) for (int j = a; j < b; j += step)
#define int long long

const int maxn = 1e6 + 1, mod = 1e9 + 7;

using namespace std;

int a[maxn], nxt[maxn], ls[maxn];
int t[maxn], ans[maxn];
vector<pi> g[maxn];

void inc(int x, int vl) {
    for (; x < maxn; x += (x & -x))
        t[x] += vl;
}

int get(int r) {
    int ans = 0;
    for (; r > 0; r -= (r & -r))
        ans += t[r];
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q;
    cin >> n >> q;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i <= n; i++)
        ls[i] = -1;
    for (int i = 0; i < n; i++) {
        nxt[i] = ls[a[i]];
        ls[a[i]] = i;
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        g[r].pb({l - 1, i + 1});
        g[l - 1].pb({l - 1, -(i + 1)});
    }
    for (int i = 0; i < n; i++) {
        inc(nxt[i] + 2, 1);
        for (auto gg : g[i + 1]) {
            int cx = gg.r / abs(gg.r);
            gg.r *= cx; --gg.r;
            ans[gg.r] += cx * get(gg.l + 1);
        }
    }
    for (int i = 0; i < q; i++)
        cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 72700
import heapq

N,M = list(map(int,input().split()))
A_tmp = [int(i) for i in input().split()]

#print(A_tmp)
A = [-i for i in A_tmp]

heapq.heapify(A)
#print(A)

for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A, -(-tmp // 2))
  #print(A)

print(-sum(A))


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(br.readLine());
		
		int input[][] = new int[n][3];
		
		for(int i = 0; i < n; i++){
			String[] tmpArray = br.readLine().split(" ");
			for(int j = 0; j < 3; j++){
				input[i][j] = Integer.parseInt(tmpArray[j]);
			}
		}
		
		boolean reachable = true;
		//到達可能チェック
		int currentX = 0;
		int currentY = 0;
		int time = 0;
		for(int i = 0; i < n; i++){
			int dist = Math.abs(currentX - input[i][1]) + Math.abs(currentY - input[i][2]);
			int timeInterval = input[i][0] - time;
			
			if(!(dist <= timeInterval && Math.abs(dist - timeInterval) % 2 == 0)){
				reachable = false;
				break;
			}
		}
		
		if(reachable){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 46772
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    int a[n];
    rep(i, n) scanf("%d", &a[i]);
    sort(a, a+n);
    printf("%d\n", accumulate(a, a+K, 0));
}

Measured memory_bytes: 3828
#include <iostream>
 
using namespace std;
 
const int Height = 1000;
const int Width = 1000;
bool b_map[Height][Width];
int i_map[Height+1][Width+1];
 
int main()
{
    int h, w, n;
    while(cin >> h >> w >> n, h | w | n)
    {
        for(int y=0; y < h; y++)
            for(int x=0; x < w; x++) {
                cin >> b_map[y][x];
                i_map[y][x] = 0;
            }
        for(int y=0; y < h; y++) i_map[y][w] = 0;
        for(int x=0; x < w; x++) i_map[h][x] = 0;
        i_map[0][0] = n - 1;
        for(int y=0; y < h; y++)
            for(int x=0; x < w; x++) {
                if(!i_map[y][x]) continue;
                int num = i_map[y][x] >> 1;
                if(i_map[y][x] & 1) {
                    if(b_map[y][x]) {
                        i_map[y][x+1] += num + 1;
                        i_map[y+1][x] += num;
                    }
                    else {
                        i_map[y][x+1] += num;
                        i_map[y+1][x] += num + 1;
                    }
                    b_map[y][x] = !b_map[y][x];
                }
                else  {
                    i_map[y+1][x] += num;
                    i_map[y][x+1] += num;
                }
            }
        int x, y;
        x = y = 0;
        do {
            if(b_map[y][x])
                x++;
            else
                y++;
        }while(x < w && y < h);
        cout << y+1 << ' ' << x+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 6048
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

for i in range(k):
    # print(t[i::k])
    t0 = t[i]
    cnt = 1
    for t1 in t[i+k::k]:
        if t0 == t1:
            t = t[:i+cnt*k] + 'n' + t[i+cnt*k+1:]
            t0 = 'n'
        else:
            t0 = t1
        cnt += 1

print(p*t.count('r')+r*t.count('s')+s*t.count('p'))


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

using namespace std;

int main()
{
	int N;

	cin >> N;
	
	for(int i = 0; i <= N; i+=4) {
		for(int j = 0; j <= N; j+=7) {
			if(i + j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;

}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = list(str(input()))

alph = ['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']
"""
if len(set(s)) >= 26:
    print("None")
    exit()
for i in alph:
    for j in s:
        if not(i in s):
            print(i)
            exit()
"""

check = [False] * 26
for i in s:
    for j in range(26):
        if i == alph[j]:
            check[j] = True
tmp = 0
for i in range(26):
    if check[i] == False:
        print(alph[i])
        exit()
    if check[i]:
        tmp += 1
if tmp == 26:
    print("None")


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#include <unordered_map>
#define inputarr(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define prllarr(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
#define pb push_back
#define ll long long
#define mod 1000000007
#define foi ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define in(n) scanf("%lld",&n);
#define in2(x,y) scanf("%lld %lld",&(x),&(y));
#define in3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z));
#define out(n) printf("%lld\n",n);
#define out2(x,y) printf("%lld %lld\n",x,y);
#define test(t)  ll t; in(t);while(t--)
#define set(arr,n,s) for(ll i=0;i<n;i++){arr[i]=s;}


ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1){res=(res*x)%p;} y=y>>1;x=(x*x)%p;}return res;}
ll modInverse(ll a,ll p){return power(a,p-2,p);}//used with feemat little

ll gcd(ll x,ll y){if(x==0 || y==0){return max(y,x);}return gcd(y%x,x);}
ll gcdExtended(ll a,ll b,ll &x,ll &y){if(a==0){x=0;y=1;return b;}ll x1,y1;ll gcd = gcdExtended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return gcd;}//o(log(b))
;
void prac(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
   #endif 
}
ll n;
ll arr[21];
ll dp[1<<21];
ll solve(ll mask)
{
	if(mask==(1<<n)-1){
		return 1;
	}
	if(mask>=(1<<n) )return 0;
	if(dp[mask]!=-1)return dp[mask];
	
	ll index=__builtin_popcount (mask);
	// cout<<index;
	ll ans=0;
	for(ll i=0;i<n;i++){
		// cout<<mask<<(1<<i)<<endl;
		// cout<<i<<(arr[index]&(1<<i)) <<((mask&(1<<i))==0LL)<<endl;
		if(arr[index]&(1<<i) && ((mask&(1<<i))==0LL)){
			
			ans+=solve(mask|(1<<i));
			ans%=mod;
		}
	}
	dp[mask]=ans;
	return ans;
}

int main() 
{
  	// prac();
  
    in(n)
    for(ll i=0;i<(1<<n);i++)dp[i]=-1;
    for(ll i=0;i<n;i++){
    	for(ll j=0;j<n;j++){
    		ll x;
    		in(x)
    		if(x){
    			arr[i]|=(1<<j);
    		}
    	}
    }

    ll ans=solve(0);
    //prllarr(arr,7)
    out(ans)




}
/*error-----
convert every int to long long eg-1LL
create array with proper analysis of problem constrain
check mod also
*/






Measured memory_bytes: 16768
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l[] = new int[n];
		for(int i = 0; i < n; i++){
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		int sum = 0;
		for(int i = 0; i < n-1; i++){
			sum+= l[i];
		}
		System.out.print(l[n-1] < sum?"Yes":"No");
	}
}


Measured memory_bytes: 25172
n,k=map(int,input().split())
p=list(map(int,input().split()))
p=[pp+1 for pp in p]
ans=sum(p[0:k])
last=ans
for i in range(n-k):
  tmp=last-p[i]+p[i+k]
  ans=max(ans,tmp)
  last=tmp

ans/=2
print(ans)

Measured memory_bytes: 77448
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    Edge = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, input().split())
        Edge[a-1].append((b-1, c))
        Edge[b-1].append((a-1, c))
    Q, K = map(int, input().split())
    q = deque()
    Dist = [-1] * N
    q.append((K-1, K-1, 0))
    while q:
        nowN, preN, nD = q.popleft()
        if Dist[nowN] == -1:
            Dist[nowN] = nD
            for e, add in Edge[nowN]:
                if e != preN: q.append((e, nowN, nD + add))
    Ans = [None] * Q
    for i in range(Q):
        x, y = map(int, input().split())
        Ans[i] = str(Dist[x-1] + Dist[y-1])
    print("\n".join(Ans))

    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 98772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string A, B, C;
	cin >> A >> B >> C;

	string S;
	S += toupper(A[0]);
	S += toupper(B[0]);
	S += toupper(C[0]);
	co(S);


	Would you please return 0;
}

Measured memory_bytes: 256
//@@@@@@@@@@ JAI BAJRANG BALI @@@@@@@@@
/********** code by naman *******/

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define maxn 10000001
#define endl "\n"
#define im INT_MAX
#define vec vector <ll>
#define mps map <ll,ll>
#define ppl vector<pair<ll,ll>> 
#define fi first
#define si second
#define pr pair<ll,ll> 
#define mvec map<ll,vector <ll>>
  
int main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll flg=0;
    for(ll i=0;i<s.length();i++)
    {
    	if(s[i]=='7')
    	{
    		flg=1;
    		break;
    	}
    }
    if(flg==1)
    	cout<<"Yes"<<endl;
    else
    	cout<<"No"<<endl;

return 0;
}


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

int main()
{
        string s;
        cin >> s;
        int a = (s[0]-'0')*10+s[1]-'0';
        int b = (s[2]-'0')*10+s[3]-'0';
        if(not a and not b)cout <<"NA";
        else if((b <= 12 && a > 12 && b) || ((a == 0) and (b <= 12)))cout <<"YYMM";
        else if((b > 12 && a  && a<= 12) || (b == 0 and a <= 12))cout <<"MMYY";
        else if(a <= 12 and b <= 12)cout << "AMBIGUOUS";
        else cout <<"NA";
        return 0;
}


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

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++) cin >> p[i];
    int count = 0;
    for(int i = 1; i < n - 1; i++){
        if(
            (p[i - 1] < p[i] && p[i] < p[i + 1]) || 
            (p[i - 1] > p[i] && p[i] > p[i + 1])
        ){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
n,a,b,c,d=map(int,input().split())
s=input()[:max(c,d)]
flag=0
if c>d:
    for i in range(b,d+1):
        if [s[i-2],s[i-1],s[i]]==[".",".","."]:flag=1
if c<d:
    if "##" not in s[b:d] and "##" not in s[a:c]:print("Yes")
    else:print("No")
else:
    if "##" in s[b:d] and "##" in s[a:c]:print("No")
    elif flag==1:print("Yes")
    else:print("No")

Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cstdint>
#include <cmath>
using namespace std;

void solve() {
	string s;
	cin >> s;
	map<string, int> m{{"SUN",7},{"MON",6},{"TUE",5},{"WED",4},{"THU",3},{"FRI",2},{"SAT",1}};
	cout << m[s] << endl;
}

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


Measured memory_bytes: 888
#include <stdio.h>

int main() {

    int a = 0;
    char s[4];
    char t[4];

    scanf("%s", s);
    scanf("%s", t);

    for (int i = 0; i < 3 ; i++) {
        if (s[i] == t[i]) {
            a++;
        }
    }

    printf("%d", a);
    return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    int a,b,m,x,y,c;
    cin>>a>>b>>m;
    vi aa(a),bb(b);
    f(i,0,a)cin>>aa[i];
    f(i,0,b)cin>>bb[i];
    int ans=1e9;
    f(i,0,m){
        cin>>x>>y>>c;
        ans=min(ans,aa[x-1]+bb[y-1]-c);
    }
    sort(all(aa));sort(all(bb));
    ans=min(ans,aa[0]+bb[0]);
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
    
int main(){
  int N; cin >> N;
  vector<int> a(N);
  priority_queue<int, vector<int>> pq;
  int MAX, second;
    
   for(int i = 0; i < N; i++){
     cin >> a.at(i);
  pq.push(a.at(i));
   }
     
     MAX = pq.top();
  pq.pop();
	second = pq.top();

 for(int i = 0; i < N; i++){
   if(a.at(i) == MAX)
   cout << second << endl;
   else 
     cout << MAX << endl;
   } 
 }

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

int dp[5005][5005];

int main(){
    int N;
    string S;

    cin >> N >> S;

    for(int i=0; i< N; ++i){
        for(int j=0; j<N; ++j){
            if(S[i]==S[j]){
                if (i==0 || j==0){
                    dp[i][j] = 1;
                } else {
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
            }
        }
    }
    int res = 0;
    for(int i=0; i<N; ++i){
        for(int j=0; j<N; ++j){
            if(i >= j){
                continue;
            }
            int val = min(dp[i][j], j-i);
            res = max(res, val);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 98048
#include<bits/stdc++.h>
using namespace std;
int n,k,t,a[4010],vis[4010][2];
long long fac[4010],g[4010],ans,f[4010][4010][2],p=924844033;
int main() {
   // freopen("permutation.in","r",stdin);
    //freopen("permutation.out","w",stdout);
    cin>>n>>k;
    for(int i=1; i<=n; i++)
        for(int j=0; j<=1; j++)
            if(!vis[i][j]) {
                int x=i,y=j,len=0;
                while(x<=n) {
                    vis[x][y]=1;
                    len++;
                    x+=k;
                    y^=1;
                }t+=len;
                a[t]=1;
            }
    f[1][0][0]=1;
    for(int i=1; i<=t; i++)
        for(int j=0; j<=n; j++) {
            f[i+1][j][0]=(f[i][j][0]%p+f[i][j][1]%p)%p;
            if(!a[i]) f[i+1][j+1][1]=f[i][j][0];
        }
    for(int i=1; i<=n; i++) g[i]=(f[t][i][0]%p+f[t][i][1]%p)%p;
    fac[0]=1;
    for(int i=1; i<=n; i++) fac[i]=fac[i-1]%p*i%p;
    ans=fac[n]%p;
    for(int i=1,j=-1; i<=n; i++,j=-j) ans=(ans%p+p+j%p*g[i]%p*fac[n-i]%p)%p;
    printf("%lld\n",ans%p);
    return 0;
}


Measured memory_bytes: 249728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;



int main() {
    ll n; cin >> n;
    vector<vpl> G(n);
    rep(i,n-1){
        ll a,b,c; cin >> a >> b >> c;
        a--; b--;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
    }
    ll q,k; cin >> q >> k; k--;
    vl d(n,linf);
    d[k] = 0;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.emplace(0,k);
    while(!pq.empty()){
        P p = pq.top(); pq.pop();
        ll u = p.second;
        for(auto v : G[u]){
            if(d[v.first] > d[u] + v.second){
                d[v.first] = d[u] + v.second;
                pq.emplace(d[v.first],v.first);
            }
        }
    }
    //rep(i,n) cout << d[i] << " ";
    cout << endl;
    while(q--){
        ll x,y; cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
}

Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
inline void read(int &x)
{
	char c=getchar();
	x=0;
	while (c>'9'||c<'0')
		c=getchar();
	while (c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
}
const int N=10005;
int n,m,fa[N],v[N],f[N],g[N],x,y,a,b,c,d,flag;
inline int gf(int x)
{
	return fa[x]==x?x:fa[x]=gf(fa[x]);
}
int main()
{
	read(n);
	read(m);
	for (int i=1;i<=1000;++i)
		fa[i]=i;
	for (int i=1;i<=n;++i)
	{
		read(a);
		read(b);
		read(c);
		read(d);
		if (c)
			x=500-c;
		else
			x=500+a;
		if (d)
			y=500+d;
		else
			y=500-b;
		fa[gf(x)]=gf(y);
		++f[x];
		--f[y];
		v[x]=1;
	}
	flag=1;
	for (int i=1;i<500;++i)
		if (f[i]>0)
			flag=0;
	for (int i=501;i<=1000;++i)
		if (f[i]<0)
			flag=0;
	for (int i=1;i<=1000;++i)
		v[gf(i)]|=v[i];
	for (int i=1;i<=1000;++i)
		if (f[i])
			g[gf(i)]=1;
	for (int i=1;i<=1000;++i)
		if (fa[i]==i&&!g[i]&&v[i])
			flag=0;
	puts(flag?"YES":"NO");
	return 0;


}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){

    long int num, i, range, a, b, ans;
    scanf("%ld", &num);

    range = sqrtl(num);

    for(i = 1; i <= range; i++){
        if(num % i == 0){
            a = i;
        }
    }

    b = num / a;

    ans = a + b - 2;

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

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

using namespace std;

int main(){
	int N;
	string str;
	int a[100], b[100];
	while(cin >> N, N){
		cin >> str;
		for(int i=0;i<N;i++) cin >> a[N-i-1] >> b[N-i-1];
		for(int i=0;i<N;i++){
			swap(str[a[i]-1], str[b[i]-1]);
			int d = b[i]-a[i];
			str[a[i]-1] = (str[a[i]-1]-'a'+d)%26+'a';
			str[b[i]-1] = (str[b[i]-1]-'a'+d)%26+'a';
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 0
s = input()

if s == "SUN":
  count = 7
elif s == "MON":
  count = 6
elif s == "TUE":
  count = 5
elif s == "WED":
  count = 4
elif s == "THU":
  count = 3
elif s == "FRI":
  count = 2
elif s == "SAT":
  count = 1
  
print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
  	vector<vector<int>> data(N, vector<int>(2));
  	cin>>N;
	for(int i=0;i<N;i++)
  		for(int j=0;j<2;j++)
          cin>>data.at(i).at(j);
  	int count=0;
  	for(int i=0;i<N-2;i++)
      	if(data.at(i).at(0)==data.at(i).at(1)&&data.at(i+1).at(0)==data.at(i+1).at(1)&&data.at(i+2).at(0)==data.at(i+2).at(1))
          count++;
  	if(count>0)
      cout<<"Yes"<<endl;
  	else
      cout<<"No"<<endl;
  	
  
}

Measured memory_bytes: 4932
#!/usr/bin/env python
while 1:
    T,U,N,E,W,S=1,6,5,3,4,2
    n=int(raw_input())
    if n==0: break
    ans=T
    for i in range(n):
        di=raw_input()
        if di=="North":
            N,T,S,U=T,S,U,N
        elif di=="East":
            E,U,W,T=T,E,U,W
        elif di=="South":
            T,S,U,N=N,T,S,U
        elif di=="West":
            T,E,U,W=E,U,W,T
        elif di=="Left":
            E,S,W,N=S,W,N,E
        elif di=="Right":
            S,W,N,E=E,S,W,N
        else:
            print '[*] Error ->',di
            raise IOError
        ans+=T
    print ans

Measured memory_bytes: 4392
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin>>N;
    vector<int> dp(3);
    for (int day=0; day<N; day++) {
        vector<int> new_dp(3, 0);
        vector<int> c(3);
        for (int i=0; i<3; i++) {
            cin >> c[i];
        }
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                if (i != j) {
                    new_dp[j] = max(new_dp[j], c[j] + dp[i]);
                }
            }
        }
        dp = new_dp;
    }
    
    cout << max({dp[0], dp[1], dp[2]}) << "\n";
    
    return 0;
}


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

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

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

//与えられた数字の先頭の数b と、末尾の数aを取得して、Ｐ型の(a,b)を返す
P f(int x){
	int a  =x % 10 ;//末尾の数
	int b = 0 ;
	while(x){
		b = x ;
		x /= 10;
	}
	return P(a,b);
}
//aで始まりbで終わる数に対してi(bで始まりaで終わる数は条件を満たすものだよ)<-n以下であることはnまでのループであることから分かる。

//Write From this Line

int main()
{
	int n ;
	cin >> n;
	map<P,int> freq;
	for(int i = 1 ; i <= n; i++){
		P p = f(i);
		freq[p] ++;
	}
	ll ans = 0 ; 
	for(int i = 1 ; i<= n ; i++){
		P p = f(i);
		//今、i がaで始まってbで終わる数だとすると、bで始まってaで終わる数の個数をansに＋したい。
		//f(i)は、(b,a)に対応するものとして、iは可能。っていうことを示しているので、逆にここでは、(a,b)に対応して何個可能なものがあるかを見たい。
		//だから、まあとりあえず入れ替えないといけない
		P q(p.second,p.first);
		ans += freq[q];
	}
	cout << ans << endl;
}



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

vector <int> vc;

main()
{
	int n, k, x;
	scanf("%d %d", &n, &k);
	
	vc.pb(0);
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);
		vc.pb(x);
	}
	
	int dp[100005]; dp[1] = 0;
	
	for (int i = 2; i <= n; i++) {
		int minn = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i > j) {
				minn = min(minn, dp[i-j]+abs(vc[i]-vc[i-j]));
			}
		}
		dp[i] = minn;
	}
	
	printf("%lld\n", dp[n]);
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    rep(i, s.size()){
        if(s[i] == '?')s[i] = 'D';
    }
    cout << s << endl;
}

Measured memory_bytes: 3756
// https://atcoder.jp/contests/abc153/tasks/abc153_f

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

#if 0
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(a) if (DEBUG) REP(_i, a.size()) DUMP(a[_i]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(a)
#endif

const int N_MAX = 2*1e5;
const int D_MAX = 1e9;
const int A_MAX = 1e9;
const int X_I_MAX = 1e9;
const int H_I_MAX = 1e9;

int N, D, A;
vector<int> X;
vector<int> H;

map<double, int> mp;
vector<int> k;

int main() {
  cin >> N >> D >> A;
  X = vector<int>(N);
  H = vector<int>(N);
  REP(i, N) cin >> X[i] >> H[i];

  REP(i, N) {
    mp[X[i]] = (i + 1);
    mp[X[i] + D * 2 + 0.5] = -(i + 1);
  }
  k = vector<int>(N);

  ll cur = 0;
  ITR(mp, it) {
    int i1 = it->second;
    int i = abs(i1) - 1;
    if (i1 > 0) {
      k[i] = max((ll) 0, (H[i] + A - 1) / A - cur);
      cur += k[i];
    } else {
      cur -= k[i];
    }
  }

  DUMP(k);

  ll ans = 0;
  REP(i, N) ans += k[i];
  cout << ans << endl;
}


Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, c, k,tm,flg=0,cnt=0,ctmp=0;
	cin >> n >> c >> k;
    vector<int> t(n);
	for(int i=0;i<n;i++)
		cin >> t.at(i);
	sort(t.begin(),t.end());
	for(int i=0;i<n;){
		if(flg==0){
			tm = t.at(i);
			flg=1;
		}
		while(i<n&&(ctmp<c&&t.at(i)<=tm+k)){
				ctmp++;
				i++;
		}
		flg=0;
		ctmp=0;
		cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 640
N = int(input())
W = list(map(int, input().split()))

s_array = []

for i in range(1, N):
    s1 = sum(W[0:i])
    s2 = sum(W[i:N])
    di = abs(s1 - s2)
    
    s_array.append(di)

print(min(s_array))


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    sort(a.begin(),a.end());
    
    int left = a[n/2-1];
    int right = a[n/2];
    
    cout << right - left;
}

Measured memory_bytes: 640