akhauriyash/Code-Regression huggingface dataset:
n,C=map(int,input().split())
que=[]
for _ in range(n):
    x,v=map(int,input().split())
    que.append((x,v))

dpl=[0 for i in range(n+1)] #dpl[i]=左からi番目に行くまでのお腹の値のプラス
dpr=[0 for i in range(n+1)] #dpr[j]＝右からj番目に行くまでのお腹の値のプラス

c=0
for i in  range(n):
    c+=que[i][1]
    dpl[i+1]=c-que[i][0]

d=0
for i in range(1,n+1):
    d+=que[-i][1]
    dpr[i]=d-(C-que[-i][0])

max1=max(dpl)
max2=max(dpr)

dpb_l=[0 for i in range(n+1)]#dpb_l[i]=左からi番目に行って戻るときに達成できるお腹の値のプラス
dpb_r=[0 for i in range(n+1)]#dpb_r[i]=右からi番目に行って戻るときに達成できるお腹の値のプラス

c=0

for i in  range(n):
    c+=que[i][1]
    dpb_l[i+1]=c-2*que[i][0]

d=0
for i in range(1,n+1):
    d+=que[-i][1]

    dpb_r[i]=d-2*(C-que[-i][0])

#dpl[i]=左からi番目のところに行くまでに達成できるお腹の値のプラスの最大値
#dpr[i]=右からi番目のところに行くまでに達成できるお腹のあたいのプラスの最大値

for i in range(1,n+1):
    dpl[i]=max(dpl[i-1],dpl[i])
for i in range(1,n+1):
    dpr[i]=max(dpr[i],dpr[i-1])

max3=0

for i in range(1,n):
    max3=max(max3,dpb_l[i]+dpr[n-i],dpb_r[i]+dpl[n-i])

print(max(max1,max2,max3))




Measured memory_bytes: 32472
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<deque>
using namespace std;
typedef long long ll;
ll n;
deque<int>x,y;
int t=2;
int main()
{
    scanf("%lld",&n);
    n++;
    int cnt=0;
    int f=0;
    while(1ll<<(f+1)<=n)
        f++;
    for(int i=f;i>=0;i--){
        if(i!=f&&n&1ll<<i){
            t++;
            cnt+=2;
            x.push_front(t);
            y.push_back(t);
        }
        if(i>0){
            t++;
            cnt+=2;
            x.push_front(t);
            y.push_front(t);
        }
    }
    printf("%d\n",cnt);
    while(!x.empty()){
        printf("%d ",x.front());
        x.pop_front();
    }
    while(!y.empty()){
        printf("%d ",y.front());
        y.pop_front();
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
char a[10005];
int main()
{
	int n,k,x,y,sum=0;
	cin>>n>>k>>x>>y;
	if(k>n)
	{
		sum=x*n;
	}
	else sum=k*x+(n-k)*y;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int a = S[0] -'0', b = S[1] - '0', c = S[2] - '0', d = S[3] - '0';
    if(a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d;
    else if (a + b + c - d == 7)cout << a << "+" << b << "+" << c << "-" << d;
    else if (a + b - c - d == 7)cout << a << "+" << b << "-" << c << "-" << d;
    else if (a - b - c - d == 7)cout << a << "-" << b << "-" << c << "-" << d;
    else if (a + b - c + d == 7)cout << a << "+" << b << "-" << c << "+" << d;
    else if (a - b - c + d == 7)cout << a << "-" << b << "-" << c << "+" << d;
    else if (a - b + c + d == 7)cout << a << "-" << b << "+" << c << "+" << d;
    else if (a - b + c - d == 7)cout << a << "-" << b << "+" << c << "-" << d;
    cout << "=7" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define si set <ll>
#define vi vector <ll>
#define popcount(x) __builtin_popcountll(x)
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,n) for( ll i=a ; i<n ; i++)
#define ld long double
#define rall(a) (a).rbegin(),(a).rend()

ll power(ll b,ll e,ll m)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b%m,e/2,m)%m;
  return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
  if(e==0) return 1;
  if(e&1) return b*power(b*b,e/2);
  return power(b*b,e/2);
}  
bool isPowerOfTwo(ll x)
{
    // x will check if x == 0 and !(x & (x - 1)) will check if x is a power of 2 or not
    return (x && !(x & (x - 1)));
} 

void solve()
{
  ll x,y;
  cin>>x>>y;
  if(x<=y) cout<<"unsafe"<<"\n";
  else cout<<"safe"<<"\n";
}


int main()       
{
  fastio
  ll tt=1;
  // cin>>tt;
  while(tt--)
  {
    solve();
    cout<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3548
#include <iostream>

using namespace std;

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int numMinutes = (h2 - h1) * 60 + (m2 - m1);
  int ans = numMinutes - k;
  if (ans < 0)
    ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    while(1) {
        cin >> n;
        if(n == 0) break;
        int w, h; cin >> w >> h;
        vector< vector<int> > smap(h, vector<int>(w, 0));
        for(int i = 0; i < n; ++i) {
            int x, y; cin >> x >> y;
            x--; y--;
            smap[y][x] = 1;
        }
        int ss, tt; cin >> ss >> tt;
        vector< vector<int> > s(h+1, vector<int>(w+1, 0));
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                s[i+1][j+1] = s[i][j+1] + s[i+1][j] - s[i][j] + smap[i][j];
            }
        }
    
        int ans = 0;
        for(int i = 0; i < h; ++i) {
            for(int j = 0; j < w; ++j) {
                int x1 = j, x2 = j+ss;
                int y1 = i, y2 = i+tt;
                if(x2 <= w && y2 <= h) {
                    int sum = s[y2][x2] - s[y2][x1] - s[y1][x2] + s[y1][x1];
                    chmax(ans, sum);
                }
            }
        }
        cout << ans << endl;
    }
}


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

int c[200009];
long long p[200009], d[200009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	d[0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
		if (c[i] == c[i - 1]) {
			d[i] = d[i - 1]; continue;
		}
		p[c[i]] = (p[c[i]] + d[i - 1]) % 1000000007LL;
		d[i] = p[c[i]];
	}
	cout << d[n] << '\n';
	return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int N;
    ll K;
    cin >> N >> K;
    ve<ve<int>> G(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    
    
    queue<pii> Q;
    Q.push({0,-1});
    ll ans = 0;
    ans = K;
    
    while (!Q.empty()) {
        pii u = Q.front();
        Q.pop();
        
        for (int v : G[u.fi]) {
            if(v == u.se) continue;
            Q.push({v,u.fi});
        }
        ll aa = G[u.fi].size();
        if(u.fi != 0) aa--;
        if(u.fi == 0){
            for (ll bb = K-1; bb > K-1-aa; bb--) {
                ans *= bb;
                ans %= mod;
            }
        }else{
            for (ll bb = K-2; bb > K-2-aa; bb--) {
                ans *= bb;
                ans %= mod;
                
            }
        }
        
        
    }
    cout << ans << endl;

    
    
    
    

    return 0;
}


Measured memory_bytes: 6904
#include <stdio.h>

int n, A[50];

int Search(int, int);

int main()
{
  int i, q, m;

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);

  for( i = 0 ; i < q ; i++ ){
    scanf("%d", &m);
    if( search(0,m) ) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

int search(int i, int m)
{
  int sea;

  if( m == 0 ) return 1;
  if( i >= n ) return 0;
  
  sea = search(i+1, m) || search(i+1, m-A[i]);
  
  return sea;
}

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

int main(){
	long long a,n,k; cin>>n>>k;
	a=1;
	for(int i=0;i<n;i++){
		if(a*2<a+k) a*=2;
		else a+=k;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  string s, t; cin >> s >> t;
  string tt{t.rbegin(), t.rend()};
  auto ans = s == tt ? "YES" : "NO";
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#coding:utf-8
import numpy as np
def divisor(n,m):
    arr = []
    for i in range(1,(int(np.sqrt(m))+1)):
        if m % i == 0:
            if i <= m/n:
                arr.append(i)
            if m/i <= m/n:
                arr.append(int(m/i))
    return arr



n,m = list(map(int,input().split()))
print (max(divisor(n,m)))


Measured memory_bytes: 21624
#include<stdio.h>
bool rangeCheck(int x,int y){
    if(x >= 0 && x <= 9 && y>=0 && y <= 9)return true;
    else{
        return false;
    }
}
int main(){
	int x,y,s,i,j;
	int p[10][10];
	for(i=0;i<10;i++)
		for(j=0;j<10;j++)
			p[i][j]=0;
	while(~scanf("%d,%d,%d",&x,&y,&s)){
		if(s==1){
			p[x][y]++;            
			if(rangeCheck(x,y-1))p[x][y-1]++;
            if(rangeCheck(x,y+1))p[x][y+1]++;
            if(rangeCheck(x-1,y))p[x-1][y]++;
            if(rangeCheck(x+1,y))p[x+1][y]++;}
		if(s==2){
			p[x][y]++;            
			if(rangeCheck(x-1,y-1))p[x-1][y-1]++;
            if(rangeCheck(x,y-1))p[x][y-1]++;
            if(rangeCheck(x+1,y-1))p[x+1][y-1]++;
            if(rangeCheck(x-1,y))p[x-1][y]++;
            if(rangeCheck(x+1,y))p[x+1][y]++;
            if(rangeCheck(x-1,y+1))p[x-1][y+1]++;
            if(rangeCheck(x,y+1))p[x][y+1]++;
            if(rangeCheck(x+1,y+1))p[x+1][y+1]++;}
		if(s==3){
			p[x][y]++;
		    if(rangeCheck(x-1,y-1))p[x-1][y-1]++;
            if(rangeCheck(x,y-1))p[x][y-1]++;
            if(rangeCheck(x+1,y-1))p[x+1][y-1]++;
            if(rangeCheck(x-1,y))p[x-1][y]++;
            if(rangeCheck(x+1,y))p[x+1][y]++;
            if(rangeCheck(x-1,y+1))p[x-1][y+1]++;
            if(rangeCheck(x,y+1))p[x][y+1]++;
            if(rangeCheck(x+1,y+1))p[x+1][y+1]++;
            if(rangeCheck(x,y-2))p[x][y-2]++;
            if(rangeCheck(x-2,y))p[x-2][y]++;
            if(rangeCheck(x+2,y))p[x+2][y]++;
            if(rangeCheck(x,y+2))p[x][y+2]++;}}
	int max=0,sum=0;
	for(i=0;i<10;i++)
		for(j=0;j<10;j++){
			if(p[i][j]>max)max=p[i][j];
			if(p[i][j]==0)sum++;}
	printf("%d\n%d\n",sum,max);
	return 0;}


Measured memory_bytes: 2596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  string S,T;
  cin>>S>>T;
  sort(S.begin(),S.end());
  sort(T.rbegin(),T.rend());
  int SL=S.size(),TL=T.size();
  int i=0;
  while(S[i]==T[i]&&i<SL){
    i++;
  }
  if(SL<TL&&i==SL){
    cout<<"Yes"<<endl;
  }else if(S[i]<T[i]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

// xが8子以上でout
signed main() {
    string str;
    cin >> str;
    int num = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'x') num++;
    }

    if (num >= 8) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}

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

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

         r=N%10;

         if(r==2||r==4||r==5||r==7||r==9)
                  cout<<"hon"<<endl;
         else if(r==0||r==1||r==6||r==8)
                  cout<<"pon"<<endl;
         else if(r==3)
                  cout<<"bon"<<endl;
                  return 0;




}


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

int main() {
  ll x=1;
  for(int i=1; i<=7; i++) x*=i;
  int n;
  while(cin >> n && n) {
    ll ans=0;
    if(n%2) {
      ll dp[n][8];
      memset(dp,0,sizeof(dp));
      dp[0][0]=1;
      for(int i=2; i<n-1; i++) {
        for(int j=7; j>0; j--) {
          for(int k=0; k<i-1; k++) {
            dp[i][j]+=dp[k][j-1];
          }
        }
        ans+=dp[i][7];
      }
    } else {
      ll dp[n/2][8][3];
      memset(dp,0,sizeof(dp));
      dp[0][0][0]=1;
      for(int i=1; i<n/2; i++) {
        for(int j=7; j>=0; j--) {
          if(j<7) {
            dp[i][j+1][0]+=dp[i-1][j][1]+dp[i-1][j][2];
            dp[i][j+1][1]+=dp[i-1][j][0]+dp[i-1][j][2];
          }
          dp[i][j][2]+=dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2];
        }
        ans+=dp[i][7][0];
        if(i<n/2-1) ans+=dp[i][7][1];
      }
    }
    cout << ans*n*x << endl;
  }
  return 0;
}

Measured memory_bytes: 3016
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
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; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    string s; cin >> s;
    ll q; cin >> q;
    vector<ll> k(q);
    REP(i, q) cin >> k[i];

    REP(t, q) {

        ll ans = 0;
        ll dnum = 0, mnum = 0, dmnum = 0;
        REP(i, n) {
            if (i - k[t] >= 0) {
                switch (s[i-k[t]]) {
                    case 'D':
                        --dnum;
                        dmnum -= mnum;
                        break;
                    case 'M':
                        --mnum;
                        break;
                    case 'C':
                        // do nothing
                        break;
                }
            }
            switch (s[i]) {
                case 'D':
                    ++dnum;
                    break;
                case 'M':
                    ++mnum;
                    dmnum += dnum;
                    break;
                case 'C':
                    ans += dmnum;
                    break;
            }
        }
        cout << ans << endl;

    }
    
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;

void warshall_floyd(vector<vector<long long>> &_Date){
    for(int k = 0; k < _Date.size(); ++k){
        for(int i = 0; i < _Date.size(); ++i){
            for(int j = 0; j < _Date.size(); ++j){
                _Date[i][j] = min(_Date[i][j], _Date[i][k] + _Date[k][j]);
            }
        }
    }
}

int main(){
    int N, M, Q;
    long long L;
    cin >> N >> M >> L;
    vector<vector<long long>> dist(N, vector<long long>(N, INF));
    
    for(int i = 0; i < M; ++i){
        int a, b;
        long long c;
        cin >> a >> b >> c;
        --a;
        --b;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    
    warshall_floyd(dist);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            dist[i][j] = ((dist[i][j] <= L) ? 1 : INF);
        }
    }
    warshall_floyd(dist);
    
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int s, g;
        cin >> s >> g;
        --s;
        --g;
        long long ans = ((dist[s][g] == INF) ? -1 : dist[s][g] - 1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()

	if c-(a-b) > 0 {
		fmt.Println(c - (a - b))
	} else {
		fmt.Println(0)
	}

}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1772
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define mod 998244353
#define inv2 499122177
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int Add(int a, int b)
{
	int c = a + b;
	if (c >= mod)
		c -= mod;
	return c;
}
int Sub(int a, int b)
{
	int c = a - b;
	if (c < 0)
		c += mod;
	return c;
}
int Pow(int a, int k)
{
	if (!k)
		return 1;
	int p = Pow(a, k / 2);
	if (k & 1)
		return (ll)p * p % mod * a % mod;
	return (ll)p * p % mod;
}
int A[1 << 18], B[1 << 18], C[1 << 18], D[1 << 18];
int n, s;
void FWT(int *A, int w)
{
	if (w == 1)
		return;
	FWT(A, w >> 1);
	FWT(A + (w >> 1), w >> 1);
	for (int i = 0; i < (w >> 1); i++)
	{
		int x = A[i], y = A[i + (w >> 1)];
		A[i] = Add(x, y);
		A[i + (w >> 1)] = Sub(x, y);
	}
}
void IFWT(int *A, int w)
{
	if (w == 1)
		return;
	IFWT(A, w >> 1);
	IFWT(A + (w >> 1), w >> 1);
	for (int i = 0; i < (w >> 1); i++)
	{
		int x = A[i], y = A[i + (w >> 1)];
		A[i] = (ll)Add(x, y) * inv2 % mod;
		A[i + (w >> 1)] = (ll)Sub(x, y) * inv2 % mod;
	}
}
int main()
{
	Read(n);
	for (int i = 0; i < (1 << n); i++)
		Read(D[i]), s = Add(s, D[i]);
	s = Pow(s, mod - 2);
	for (int i = 0; i < (1 << n); i++)
		A[i] = D[i] = (ll)D[i] * s % mod;
	B[0] = (1 << n) - 1;
	for (int i = 1; i < (1 << n); i++)
		B[i] = mod - 1;
	A[0] = Sub(A[0], 1);
	FWT(A, 1 << n);
	FWT(B, 1 << n);
	int x = 0, p = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		if (A[i] == 0)
			x = i;
		C[i] = (ll)Pow(A[i], mod - 2) * B[i] % mod;
	}
	IFWT(C, 1 << n);
	p = (ll)Sub(0, C[0]) * (1 << n) % mod;
	FWT(C, 1 << n);
	C[x] = p;
	IFWT(C, 1 << n);
	for (int i = 0; i < (1 << n); i++)
		printf("%d\n", C[i]);
}


Measured memory_bytes: 6912
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a[20];
	for(int i=0;i<10;i++)
		cin>>a[i];
	sort(a,a+10);
	for(int i=9;i>6;i--)
		cout<<a[i]<<endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
int n,c[10000];
int no(int i,int color){
    int ue=i-1,shita=i+1,x=1,y=n;
    if (c[ue]==color) {
        ue--;
        x++;
    }
    if (c[shita]==color) {
        shita++;
        x++;
    }
    if (x==1) {
        return n;
    }
    while (ue!=-1&&shita!=n) {
        while (ue!=-1&&c[ue]==color) {
            ue--;
            x++;
        }
        while (shita!=n&&c[shita]==color) {
            shita++;
            x++;
        }
        if (x>=4) {
            y-=x;
            x=0;
            if (c[ue]!=c[shita]) {
                return y;
            }
            color=c[ue];
        }else{
            return y;
        }
    }
    return y;
}
 
int main(){
    while (1) {
        int i,j,ans;
        scanf("%d",&n);
        if (n==0) {
            return 0;
        }
        ans=n;
        for (i=0; i<n; i++) {
            scanf("%d",&c[i]);
        }
        for (i=0; i<n; i++) {
            for (j=1; j<=3; j++) {
                ans=min(ans, no(i,j));
            }
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 2628
#include <iostream>

using namespace std;

char table[3][3];

int main(void){
	while(true){
		for(int y=0;y<3;y++)
			for(int x=0;x<3;x++)
				cin >> table[x][y];
		if(cin.eof())
			break;
		int judge=0;
		for(int y=0;y<3;y++){
			if(table[0][y]==table[1][y]&&table[1][y]==table[2][y]&&table[2][y]=='o')
				judge=1;
			if(table[0][y]==table[1][y]&&table[1][y]==table[2][y]&&table[2][y]=='x')
				judge=2;
		}
		for(int x=0;x<3;x++){
			if(table[x][0]==table[x][1]&&table[x][1]==table[x][2]&&table[x][2]=='o')
				judge=1;
			if(table[x][0]==table[x][1]&&table[x][1]==table[x][2]&&table[x][2]=='x')
				judge=2;
		}
		if(table[0][0]==table[1][1]&&table[1][1]==table[2][2]&&table[2][2]=='o')
				judge=1;
		if(table[0][0]==table[1][1]&&table[1][1]==table[2][2]&&table[2][2]=='x')
				judge=2;
		if(table[0][2]==table[1][1]&&table[1][1]==table[2][0]&&table[2][0]=='o')
				judge=1;
		if(table[0][2]==table[1][1]&&table[1][1]==table[2][0]&&table[2][0]=='x')
				judge=2;
		if(judge ==1) 
			cout << 'o' <<endl;
		else if(judge == 2)
			cout << 'x' << endl;
		else
			cout << 'd' << endl;
	}
	return 0;
}

Measured memory_bytes: 1132
#include<stdio.h>
  
int main()
{
  int t[4][3][10]={0};
  int b,f,r,v,i,j,k,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d%d%d%d",&b,&f,&r,&v);
t[b-1][f-1][r-1]=t[b-1][f-1][r-1]+v;
 
       
     
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
    printf(" %d",t[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3)printf("####################\n");
  }
  return 0;
}


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

class Node{
public:
	int node;
	int cost;
	Node(int n,int c){
		node = n;
		cost = c;
	}
	bool operator < (const Node &o) const{
		return cost > o.cost;
	}
};
#define MAX 2000000000
int main(){
	int n,m;
	int s,g,money,hashira;
	priority_queue<Node> pq;
	priority_queue<Node> pq2;
	int map[50][50];
	bool visited[100];
	char ch;

	cin >> n >> m;
	for(int i = 1; i <=n;i++ ){
		visited[i] = false;
	}
	for(int i = 1 ; i <=n ;i++){
		for(int j = 1;j <=n ;j++){
			map[i][j] = MAX;
		}
	}

	for(int i = 1 ; i <= m;i++){
		int a,b,c,d;
		cin >> a >> ch >> b >> ch >> c >> ch >> d;
		map[a][b] = c;
		map[b][a] = d;
	}

	cin >> s >> ch >> g >> ch >> money >> ch >> hashira;
	//ツ行ツつォツづ個コツスツトツづーツ仰づ淞づゥ
	pq.push(Node(s,0));
	while(!pq.empty()){
		Node c_node = pq.top();
		pq.pop();
		if(c_node.node == g){
			pq2.push(c_node);
			break;
		}
		if(visited[c_node.node])continue;
		visited[c_node.node]= true;
		for(int i = 1;i <= n;i++ ){
			if(map[c_node.node][i] == MAX)continue;
			int n_cost = c_node.cost + map[c_node.node][i];
			pq.push(Node(i,n_cost));
		}
	}

	for(int i = 1; i <= n;i++ ){
		visited[i] = false;
	}

	//ツ帰ツづィツづ個コツスツトツづーツ仰づ淞づゥ
	while(!pq2.empty()){
		Node c_node = pq2.top();
		pq2.pop();
		if(c_node.node == s){
			int ans = money - hashira-c_node.cost;
			cout <<ans <<endl;
			break;
		}
		if(visited[c_node.node])continue;
		visited[c_node.node]= true;
		for(int i = 1;i <= n;i++ ){
			if(map[c_node.node][i] == MAX)continue;
			int n_cost = c_node.cost + map[c_node.node][i];
			pq2.push(Node(i,n_cost));
		}
	}
	return 0;
}

Measured memory_bytes: 0
import sys

input = sys.stdin.readline


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    time = sum(A)
    for i in reversed(range(N)):
        if time <= K:
            i_A = i
            break
        time -= A[i]

    if time == 0:
        ans = 0
        for i in range(M):
            time += B[i]
            if time > K:
                break
            ans += 1
    else:
        ans = i_A + 1
        cnt = i_A + 1
        for i in range(M):
            time += B[i]
            cnt += 1
            if time > K:
                for j in reversed(range(i_A + 1)):
                    time -= A[i_A]
                    cnt -= 1
                    i_A -= 1
                    if time <= K:
                        break
                if time > K:
                    break
            else:
                if cnt > ans:
                    ans = cnt

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41336
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N, K = readmap()
A = readlist()

cnt = [0] * 50  # cnt[i] は 2^i の桁の 1 の数

for a in A:
    i = 0
    while a:
        if a % 2:
            cnt[i] += 1
        i += 1
        a = a // 2

is_zero = [False] * 50

for i in range(50):
    if 2 * cnt[i] >= N:
        is_zero[i] = True

candidate = [0]

for i in range(49):
    if 2**i <= K:
        c = 0
        for j in reversed(range(i+1)):
            if (not is_zero[j]) and c + 2 ** j <= K:
                c += 2 ** j
        candidate.append(c)

can = [sum([c ^ a for a in A]) for c in candidate]

print(max(can))

Measured memory_bytes: 14712
input_ab = list(map(int, input().split()))
calc_plus = input_ab[0] + input_ab[1]
calc_minus = input_ab[0] - input_ab[1]
calc_times = input_ab[0] * input_ab[1]
result = [calc_plus, calc_minus, calc_times]
result.sort()
print(result[2])


Measured memory_bytes: 2940
N, X = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
x.append(X)
D = abs(X-x[0])
x.sort()


def GCD(x, y):
    a = max(x, y)
    b = min(x, y)
    r = 1
    while r != 0:
        r = a % b
        a = b
        b = r
    return a


for ni in range(N):
    dif = x[ni+1] - x[ni]
    D = GCD(dif, D)

print(D)

Measured memory_bytes: 14224
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n);
	for (int i = 0; i < a.size(); i++) {
		cin >> a[i];
	}
	for (int i = 0; i < b.size(); i++) {
		cin >> b[i];
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += (a[i] > b[i]) ? b[i] : a[i];
		b[i] -= (a[i] > b[i]) ? b[i] : a[i];
		ans += (a[i + 1] > b[i]) ? b[i] : a[i + 1];
		a[i + 1] -= (a[i + 1] > b[i]) ? b[i] : a[i + 1];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x,K,D;
  cin >> x >> K >> D;
  long long X = abs(x);
  if(X / D >= K){
    printf("%llu",X - D * K);
    return 0;
  }
  long long sa = K - (X / D);
  long long amari = X % D;  
  long long hu = D - amari;
  if(sa % 2 != 1) printf("%llu",amari);
  else printf("%llu",hu);
}

Measured memory_bytes: 3768
s = int(input())
a = [s]

for i in range(1,20**20):
  if a[i-1]%2 == 0:
    a.append(a[i-1]/2)
  else:
    a.append(3*a[i-1]+1)
  
  if a[-1] in a[:-1]:
    break

print(i+1)

Measured memory_bytes: 3060
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    a,b,h,m = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    min = h*60 + m
    long = min * 360 / (60*12)
    short = 360 * m/60
    angle = abs(short-long)
    c2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(angle))
    print(c2 ** 0.5)



main()


Measured memory_bytes: 9524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    ll time = 0;
    ll book_b = 0;
    ll book_a = 0;
    ll books = 0;
    for (ll i = 0; i < n and time + a[i] <= k; i++) {
        time += a[i];
        book_a = i + 1;
    }
    for (ll i = book_a - 1; i >= -1; i--) {
        for (ll j = book_b; j < m and time + b[j] <= k; j++) {
            time += b[j];
            book_b = j + 1;
        }
        books = max(books, book_a + book_b);
        if (book_a != 0) {
            time -= a[i];
            book_a--;
        }
    }
    cout << books << endl;
    return 0;
}

Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int f (int k, int n) {
    int ret = 0;
    rep (i, n) {
        ret += ((k & (1 << i)) ? (1 << (n - i - 1)) : 0);
    }
    return ret;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int> > p(n + 1, vector<int>(1 << n));
    rep (i, (1 << n)) cin >> p[0][i];
    rep (i, n) {
        rep (j, (1 << n)) {
            int block = j >> (n - i), fl = (j >> (n - i - 1)) % 2, k = j % (1 << (n - i - 1));
            // eprintf("%d %d %d %d %d\n", i, j, block, fl, k);
            int x = (block << (n - i)) + (2 * k + fl), y = (block << (n - i)) + (2 * k + fl + 1) % (1 << (n - i));
            if (p[i][x] > p[i][y]) swap(x, y);
            p[i + 1][j] = (s[p[i][y] - p[i][x] - 1] == '1' ? p[i][y] : p[i][x]);
            // eprintf("%d %d %d %d %d\n", x, y, p[i][x], p[i][y], p[i + 1][j]);
        }
    }
    rep (i, 1 << n) {
        // eprintf("%d %d %d\n", i, f(i, n), p[n][f(i, n)]);
        cout << p[n][f(i, n)] << "\n";
    }
    return 0;
}


Measured memory_bytes: 23932
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x,t,d,b=0,c=1;
    scanf("%d %d",&n,&x);
    while(n--){
        scanf("%d",&d);
        b+=d;
        if(b<=x) c++;
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 256
using System;

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Union(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y)
    {
        return Root(x) == Root(y);
    }
    private int Root(int x)
    {
        if (data[x] < 0) return x;
        else return data[x] = Root(data[x]);
    }
}
public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var q = int.Parse(line[1]);
        var uf = new UnionFind(n + 1);
        for (int i = 0; i < q; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var a = int.Parse(line[1]);
            var b = int.Parse(line[2]);
            if (c == 0) uf.Union(a, b);
            else if (c == 1)
            {
                if (uf.IsSameGroup(a, b)) Console.WriteLine(1);
                else Console.WriteLine(0);
            }
        }
    }
}



Measured memory_bytes: 9452
#include<stdio.h>
int main(void)
{
	int n,k,x,y,a;
	scanf("%d %d %d %d",&n,&k,&x,&y);
	if(n<k) {
	a=n*x;
	}
	else {
	a=k*x+((n-k)*y);
	}
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 128
#!python3

iim = lambda: map(int, input().rstrip().split())

def factor(n):
    ans = []
    i = 0
    while n & 1 == 0:
        n >>= 1
        i += 1

    if i > 0:
        ans.append((2, i))

    for i in range(3, int(n**.5) +1, 2):
        x, y = divmod(n, i)

        if y == 0:
            j = 1
            x1 = x
            while True:
                x1, y = divmod(x, i)
                if y == 0:
                    x = x1
                    j += 1
                else:
                    ans.append((i, j))
                    break
            n = x

    if n > 1:
        ans.append((n, 1))

    return ans

def resolve():
    N = int(input())

    ans = 0
    for a, b in factor(N):
        c = 1
        while b >= c:
            b -= c
            ans += 1; c += 1
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int n;
int match[25][25];
int dp[2097160][25];
long solve(int mask, int pos)
{
    //cout<<mask<<endl;
    if(mask == (1<<n)-1)
        return 1;

    if(pos == n && mask!= (1<<n)-1)
        return 0;
    
    if(dp[mask][pos]!=-1)
        return dp[mask][pos];
    
    int ans = 0;
    for(int i=0; i<n; i++)
    {        
        if(match[pos][i]==1) // compatible
        {            
            // Check if not already taken
            if(!(mask & (1<<i))) 
            {                
                ans = (ans+solve(mask|(1<<i), pos+1))%MOD;
            }
        }
    }
    dp[mask][pos] = ans;
    return ans;   

}

int main()
{    
    
    cin>>n; 
     
    memset(dp,-1,sizeof(dp));
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            cin>>match[i][j];
        }
    }    
    cout<<solve(0,0)<<endl;
    
    return 0;
}

Measured memory_bytes: 205056
#include <iostream>
#include <string>
#include <cmath>

int main() {
	int a, b;
	std::string numstr;
	int c;
	double d;

	std::cin >> a >> b;
	numstr =  std::to_string(a) + std::to_string(b);
	c = std::stoi(numstr);
	d = sqrt(c);
	if (c == int(d) * int(d)) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

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

int main(void)
{
  vector<int> v(10);

  for (int i = 0; i < 10; i++) cin >> v[i];

  sort(v.begin(), v.end(), greater<int>());

  for (int i = 0; i < 3; i++) cout << v[i] << endl;

  return 0;
}

Measured memory_bytes: 1212
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1e9+1
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int td,n,i=1;
  cin >> td >> n;
  int r = 0,k = (2*n)+1;
  while(r < td)
  {
    r = k*i;
    i++;
  }
  cout << i-1;
  return 0;
} 


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{ 
    static int [] e;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        e = new int [n];
        for(int x = 0; x < n; x++){
            e[x] = scan.nextInt();
        }
        int q = scan.nextInt();
        int [] qu = new int[q];
        for (int x = 0; x < q; x++){
            qu[x] = scan.nextInt();
        }
        for (int x = 0; x < q; x++){
            if(solve(0, qu[x])){
                System.out.println("yes");
            }
            else{
                System.out.println("no");
            }
        }
    }
    static public boolean solve(int p, int t){
        if(t == 0){
            return true;
        }
        else if(p == e.length){
            return false;
        }
        else if(t < 0){
            return false;
        }
        else{
            return solve(p +1, t) || solve(p + 1, t - e[p]);
        }
    }
}


Measured memory_bytes: 26784
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

int dfs(const string& s, int n) {
    ll sn = s == "" ? 0 : stol(s); 
    if (sn > n) return 0;
    int ret = 0;
    if (s.find('3') != string::npos 
     && s.find('5') != string::npos
     && s.find('7') != string::npos ) ret += 1; 
    ret += dfs(s + '3', n);
    ret += dfs(s + '5', n);
    ret += dfs(s + '7', n);
    return ret;
}

int main() {
    int n;
    cin >> n;
    cout << dfs("", n) << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i

arr = gets.split.map(&:to_i)

count = 0

n.times do |i|
  (n - 1).downto(i + 1) do |j|
    if arr[j] < arr[j - 1]
      arr[j - 1], arr[j] = arr[j], arr[j - 1]
      count += 1
    end
  end
end

puts arr.join(' ')
puts count

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

int main(){
	string S;
	cin >> S;
	
	rep(i,3){
		if (S[i] == '7') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;



    
}


Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main()
{
    int h, w;
    while (cin >> h >> w)
    {
        if ((h == 0) && (w == 0))
        {
            return (0);
        }
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if((j + i)%2 == 0)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector <int> v;
vector <char> vc;
vector <string> vs;
map <string,int> sm;
map <int,int> mp;
map <char,int>cm;
//int string_to_int(string s){stringstream x(s);double a=0; x>>a; return a;}
//long long int gcd(long long int a, long long int b){if(a%b==0)return b;return gcd(b, a%b);}
//long long int lcm(long long int a, long long int b){return (a*b)/gcd(a, b);}
//int string_sum(string s){int b = 0;auto k =s.size();for(int j=0; j<k; j++){b +=(s[j]-48);}return b;}
//long long int factorial(long long int n){if (n == 0)return 1;return n * factorial(n - 1);}

//int cnt =0;
//
//void SieveOfEratosthenes(int n)
//{
//   // v.push_back(1);
//
//    bool prime[n+1];
//    memset(prime, true, sizeof(prime));
//
//    for (int p=2; p*p<=n; p++)
//    {
//
//        if (prime[p] == true)
//        {
//
//            for (int i=p*p; i<=n; i += p)
//                prime[i] = false;
//        }
//    }
//
//
//    for (int p=2; p<=n; p++)
//       if (prime[p])
//          v.push_back(p);
//}
//
   

//int mod(string num, int a)
//{
//    // Initialize result
//    int res = 0;
//
//    // One by one process all digits of 'num'
//    for (int i = 0; i < num.length(); i++)
//         res = (res*10 + (int)num[i] - '0') %a;
//
//    return res;
//}

#include <bits/stdc++.h>
using namespace std;
  
void adj(string S){
      
   int n = S.size();
  
   
   if (n < 2)
     return;
   
   int j = 0;
  
   for (int i=1; i<n; i++)
   {
       
       if (S[j] != S[i])
       {
           j++;
           S[j] = S[i];
       }
   }
  
   j++;
   S[j] = '\0';
}
   
int main() {
    int a,b,c,n;
    string s,p;
   
    cin >> n >> s;
    int j=0;
    
    for(int i=0; i<n; i++)
        {
            if(i==0)
            {
                vc.push_back(s[i]);
                j++;
                continue;
            }
            if(vc[j-1]!=s[i])
            {
                vc.push_back(s[i]);
                j++;
            }
        
        
        }
    
   
   
    cout << vc.size() << endl;
    
       
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include <string>
#include <iostream>
#include <assert.h>
#include <stdio.h>
#define SIZEOF(x) (sizeof x )/(sizeof x[0])
#include <math.h>

int main(){
    int N,K;
    scanf("%d" , &N);
    scanf("%d" , &K);
    int p = 1;
    for(int t = 0 ; t < N ; t++){
        if(p*2 > p+K){
            p = p+K;
        }else{
            p = p*2;
        }

    }
    printf("%d\n" ,p);




    return 0;

}

Measured memory_bytes: 256