akhauriyash/Code-Regression huggingface dataset:
a,b,c,d=map(int,input().split())
y=c-a
x=d-b
#round1
if(x>0):
  for i in range(x):
    print("U",end="")
else:
  for i in range(-x):
    print("D",end="")
if(y>0):
  for i in range(y):
    print("R",end="")
else:
  for i in range(-y):
    print("L",end="")
    
#round2
if(x>0):
  for i in range(x):
    print("D",end="")
else:
  for i in range(-x):
    print("U",end="")
if(y>0):
  for i in range(y):
    print("L",end="")
else:
  for i in range(-y):
    print("R",end="")
    
#round3
if(x>0):
  if(y>0):
    print("L",end="")
  else:
    print("R",end="")
  for i in range(x+1):
    print("U",end="")
else:
  if(y>0):
    print("L",end="")
  else:
    print("R",end="")
  for i in range(-x+1):
    print("D",end="")
    
if(y>0):
  for i in range(y+1):
    print("R",end="")
  if(x>0):
    print("D",end="")
  else:
    print("U",end="")
else:
  for i in range(-y+1):
    print("L",end="")
  if(x>0):
    print("D",end="")
  else:
    print("U",end="")
    
#round4
if(x>0):
  if(y>0):
    print("R",end="")
  else:
    print("L",end="")
  for i in range(x+1):
    print("D",end="")
else:
  if(y>0):
    print("R",end="")
  else:
    print("L",end="")
  for i in range(-x+1):
    print("U",end="")
if(y>0):
  for i in range(y+1):
    print("L",end="")
  if(x>0):
    print("U",end="")
  else:
    print("D",end="")
else:
  for i in range(-y+1):
    print("R",end="")
  if(x>0):
    print("U",end="")
  else:
    print("D",end="")

Measured memory_bytes: 4596
#include <stdio.h>

#define LIMIT 1000000007

typedef long long ll;

/* n! */
ll factorial(ll n){
    ll x = 1;
    for(ll i=1; i<=n; i++){
        x *= i%LIMIT;
        x %= LIMIT;
    }
    return x;
}

ll nPk(ll n, ll k){
    ll x=1, i;
    for(i=0; i<k; i++){
        x *= (n-i)%LIMIT;
        x %= LIMIT;
    }
    return x;
}

ll modpow(ll a, ll n, ll p){
    if(n==1) return a % p;
    if(n%2 == 1) return (a%p * (modpow(a, n-1, p))%p) % p;

    ll t = modpow(a%p, (n/2)%p, p);
    return ((t%p) * (t%p)) % p;
}

/*

nCk mod(LIMIT) = nPk/k! mod(LIMIT) = X/Y mod(LIMIT)
Y * Y^LIMIT-2 mod(LIMIT) = 1 フェルマーの小定理
>> nCk mod(LIMIT) = X * Y^LIMIT-2 mod(LIMIT)

*/

int main(){
    ll n, a, b;
    ll ans = 0;
    scanf("%lld%lld%lld", &n, &a, &b);

    ans += modpow(2, n, LIMIT) - 1;
    ll x, y;

    x = nPk(n, a)%LIMIT;
    y = factorial(a)%LIMIT;
    ans = (ans - (x * modpow(y, LIMIT-2, LIMIT)) )%LIMIT;

    x = nPk(n, b)%LIMIT;
    y = factorial(b)%LIMIT;
    ans = (ans - (x * modpow(y, LIMIT-2, LIMIT)) )%LIMIT;

    if(ans<0) ans += LIMIT;

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

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int main(void){
    int N, M; cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    for (int i = 0; i < N - M + 1; ++i) {
        for (int j = 0; j < N - M + 1; ++j) {
            bool ok = true;
            for (int a = 0; a < M; a++) {
                for (int b = 0; b < M; b++) {
                    if (A[i + a][j + b] != B[a][b])ok = false;
                }
            }
            if (ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

const int INF = 100000 + 1000;

int calcD(int d) {
    int ans = 0;
    while (d > 0) {
        ans += d % 10;
        d /= 10;
    }
    return ans;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int d = calcD(i);
        if (a <= d && d <= b) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 2000000000;

/* sample input

*/
bool pairCompare(const P& A, const P& B)
{
	bool ret =false ;
	if (A.first > B.first) {
		ret = true;
	}
	else if(A.first == B.first){
		if (A.first > B.second) {
		ret = true;
		}
	}
	
	return ret;
}

int main()
{
	int n, k;
	vector<ll> x, y,xorg,yorg;
	cin >> n >> k;
	x.resize(n);
	xorg.resize(n);
	y.resize(n);
	yorg.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		xorg[i] = x[i];
		yorg[i] = y[i];
	}

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	ll w, h;

	ll answer = (x[n - 1] - x[0])*(y[n - 1] - y[0]);

	for (ll xi = 0; xi < n; xi++) {
		for (ll xj = xi + 1; xj < n; xj++) {
			for (ll yi = 0; yi < n; yi++) {
				for (ll yj = yi + 1; yj < n; yj++) {
					int num = 0;
					for (int i = 0; i < n; i++) {
						if (x[xi] <= xorg[i] && xorg[i] <= x[xj] && y[yi] <= yorg[i] && yorg[i] <= y[yj]) {
							num++;
						}
					}
					if (num >= k) {
						answer = min(answer, (x[xi] - x[xj])*(y[yi] - y[yj]));
					}
				}
			}
		}
	}
	cout << answer;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int MAX=1e5+10;
const ll INF=1e18;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<ll> a(n),b(n+1);
    rep(i,n) {
        cin >> a[i];
        b[i+1]=(a[i]+b[i])%MOD;
    }
    ll ans=0;
    rep(i,n) ans=(ans+a[i]*((MOD+b[n]-b[i+1])%MOD)%MOD)%MOD;
    cout << ans << endl;

    return 0;   
}

Measured memory_bytes: 6400
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#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);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,max_diff = 0,remi;

    cin >> n;
    vector<int>a(n);
    vector<int>answer(n);

    REP(i,n)cin>> a[i];
    
    answer[0]=0;
    REP(i,n){
        if(i%2)answer[0]-=a[i];
        else answer[0]+=a[i];
    }

    FOR(i,1,n){
        answer[i] = (a[i-1]-answer[i-1]/2)*2;
    }

    REP(i,n){
        cout << answer[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>

int main(void)
{
  int a[4], b[4], tmp, flag = 0, i, j;
  
  for(i = 0;i < 4;i++)
  {
    scanf("%d %d", &a[i], &b[i]);
  }
  
  for(i = 1;i <= 4;i++)
  {
    tmp = 0;
    for(j = 0;j < 4;j++)
    {
      if(a[j] == i)
      {
        tmp++;
      }
      if(b[j] == i)
      {
        tmp++;
      }
    }
    
    if(tmp > 2)
    {
      flag = 1;
    }
  }
  
  if(flag)
  {
    printf("NO\n");
  }
  else
  {
    printf("YES\n");
  }
}

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

//子から親を求める演算
auto calc_parent = [](ll x, ll y) { return min(x,y); };
//親遅延配列を子に伝播する演算
auto calc_lazychild = [](ll &x,ll y) { x+=y; };
//遅延配列をノードに反映する演算
auto lazy_to_node = [](ll &x,ll y) { x+=y; };
//遅延配列に値を入れる演算 y-値 l,r-区間index
auto intolazy = [](ll &x,ll y,ll r,ll l) { x+=y; };
//単位元
const ll unit = INF;

struct LazySegTree
{
private:
  ll n;
  vector<ll> node,lazy;
  vector<bool> islazy;

public:
  LazySegTree(vector<ll> v)
  {
    node.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, unit); 
    lazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, 0); 
    islazy.resize((1LL << 64 - __builtin_clzll(v.size())) * 2 - 1, 0); 

    n = 1LL << 64 - __builtin_clzll(v.size());
    for (ll i = 0; i < v.size(); i++)
      node[i + n - 1] = v[i]; //最下段から構築
    for (ll i = n - 2; i >= 0; i--)
      node[i] = calc_parent(node[2 * i + 1], node[2 * i + 2]);
  }
  
  // k 番目のノードについて遅延評価を行う
  void eval(int k, int l, int r){ 
    // 遅延配列が空でない場合、自ノード及び子ノードへの
    // 値の伝播が起こる
    if (islazy[k]){
      lazy_to_node(node[k],lazy[k]);
      // 最下段かどうかのチェック
      if (r - l > 1){
        calc_lazychild(lazy[2 * k + 1],lazy[k]);
        calc_lazychild(lazy[2 * k + 2],lazy[k]);
        islazy[2 * k + 1] = 1;
        islazy[2 * k + 2] = 1;
      }
      // 伝播が終わったので、自ノードの遅延配列を空にする
      islazy[k] = 0;
      lazy[k] = 0;
    }
  }

  void update(int a, int b, ll x, int k = 0, int l = 0, int r = -1){
    if (r < 0)
      r = n;
    // k 番目のノードに対して遅延評価を行う
    eval(k, l, r);
    // 範囲外なら何もしない
    if (b <= l || r <= a)
      return;
    // 完全に被覆しているならば、遅延配列に値を入れた後に評価
    if (a <= l && r <= b){
      intolazy(lazy[k],x,r,l);
      islazy[k] = 1;
      eval(k, l, r);
    }
    // そうでないならば、子ノードの値を再帰的に計算して、
    // 計算済みの値をもらってくる
    else{
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = calc_parent(node[2 * k + 1] , node[2 * k + 2]);
    }
  }

  // 要求区間 [a, b) 中の要素の最小値を答える k := 自分がいるノードのインデックス 対象区間は [l, r) にあたる
  ll get(ll a, ll b, ll k = 0, ll l = 0, ll r = -1)
  {
    // 最初に呼び出されたときの対象区間は [0, n)
    if (r < 0)
      r = n;
    // 要求区間と対象区間が交わらない -> 適当に返す
    if (r <= a || b <= l)
      return unit;
    // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う
    // 関数が呼び出されたら評価！
    eval(k, l, r);
    if (a <= l && r <= b)
      return node[k];
    // 要求区間が対象区間の一部を被覆 -> 子について探索を行う
    // 左側の子を vl ・ 右側の子を vr としている
    // 新しい対象区間は、現在の対象区間を半分に割ったもの
    ll vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
    ll vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
    return calc_parent(vl, vr);
  }
};

int main()
{
ll n , q ;
cin >> n >> q ;

vector<ll> t(n,0);
LazySegTree s(t);
vector<ll> ans;
rep(i,q){
  ll a  ;
  cin >> a  ;
  if(!a){
    ll b , c , d ;
    cin >> b >> c >> d ;
    s.update(b, c+1, d);
  }
  else {
    ll b ,c;
    cin >> b >>c;
    ans.push_back(s.get(b, c+1));
  }
}

rep(i,ans.size())cout<<ans[i]<<"\n";

return 0;
}



Measured memory_bytes: 9348
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(){
   int i,n,v[50];
   float s;
 
   scanf("%d",&n);
   for (i=0;i<n;i++) scanf("%d",&v[i]);
   qsort(v,n,sizeof(int),asc);
   s=v[0];
   for (i=1;i<n;i++) s=(s+v[i])/2.0;
   printf("%f",s);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599)
     {cout<<"8";
     }
    else if(n>=600 && n<=799)
     {cout<<"7";
     }
    else if(n>=800 && n<=999)
     {cout<<"6";
     }
     else if(n>=1000 && n<=1199)
     {cout<<"5";
     }
     else if(n>=1200 && n<=1399)
     {cout<<"4";
     }
     else if(n>=1400 && n<=1599)
     {cout<<"3";
     }
     else if(n>=1600 && n<=1799)
     {cout<<"2";
     }
     else
      {cout<<"1";
      }
    return 0;
}


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

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

using namespace std;

int main() {
  int n, k;
  std::cin >> n >> k;

  double ans = 0.0;
  rep(i, n) {
    int score = i + 1;
    double num = 1.0;
    while (score <= k - 1) {
      score *= 2;
      num /= 2;
    }
    ans += num;
  }
  ans /= n;
  std::cout << fixed << setprecision(10) << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3708
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> PII;
#define MOD (1000000007ll)

int main(void){
	int a,b;
	cin >> a >> b;
	cout << ((a+b+1)/2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n;
pii a[51];
map<pii,int> mpp;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i].fi>>a[i].se;
    sort(a,a+n);
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            mpp[mp(a[j].fi-a[i].fi,a[j].se-a[i].se)]++;
    int ans=0;
    for(map<pii,int>::iterator it=mpp.begin();it!=mpp.end();it++)
        ans=max(ans,it->second);
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

using pqg = priority_queue<ll,vector<ll>, greater<ll> >; // 1,3,5..
using pql = priority_queue<ll,vector<ll> >; //5, 3, 1...

using pqg_p = priority_queue<P,vector<P>, greater<P> >; // 1,3,5..
using pql_p = priority_queue<P,vector<P> >; //5, 3, 1...

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n) for(auto i=s, i##_len=(n); i<i##_len; ++i)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define ALL(a)  (a).begin(),(a).end()

struct Tree {
  vector<int> next;
  ll count=0;
  ll ans=0;
  bool reach = false;
};

int N,Q;
vector<Tree> tr;

void DFS(int n, ll preva) {
  if (tr[n].reach == true) return;

  tr[n].reach = true;
  tr[n].ans = tr[n].count + preva;
  for (auto i : tr[n].next) {
    DFS(i,tr[n].ans);
  }
}


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

  cin >> N  >> Q;


  tr.resize(N+1);

  REP(i,N-1) {
    int a,b;
    cin >> a >> b;
    tr[a].next.PB(b);
    tr[b].next.PB(a);
  }

  REP(i,Q) {
    int a,b;
    cin >> a >> b;
    tr[a].count += b;
  }


  DFS(1,0);

  REP(i,N) {
    if (i == 0) cout << tr[1].ans ;
    else cout << " " << tr[i+1].ans;
  }
  cout << endl;

}


Measured memory_bytes: 24320
import fractions as math

n = int(input())
a = list(map(int, input().split()))

l = [a[0] for _ in range(n+2)]
r = [a[-1] for _ in range(n+2)]

for i in range(n):
    l[i+1] = math.gcd(l[i], a[i])
    r[-(i+2)] = math.gcd(r[-(i+1)], a[-(i+1)])
l[0] = r[0] = l[-1] = r[-1] = 0

ans = [math.gcd(l[i], r[i+2]) for i in range(n)]
print(max(ans))


Measured memory_bytes: 16156
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  ll a,a2, b,s, x=0, inp;
  cin >> a >> b;
  s=a+b;
  a2=a;
  rep(i, n-2){
    cin >> inp;
    x^=inp;
  }
  const int K=45;
  ll dp[K][2][2];
  rep(i, K)rep(j, 2)rep(k, 2){
    dp[i][j][k]=-1;
  }
  dp[0][0][0]=0;
  ll v=1;
  rep(i, K-1){
    int ca=a&1;
    int cx=x&1;
    int cs=s&1;
    int ni=i+1;
    rep(j, 2){
      rep(k, 2){
        if(dp[i][j][k]==-1)continue;
        rep(na, 2)rep(nb, 2){
          if((na^nb)!=cx)continue;
          int ns=na+nb+j;
          if(ns%2!=cs)continue;
          int nj=ns/2;
          int nk;
          if(ca>na){
            nk=0;
          } else if(ca==na){
            nk=k;
          } else {
            nk=1;
          }
          dp[ni][nj][nk]=max(dp[ni][nj][nk], dp[i][j][k]|(v*na));
        }
      }
    }
    a>>=1;
    x>>=1;
    s>>=1;
    v<<=1;
  }
  if(dp[K-1][0][0]<=0 ){
    puts("-1");
  } else {
    cout << a2-dp[K-1][0][0] << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }

vector<ll> a;
ll dp(ll,ll); ll sdp(ll,ll);

//dp
vector<vector<ll>> table;

ll dp(ll n,ll k){
  if(k<0) return 0;
  if(k==0) return 1;
  if(n<0) return 0;
  if(n==0){
    if(a.at(n)>=k) return 1;
    else return 0;
  }
  if(table.at(n).at(k)>-1) return table.at(n).at(k);
  
  table.at(n).at(k)=sdp(n-1,k+1)-sdp(n-1,max((int)(k-a.at(n)),0));
  if(table.at(n).at(k)<0) table.at(n).at(k)+=MOD;
  
  return table.at(n).at(k);
}

//sdp
vector<vector<ll>> stable;

ll sdp(ll n,ll k){
  if(k==0) return 0;
  if(stable.at(n).at(k)>-1) return stable.at(n).at(k);
  
  return stable.at(n).at(k)=(sdp(n,k-1)+dp(n,k-1))%MOD;
}
  
int main()
{
  ll N,K; cin>>N>>K;
  a=vector<ll>(N); rep(i,N) cin>>a.at(i);
  
  //dp
  table=vector<vector<ll>>(N,vector<ll>(K+1,-1));
  //sdp
  stable=vector<vector<ll>>(N,vector<ll>(K+2,-1));
  
  cout<<dp(N-1,K)<<endl;
  /*
  rep(i,N){
    rep(j,K+1){
      if(j!=0) cout<<" ";
      cout<<dp(i,j);
    }
    cout<<endl;
  }
  */
  
  return 0;
}

Measured memory_bytes: 168244
import numpy as np

N = int(input())
S = [input() for i in range(N)]

C = np.zeros(4 , dtype = int)

C[0] = S.count('AC')
C[1] = S.count('WA')
C[2] = S.count('TLE')
C[3] = S.count('RE')

print('AC x',C[0])
print('WA x',C[1])
print('TLE x',C[2])
print('RE x',C[3])

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

#define LL long long

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, x;
	cin >> n >> x;
	if(x == 1 || x == 2*n - 1) {
		cout << "No";
		return 0;
	}

	cout << "Yes" << '\n';
	int d = n - x; n += n-1;
	for(int i=0;i<n;i++)
		cout << (i - d + n) % n + 1 << " ";
}

Measured memory_bytes: 1536
n = gets.to_i
p = []
pos = []
n.times do |i|
  p[i] = gets.to_i-1
  pos[p[i]] = i
end
max = 1
con = 1
for i in 1...n do
  if pos[i-1] < pos[i]
    con += 1
  else
    max = [max, con].max
    con = 1
  end
end
max = [max, con].max

puts n - max

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

using namespace std;

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

    auto gcd = [](long x, long y) {
        if (x < y)
            swap(x, y);
        auto r = x % y;
        while (r) {
            x = y;
            y = r;
            r = x % y;
        }
        return y;
    };
    auto lcm = [&](long x, long y) {return x*y/gcd(x,y);};

    long a, b, c, d; cin>>a>>b>>c>>d;
    a--;
    auto ans = b/c - a/c + b/d - a/d;
    auto cdlcm = lcm(c, d);
    ans -= b/cdlcm - a/cdlcm;
    cout << b-a-ans << endl;

    return 0;
}


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

int main(){
	scanf("%d%d", &n, &k);
	rep(i,n){
		scanf("%d", &a);
		if(a >= k) b++;
	}
	printf("%d\n", b);
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define MOD 1000000007
typedef long long ll;

bool ng[1 << 8];
ll dp[101][1<<8];
string tagc = "TAGC";

bool haveAGC(string str){
	if(str.find("AGC") != string::npos)return true;
	REP(i, str.size() - 1){
		swap(str[i], str[i+1]);
		if(str.find("AGC") != string::npos)return true;
		swap(str[i], str[i+1]);
	}
	return false;
}

void makeNG() {
	REP(i, 1<<8){
		string str = "";
		int now = i;
		REP(j, 4){
			str += tagc[now % 4];
			now /= 4;
		}
		if(haveAGC(str))ng[i] = true;
	}
}

int main(){
	
	makeNG();
	int n;cin >> n;
		
	dp[0][0] = 1;
	REP(i, n){
		REP(j, 1<<8){
			REP(k, 4){
				int nxt = ((j << 2) + k) & ((1 << 8) - 1);
				if(!ng[nxt]){
					dp[i+1][nxt] += dp[i][j];
					dp[i+1][nxt] %= MOD;
				}
			}
		}
	}
		
	ll ans = 0;
	REP(i, 1<<8)ans = (ans + dp[n][i]) % MOD;
	cout << ans << endl;
	
	return 0;
}


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

#define F first
#define S second
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b){
	if (a == 0) return b;
	return gcd(b%a, a);
}

ll lcm(ll a, ll b){
	return (a/gcd(a, b))*b;
}

ll n,a[3004],dp[3000][3000];

ll solve(ll i,ll j)
{
	if(dp[i][j] != -1)
		return dp[i][j];

	if(i==j)
		return dp[i][j] = a[i];

	return dp[i][j] = max(a[i] - solve(i+1,j) , a[j] - solve(i,j-1));
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll i;

	cin >> n;

	for(i=0;i<n;i++)
	{
		cin >> a[i+1];
	}

	memset(dp,-1,sizeof(dp));

	cout << solve(1,n) << endl;
}

Measured memory_bytes: 74084
v = list(map(int, input().split()))
if v[0] > v[1]:
    v[0], v[1] = v[1], v[0]
if v[1] > v[2]:
    v[1], v[2] = v[2], v[1]
if v[0] > v[1]:
    v[0], v[1] = v[1], v[0]
a, b, c = v
print(a, b, c)


Measured memory_bytes: 5600
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};
int dx2[]={1, 1, 0, -1, -1, -1, 0, 1};
int dy2[]={0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int n; cin>>n;
    string s; cin>>s;
    vector<vector<ll>> sum(n+10, vector<ll>(30, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<26; j++){
            if((s[i]-'a') == j){
                sum[i+1][j]=sum[i][j]+1;
            }
            else{
                sum[i+1][j]=sum[i][j];
            }
        }
    }

/*
    for(int i=0; i<26; i++){
        cout << (char)(i+'a') << sum[n][i] << endl;
    }*/

    ll ans=0;
    for(int i=1; i<=n; i++){
        ll asum=1;
        for(int j=0; j<26; j++){
            if(s[i-1]-'a'==j) continue;

            asum*=(sum[n][j]-sum[i][j]+1LL);
            asum%=MOD;
        }
        ans+=asum;
        ans%=MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 27648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 200005;
array<ll, MAX_SIZE> fac, inv, finv;
void finit() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
    finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
    for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;
    
    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

int main() {
    init();
    finit();
    ll N, K;
    cin >> N >> K;
    if(N<K){
        cout << 0 << endl;
        return 0;
    }
    N -= K;

    cout << comb(N+K-1, N) << endl;
}


Measured memory_bytes: 7908
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
 
#define int long long int
#define ld long double
#define mod 1000000007 
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define forn(i,s, e) for (int i = s; i <= e; i++)
#define fornd(i,s, e) for (int i = s ; i >= e; i--)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define print(x) for(auto el: x) cout<<el<<" ";cout<<"\n"
#define PSET(x,y) fixed<<setprecision(y)<<x
// #define bits(x) __builtin_popcount(x)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// void fileio()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }
 
 
template <typename T> 
void swap(T& a, T& b){
    T temp = a;
    a = b;
    b = temp;
}
void selfadd(int& a, int b){
    a = a+b;
    if(a>=mod)
        a = a-mod;
}
void selfsub(int& a, int b){
    a = a-b+mod;
    if(a>=mod)
        a = a-mod;
}  
const int N = 200005; 
 
int dp[10002][103][2];
int D;
 
int rec(string& s, int index,int d, int state){
    
    if(index==s.size()){
        if(d==0)
            return 1;
        else
            return 0;
    }
    if(dp[index][d][state] !=-1){
        return dp[index][d][state];
    }
 
    int a = s[index]-'0';
 
    int ans = 0;
    if(state){
        for(int i=0;i<a;i++){
            selfadd(ans ,rec(s,index+1,(d+i)%D, 0)); 
        }
        selfadd(ans ,rec(s,index+1,(d+a)%D,1));
    }
    else{
        for(int i=0;i<=9;i++){
            selfadd(ans ,rec(s,index+1,(d+i)%D, 0)); 
        }
    }
    // cout<<index<<" "<<d<<" "<<state<<" "<<ans<<endl;
    return dp[index][d][state] = ans;
 
}
 
void solve(){
    
    string s;
    // int D;
    cin>>s;
    cin>>D;
    memset(dp,-1,sizeof(dp));
    cout<<(rec(s,0,0,1)-1+mod)%mod;
}
 
int32_t main()
{
    // fileio();
    fast;
    // int t;
    // cin>>t;
    // for(int y=1;y<=t;y++)
    {
        // cout<<"Case #"<<y<<": ";
        solve();
    }
    return 0;
} 

Measured memory_bytes: 17152
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <math.h>
 
using namespace std;
 
int main(){

	int m;
	int f;
	int r;
  
  	while(1){
    	cin >> m >> f >> r;
      
      	if(m==-1 && f==-1 && r==-1)
          break;
      
      	else if(m == -1 || f == -1 || m+f <30)
          cout << "F" << endl;
      	else if(m+f >= 80)
          cout << "A" << endl;
      	else if(m+f >= 65 && m+f <80)
          cout << "B" << endl;
      	else if(m+f >= 50 && m+f <65 || r >=50)
          cout << "C" << endl;
      	else if(m+f >= 30 && m+f <50 && r < 50)
          cout << "D" << endl;
      	
    }

  
  return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename L, typename R>
ostream& operator<<(ostream& out, const pair<L, R>& p) {
    out << "(" << p.first << ", " << p.second << ")";
    return out;
}

template <typename L, typename R>
istream& operator>>(istream& in, pair<L, R>& p) {
    in >> p.first >> p.second;
    return in;
}

const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;

#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                                  \
    ({                                                         \
        if (1) cerr << "TR: " << (#X) << " = " << (X) << endl; \
    })
#define LL(name) \
    ll name;     \
    cin >> name;
#define VL(name, num) \
    vl name(num);     \
    FOR(INPUT_VL_I, 0, num) { cin >> name[INPUT_VL_I]; }

ll median(vl& vec) {
    nth_element(vec.begin(), vec.begin() + sz(vec) / 2, vec.end());
    ll res = vec[sz(vec) / 2];
    if (sz(vec) % 2 == 0) {
        nth_element(vec.begin(), vec.begin() + sz(vec) / 2 - 1, vec.end());
        res = res + vec[sz(vec) / 2 - 1];
    }
    return res;
}

int main() {
    cin.sync_with_stdio(0);
    LL(N);
    vl As(N), Bs(N);
    FOR(i, 0, N) { cin >> As[i] >> Bs[i]; }

    const ll mA = median(As);
    const ll mB = median(Bs);

    cout << (mB - mA + 1) << endl;

} // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
using namespace std;
ll ass[13]={0};
ll dp[13][13][100001];
ll findo(ll cur,ll pre,ll prec){
	ll ans=0;
	if(pre==13)return cur==5;
	if(dp[cur][pre][prec]!=-1)return dp[cur][pre][prec];
	

	if(ass[pre]==0){ans+=findo(cur,pre+1,0);ans%=pri;}
	else{
	for(ll i=0;i<=9;i++){
		if(prec==ass[pre]-1)ans+=findo((cur+i*pre)%13,pre+1,0);
		else ans+=findo((cur+i*pre)%13,pre,prec+1);
		ans%=pri;
	}}
	
	return dp[cur][pre][prec]=ans;
	
}


void run(){
string a;
cin>>a;
ll n=a.length();
reverse(all(a));
ll pre=0;
for(ll i=0;i<13;i++){
	for(ll j=0;j<13;j++){
		for(ll k=0;k<100001;k++)dp[i][j][k]=-1;
	}
}
ll c=1;
for(ll i=0;i<n;i++)
{
	if(a[i]=='?')ass[c]++;
	else pre=(pre+c*(a[i]-'0'))%13;
	c=(c*10)%13;
}
//for(ll i=0;i<13;i++)cout<<ass[i]<<endl;
//cout<<pre<<endl;
cout<<findo(pre,0,0);




}
int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 141824
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	b := make([]int, n)
	for i := 0; i < n; i++ {
		x := n / 2
		if n%2 == 0 {
			if i%2 == 0 {
				x += i / 2
			} else {
				x -= (i + 1) / 2
			}
		} else {
			if i%2 == 1 {
				x += (i + 1) / 2
			} else {
				x -= i / 2
			}
		}
		b[x] = nextInt()
	}

	for i := range b {
		if i < n-1 {
			putf("%d ", b[i])
		} else {
			putf("%d\n", b[i])
		}
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 7040
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

constexpr int INF = numeric_limits<int>::max();

int N;
int G[100][100];

void solve()
{
    vector<int> cost(N);
    deque<bool> done(N);

    fill(begin(cost), end(cost), INF);
    cost[0] = 0;

    for(;;) {
        int mincost = INF;
        int minv    = -1;

        REP(v, N) {
            if(done[v]) continue;
            if(cost[v] < mincost) {
                mincost = cost[v];
                minv    = v;
            }
        }

        if(minv == -1) break;

        done[minv] = true;

        REP(v, N) {
            if(done[v]) continue;
            if(G[minv][v] == -1) continue;
            int cost_new = cost[minv] + G[minv][v];
            if(cost_new < cost[v]) {
                cost[v] = cost_new;
            }
        }
    }

    REP(v, N) {
        cout << v << " " << cost[v] << "\n";
    }
}

int main()
{
    cin >> N;
    REP(from, N) {
        REP(to, N) {
            G[from][to] = -1;
        }
    }

    REP(_, N) {
        int from, k;
        cin >> from >> k;
        REP(_, k) {
            int cost, to;
            cin >> to >> cost;
            G[from][to] = cost;
        }
    }

    solve();

    return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int x,a,b;
	cin >> x >> a >> b;
	if(abs(x-a)<abs(x-b)){
		cout << "A" << endl;
	}
	else{
		cout << "B" << endl;
	}
}

Measured memory_bytes: 256
h, w = map(int, input().split())

la = ["."] * (w+2)
lz = ["."] * (w+2)

l = list()
l.append(la)

for i in range(h):
    l.append(["."] + list(input()) + ["."])

l.append(lz)

for i in range(1, h+1):
    for j in range(1, w+1):
        if l[i][j] == "#":
            if l[i-1][j] == "." and l[i+1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 3064
# 解説と提出#12551970を参考に作成
# 今いる都市と銀貨の所持数を状態として、
#   ①その都市から移動可能な別の都市に移動する
#   ②金貨を銀貨に交換する
# のどちらかを行い、実施後の(同都市・同所持銀貨枚数での)最小時間を計測していく。
# 最小時間が更新された場合、さらにその状態から①・②を行う。
# これによって全都市・全銀貨所持枚数毎の最小時間を割り出す。
# 都市の銀貨所持枚数毎の最小時間の中での最小時間がその都市へ行くための最小時間になる。
#   ※1: 都市への移動は移動可能な枚数の銀貨を持っている場合のみ可能
#   ※2: 銀貨の最大所持枚数は (N - 1) * max(Ai) とする
#        -> 一番遠い都市に移動する場合にかかりうる最大の銀貨枚数

from heapq import heappop, heappush


def solve():
    n, m, s = map(int, input().split())
    graph = [[] for _ in range(n)]
    # グラフ作製
    max_a = 0
    for _ in range(m):
        u, v, a, b = map(int, input().split())
        graph[u - 1].append([v - 1, a, b])
        graph[v - 1].append([u - 1, a, b])
        max_a = max(max_a, a)
    ce = [[int(i) for i in input().split()] for _ in range(n)]
    # 初期値マップ作製
    maxSilver = max_a * (n - 1)  # max(a) * (n - 1)
    inf = float('inf')
    ns_map = [[inf] * (maxSilver + 1) for _ in range(n)]
    # スタート時の値設定と探索
    q = [[0, 0, min(maxSilver, s)]]  # 累計時間, 都市, 所持銀貨
    ns_map[0][min(maxSilver, s)] = 0  # スタート地点の時刻は0
    while q:
        ti, ni, si = heappop(q)
        # 移動
        for g in graph[ni]:
            n2, ai, bi = g
            if si >= ai and ns_map[n2][si - ai] > ti + bi:
                ns_map[n2][si - ai] = ti + bi
                # ★heapq で累計時間が少ない情報から先に処理するようにする.
                # これによって処理速度が全然違う
                heappush(q, [ti + bi, n2, si - ai])
        # 換金
        ci, di = ce[ni]
        ti += di
        si = min(si + ci, maxSilver)
        if ns_map[ni][si] > ti:
            ns_map[ni][si] = ti
            heappush(q, [ti, ni, si])
    for i in range(1, n):
        print(min(ns_map[i]))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 28156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		char[] marks = {'S', 'H', 'C', 'D'};
		for(char mark : marks) {
			for (int i = 1; i <= 13; i++) {
				Card.allCards.add(new Card(mark, i));
			}
		}

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			String[] str = br.readLine().split(" ");
			Iterator<Card> itr = Card.allCards.iterator();
			while (itr.hasNext()) {
				Card tmp = itr.next();
				if (tmp.mark != str[0].charAt(0)) {
					continue;
				}
				if (tmp.rank == Integer.parseInt(str[1])) {
					itr.remove();
				}
			}
		}

		for (Card card : Card.allCards) {
				System.out.println(card.mark + " " + card.rank);
		}
	}
}

class Card {
	char mark;
	int rank;
	static List<Card> allCards = new ArrayList<Card>();

	Card(char mark, int rank) {
		this.mark = mark;
		this.rank = rank;
	}
}

Measured memory_bytes: 16952
#include <iostream>

using namespace std;

long long pow(long long x) {
  return x * x * x * x * x;
}


int main(int argc, char* argv[]) {
  long long X;
  cin >> X;

  for (int i = -500; i < 500; ++i) {
    for (int j = -500; j < 500; ++j) {
      if (pow(i) - pow(j) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	cin >> N;

	cout << fixed << setprecision(20) << (ldbl)(N/2 + (N&1)) / N << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int w,h;
int dx[4]={0,1};
int dy[4]={1,0};
int memo[101][101][2][2];
int solve(int x,int y,int fi,int fl){
  int ans=0;
  int i;
  int temp=fl;
  // printf("%d %d f..%d\n",x,y,fl);
  if(memo[x][y][fi][fl]!=-1){
    //printf("re..%d\n",memo[x][y][fi][fl]);
    return memo[x][y][fi][fl];
  }

  if(x>=w && y>=h){
    //printf("re..%d\n",1);
    return 1;
  }
  for(i=0;i<2;i++){
    fl=temp;
    if(x+dx[i] > w || y+dy[i] > h) continue;

    if(fi==-1){}
    else if(i!=fi && fl==1)
      continue;
    else if(i!=fi && fl==0)
      fl=1;
    else
      fl=0;

    ans+=solve(x+dx[i],y+dy[i],i,fl)%100000;
  }
  memo[x][y][fi][temp]=ans%100000;
  return ans%100000;
}
main(){
  int ans;
  while(1){
    scanf("%d %d",&w,&h);
    if(w==0 && h==0) break;
    memset(memo,-1,sizeof(memo));
    ans=solve(1,1,-1,0);
    printf("%d\n",ans%100000);
  }
  return 0;
}

Measured memory_bytes: 0
<?php
while ( ! feof(STDIN) ){
    $v = trim(fgets(STDIN));
    if($v !== ""){
        $lines[] = $v;
    }
}

array_pop($lines);

while(count($lines) > 0){
    $lines = array_values($lines);
    $loopCount = $lines[0];
    unset($lines[0]);

    $dataSet = array_slice($lines,0,$loopCount);
    $dataCount = array_count_values($dataSet);
    array_splice($lines,0,$loopCount);

    for($i=0;$i<10;++$i){
        if(!empty($dataCount[$i])){
            echo str_repeat("*",$dataCount[$i])."\n";
        }else{
            echo "-\n";
        }
    }
}



Measured memory_bytes: 17820
n, k = map(int, input().split())
MOD = 10**9 + 7
table = [0 for i in range(n+1)]
for i in range(1, n+1):
    table[i] = (table[i-1] + i) % MOD
ans = 0
for i in range(k, n+2):
    ans += (i * n - 2 * table[i-1] + 1) % MOD
print(ans % MOD)

Measured memory_bytes: 79416
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    sum_a = 0
    count = 0
    for i in a:
        sum_a += i

    for j in a:
        if j >= (sum_a / (4 * m)):
            count += 1
    if count >= m:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"math"
	"sort"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const IDEAL = 22

type Person struct {
	Id int
	Weight float64
	Height float64
	BMI float64
}

type LessFunc func(p1, p2 *Person) bool
type multiSorter struct {
	People []Person
	less []LessFunc
}
func (ms *multiSorter) Sort(people []Person) {
	ms.People = people
	sort.Sort(ms)
}
func OrderBy(less ...LessFunc) *multiSorter {
	return &multiSorter{
		less: less,
	}
}
func (ms *multiSorter) Len() int {
	return len(ms.People)
}
func (ms *multiSorter) Swap(i, j int) {
	ms.People[i], ms.People[j] = ms.People[j], ms.People[i]
}
func (ms *multiSorter) Less(i, j int) bool {
	p, q := &ms.People[i], &ms.People[j]
	var k int
	for k = 0; k < len(ms.less); k++ {
		less := ms.less[k]
		switch {
		case less(p, q):
			return true
		case less(q, p):
			return false
		}
	}
	return ms.less[k](p, q)
}

func main() {
	id := func(p1, p2 *Person) bool {
		return p1.Id < p2.Id
	}
	bmi := func(p1, p2 *Person) bool {
		return math.Abs(p1.BMI-22) < math.Abs(p2.BMI-22)
	}
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		People := make([]Person, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			tmpid, _ := strconv.Atoi(buf[0])
			tmpheight, _ := strconv.ParseFloat(buf[1], 64)
			tmpweight, _ := strconv.ParseFloat(buf[2], 64)
			People = append(People,
			 		Person{tmpid,
			 		tmpheight/100,
			 		tmpweight,
			 		tmpweight/(tmpheight/100*tmpheight/100)})
		}
		OrderBy(bmi, id).Sort(People)
		// bestID := People[0].Id
		bestBMI := People[0].BMI
		for _, p := range People {
			if p.BMI == bestBMI {
				fmt.Println(p.Id)
			}
		}
	}
}


Measured memory_bytes: 1432
io = STDIN
n,$a,$b,$c=io.gets.split.map(&:to_i)
ar=n.times.map{io.gets.to_i}
def mp(hist)
  (hist[0].size-1)*10+(hist[0].inject(0){|s,i|s+i}-$a).abs+
  (hist[1].size-1)*10+(hist[1].inject(0){|s,i|s+i}-$b).abs+
  (hist[2].size-1)*10+(hist[2].inject(0){|s,i|s+i}-$c).abs
end
$ans=Float::INFINITY
def dfs(stick,hist)
  if stick==[]
     if (hist[0].size>0 &&
        hist[1].size>0 &&
        hist[2].size>0)
       $ans = [mp(hist),$ans].min
     end
     return
  end
  4.times do |i|
    hist[i] << stick[0]
    dfs(stick[1..-1],hist)
    hist[i].pop
  end
end
dfs(ar,[[],[],[],[]])
p $ans


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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000009
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

set<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	set<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.insert(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}

// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!
	string s;
	cin >> s;
	int sum = 0;
	for (char c : s)
	{
		sum += (c - '0');
	}
	if (sum % 9 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

Measured memory_bytes: 3756