akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                    \
  for (int i = 0; i < (int)(n); i++) \
    ;

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  set<int> s1;
  s1.insert(0);
  set<int> s2;
  s2.insert(w);
  set<int> s3;
  s3.insert(0);
  set<int> s4;
  s4.insert(h);

  for (int i = 0; i < n; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1) {
      s1.insert(x);
    }
    if (a == 2) {
      s2.insert(x);
    }
    if (a == 3) {
      s3.insert(y);
    }
    if (a == 4) {
      s4.insert(y);
    }
  }
  int lx = *s1.rbegin();
  int ux = *s2.begin();
  int ly = *s3.rbegin();
  int uy = *s4.begin();
  if (ux - lx <= 0 || uy - ly <= 0) {
    cout << 0 << endl;
  } else {
    cout << (ux - lx) * (uy - ly) << endl;
  }
}


Measured memory_bytes: 256
from collections import Counter

N = int(input())
*a, = map(int, input().split())
c = Counter(a)
used = set(c.keys())
size = len(used)

def check():
    if 0 in used:
        if size==1 or (size==2 and c[0]==N//3):
            return True
    elif size==3:
        s, t, u = used
        if s^t^u==0 and c[s]==c[t]==c[u]:
            return True
    return False

print("Yes" if check() else "No")

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

using namespace std;

int main()
{
string N;
cin >> N;
if (N.at(0)==N.at(1)&&N.at(0)==N.at(2))
    cout << "Yes";
else
    if (N.at(1)==N.at(2)&&N.at(1)==N.at(3))
    cout << "Yes";

else
    cout <<"No";



return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>

using namespace std;

int main() {
  string s[3];
  for(int i = 0; i < 3; i++) {
    cin >> s[i];
  }
  if(s[0][s[0].length() - 1] == s[1][0] && s[1][s[1].length() - 1] == s[2][0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for( int &i : h ) cin >> i;
	sort( h.begin(), h.end() );
	int minimum = INF;
	for( int i = 0; i+k <= n; ++i ){
		minimum = min( minimum, h[i+k-1] - h[i] );
	}
	cout << minimum << endl;
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];

    int maxi=2*1e5;
    vector<long double> curr(maxi,infll),next(maxi,infll);
    rep(i,1,maxi) curr[i]=(long double)(abs(a[0]-i))/a[0];
    rep(i,0,n-1){
        rep(j,1,maxi){
            for(int k=j; k<maxi; k+=j){
                next[k]=min(next[k],max(curr[j],(long double)(abs(a[i+1]-k))/a[i+1]));
            }
        }
        swap(curr,next);
        fill(next.begin(),next.end(),infll);
    }
    cout << *min_element(curr.begin(),curr.end()) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(12);
    solve();
    return 0;
}

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

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

    deque<int> b;
    if(n % 2 == 0){
        rep(i, n){
            int k;
            cin >> k;
            if(i % 2 == 0){
                b.push_back(k);
            }
            else{
                b.push_front(k);
            }
        }
    }
    else{
        rep(i, n){
            int k;
            cin >> k;
            if(i % 2 == 0){
                b.push_front(k);
            }
            else{
                b.push_back(k);
            }
        }
    }
    rep(i, n){
        cout << (i ? " " : "") << b[i];
    }
}

Measured memory_bytes: 2944
#include<iostream>
#include <climits>
using namespace std;
int main(){
  int num_num, min_divide=INT_MAX;
  cin >> num_num;
  int nums[201];
  for(int i = 0; i < num_num; ++i){
    cin >> nums[i];
  }
  for(int i = 0; i < num_num; ++i){
    int tmp_divide=0;
    while(true){
      if (nums[i] % 2 == 0){
        nums[i] /= 2;
        tmp_divide++;
      }else{
        break;
      }
      if(tmp_divide >= min_divide){
        break;
      }
    }
    if(tmp_divide < min_divide){
      min_divide = tmp_divide;
    }
  }
  cout << min_divide << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=s; i<(n); ++i)
#define ALL(n) begin(n),end(n)
using ll = long long;
const ll INF = 1e18;
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; }

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> H(N); REP(i, 0, N) cin >> H[i];
    vector<int> A(M), B(M); REP(i, 0, M) cin >> A[i] >> B[i];

    vector<set<int>> network(N);
    REP(i, 0, M){
        network[A[i] - 1].insert(B[i] - 1);
        network[B[i] - 1].insert(A[i] - 1);
    }

    int cnt = 0;
    REP(i, 0, N){
        int h = H[i];
        bool top_flag = true;
        for (auto j: network[i]){
            if (h <= H[j]){
                top_flag = false;
                break;
            }
        }
        if (top_flag)
            ++cnt;
    }

    cout << cnt << endl;

    return 0;
}


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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++) {
		int l,r;
		cin >> l >> r;
		sum+= r-l+1;
	}
	cout << sum;
	return 0;
}



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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    a.at(i)--;
  }
  vector<bool> seen(N,false);
  int num=0;
  int on=0;
  while(1){
    seen.at(on)=true;
    on=a.at(on);
    num++;
    if(seen.at(on)==true){
      cout<<-1<<endl;
      break;
    }
    if(on==1){
      cout<<num<<endl;
      break;
    }
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s, t; cin >> s;
    int a, b;

    t=s;
    s.erase(s.begin(), s.begin()+2);
    t.erase(t.begin()+2, t.end());

    a=atoi(s.c_str());
    b=atoi(t.c_str());

    if(a>0 && a<13){
        if(b>0 && b<13){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "YYMM" << endl;
        }
    }else{
        if(b>0 && b<13){
            cout << "MMYY" << endl;
        }else{
            cout << "NA" << endl;
        }
    }

}
//g++ -o prob.exe prob.cpp

//VSCなら./test
//Atomならtest.exe


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort()
    B.sort()
    C.sort()

    def binsearch_left(a, x):
        l = -1
        r = len(a)
        while r-l>1:
            m = (l+r)//2
            if x<a[m]:
                r = m
            else:
                l = m
        return r

    def binsearch_right(a, x):
        l = -1
        r = len(a)
        while r-l>1:
            m = (l+r)//2
            if x<=a[m]:
                r = m
            else:
                l = m
        return r

    ans = 0
    for b in B:
        a_r = binsearch_right(A, b)
        c_l = binsearch_left(C, b)
        ans += a_r * (N - c_l)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int x;
    cin>>x;
    if(x<1200){
        cout<<"ABC"<<endl;
    }else if(x<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/dp/tasks/dp_a
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> h (n);
	for (auto& x:h) {
		cin >> x;
	}
	vector<int> dp (n);
	dp[1] = abs(h[1]-h[0]);
	for (int i = 2; i < (int)h.size(); i++) {
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 1000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 // 二項係数計算
ll COM(ll n, ll k){
     if (n < k) return 0;
     if (n < 0 || k < 0) return 0;
     return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

 using graph = vector<vector<ll>>;
 pair<pair<ll,ll>,ll> p[100010];

 map<ll, int> factorize(ll n) {
     map<ll, int> res;
  
     for (ll i = 2; i * i <= n; i++) {
         if (n % i != 0) {
             continue;
         }
         res[i] = 0;
         while (n % i == 0) {
             n /= i;
             res[i]++;
         }
     }
  
     if (n != 1) res[n] = 1;
     return res;
 }
  
  
 int main() {
     ll n;
     cin >> n;
  
     auto f = factorize(n);
  
     int ans = 0;
     for (auto &e : f) {
  
         int k = e.second;
         int j = 1;
         while (k >= j) {
             ans++;
             k -= j;
             j++;
         }
  
     }
  
     cout << ans << endl;
     return 0;
 }


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt,i;
	char s[51];
	scanf("%d",&n);
	scanf("%s",s);
	cnt=0;
	for(i=0;i<n-2;i++)	{
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
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;}

char data[110][110];
int h,w;

bool inrange(int x,int y){
	if(x<0||y<0||x>h-1||y>w-1) return false;
	else return true;
}

int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
void dfs(int x,int y,char mark){
	data[x][y] = '0';
	REP(i,4){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(!inrange(nx,ny)) continue;
		if(data[nx][ny]==mark){
			dfs(nx,ny,mark);
		}
	}
}

int main(){
	while(1){
		cin >> h >> w;
		string tmp;
		if(h==0&&w==0) break;
		REP(i,h){
			cin >> tmp;
			REP(j,w) data[i][j] = tmp[j];
		}
		ll int cnt = 0;
		REP(i,h){
			REP(j,w){
				if(data[i][j]!='0'){
					cnt++;
					dfs(i,j,data[i][j]);
				}
			}
		}
		cout << cnt << endl;
	}
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<long> h(n);
    for(auto&& e:h) cin >> e;
    vector<vector<int>> adj(n,vector<int>());
    int a,b;
    while(cin >> a >> b){
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
	cerr << "adj.size() = " << adj.size() << endl;

    int ans = 0;
    for(int i=0; i<n; i++){
      	bool flag = 1;
        for(auto j: adj[i]){
            if(h.at(i) <= h.at(j))
                flag = 0;
        }
      	if(flag)
        	ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9064
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range (n-1):
    ans+=b[a[i]-1]
    if a[i]==a[i+1]-1:
        ans+=c[a[i]-1]
ans+=b[a[-1]-1]
print(ans)

Measured memory_bytes: 3064
N=int(input());A=list(map(int, input().split()));z=[0]*(max(A)+1);m=998244353;r=0
for a in A:z[a]+=a
for i in range(1,len(z)):
  for j in range(2*i,len(z),i):z[i]+=z[j]
for i in range(1,len(z)):z[i]*=z[i]
for i in range(len(z)-1,0,-1):
  for j in range(2*i,len(z),i):z[i]-=z[j]
for a in A:z[a]-=a**2
for i in range(1,len(z)):
  z[i]//=i*2;r=(r+z[i])%m
print(r)

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define pi acos(-1.0)
#define eps 1e-8
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int n, m, x, y, dp[3005][3005] ;
string s, t, ans ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    cin>> s >> t ;
    n=s.length(), m=t.length() ;
    s='#'+s, t='#'+t ;
    for(int i=1 ; i<=n ; i++)
      for(int j=1 ; j<=m ; j++)
        if(s[i]==t[j]) dp[i][j]=max(dp[i][j], 1+dp[i-1][j-1]) ;
        else dp[i][j]=max({dp[i][j], dp[i-1][j], dp[i][j-1]}) ;
    x=n, y=m ;
    while(x && y)
      if(s[x]==t[y]) ans+=s[x], x--, y-- ;
      else if(dp[x-1][y]>dp[x][y-1]) x-- ;
      else y-- ;
    reverse(all(ans)) ;
    cout<< ans ;
  }


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n;
  string name;
  cin >> n >> name;

  int ans = 0;
  string s;
  rep(i, n) {
    cin >> s;

    bool isOK = false;
    for (int j = 0; j < s.length(); ++j) {
      for (int k = 1; k < s.length(); ++k) {
        string u = "";
        for (int l = j; l < s.length(); l += k) {
          u += s[l];
        }
        if (u.length() < name.length()) continue;
        if (u.find(name) + 1) isOK = true;
      }
    }
    if (isOK) ++ans;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 998244353
#define inf 1e18 
 
using namespace std;
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,i,j,k;
    cin>>n;
    string s;
    cin>>s;
    vi r,g,b;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R') r.pb(i);
        else if(s[i]=='G') g.pb(i);
        else b.pb(i);
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(s[i]==s[j]) continue;
            int x=0,y=0,z=0;
            if(s[i]=='R'||s[j]=='R') x++;
            if(s[i]=='G'||s[j]=='G') y++;
            if(s[i]=='B'||s[j]=='B') z++;
            // cout<<x<<" "<<y<<" "<<z<<endl;
            if(x==0)
            {
                auto it=upper_bound(r.begin(),r.end(),j);
                ans+=r.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(r.begin(),r.end(),num);
                if(it1!=r.end()&&*it1==num) ans--;
            }
            else if(y==0)
            {
                auto it=upper_bound(g.begin(),g.end(),j);
                ans+=g.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(g.begin(),g.end(),num);
                if(it1!=g.end()&&*it1==num) ans--;
            }
            else
            {
                auto it=upper_bound(b.begin(),b.end(),j);
                ans+=b.end()-it;
                int num=j+j-i;
                auto it1=lower_bound(b.begin(),b.end(),num);
                if(it1!=b.end()&&*it1==num) ans--;
            }
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
namespace fdata
{
inline char nextchar()
{
    static const int BS = 1 << 21;
    static char buf[BS], *st, *ed;
    if (st == ed)
        ed = buf + fread(st = buf, 1, BS, stdin);
    return st == ed ? -1 : *st++;
}
#ifdef lky233
#define nextchar getchar
#endif
template <typename Y>
inline void poread(Y &ret)
{
    ret = 0;
    char ch;
    while (!isdigit(ch = nextchar()))
        ;
    do
        ret = ret * 10 + ch - '0';
    while (isdigit(ch = nextchar()));
}
#undef nextcar
} // namespace fdata
using fdata::poread;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n;
int T[MAXN], A[MAXN];
int  h[MAXN];
signed main()
{
#ifdef lky233
	freopen("testdata.in",  "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
	poread(n);
	for(register int i = 1; i <= n; ++i)
		poread(T[i]);
	for(register int i = 1; i <= n; ++i)
		poread(A[i]);
	for(register int i = 1; i <= n; ++i)
		if(T[i] != T[i - 1])
			h[i] = T[i];
	for(register int i = n; i >= 1; --i)
		if(A[i] != A[i + 1])
			h[i] = A[i];
	for(register int i = 1, mx = 0; i <= n; ++i)
	{
		mx = max(h[i], mx);
		if(mx != T[i])
		{
			puts("0");
			return 0;
		}
	}
	for(register int i = n, mx = 0; i >= 1; --i)
	{
		mx = max(h[i], mx);
		if(mx != A[i])
		{
			puts("0");
			return 0;
		}
	}
	int ans = 1;
	for(register int i = 1; i <= n; ++i)
	{
		if(!h[i])
		{
			ans = (long long) ans * min(A[i],T[i]) % MOD;
		}
	}
	cerr << ans << endl;
	cout << ans << endl;
}


Measured memory_bytes: 3328
def show(a,b,k)
  to=a+k-1
  while a<=to&&a<=b
    puts a
    a+=1
  end
  from=a>=b-k+1 ? a : b-k+1
  while from<=b
    puts from
    from+=1
  end
end

s=gets.chomp
nums=s.split(" ")
show(nums[0].to_i,nums[1].to_i,nums[2].to_i)


Measured memory_bytes: 1788
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve(){

}

int main() {
    fastik();
    ll n;cin>>n;
    vll c(n),v(n),a(n);
    forn(i,n){
        cin >> v[i];
        a[i] = v[i];
    }
    forn(i,n){
        cin >> c[i];
        a[i] -= c[i];
    }
    //sort(all(a));
    ll ans = 0;
    forn(i,n){
        if(a[i] > 0){
            ans += a[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)

using namespace __gnu_pbds;
using namespace std;

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

//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif


std::mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int ri(int a, int b) {
    return uniform_int_distribution<int>(a, b)(rng);
}

ll power(ll x, ll y, ll p){
   ll res = 1;
   x = x % p;
   while (y > 0) {
      if (y & 1)
         res = (res * x) % p;
      y = y >> 1;
      x = (x * x) % p;
   }
   return res;
}

const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll Hashprime = (ll)31;

const int maxn = 100100;

bool vis[maxn];
vector <int> g[maxn];

void dfs(int v){
  for(auto i : g[v]){
     if(!vis[i]){
        vis[i] = true;
        dfs(i);
     }
  }
}

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    //  freopen("input.txt", "r", stdin);
    //  freopen("output.txt", "w", stdout);
    #endif
    int TestCases = 1; // cin >> TestCases;
    while(TestCases--){
       int n; cin >> n;
       int m; cin >> m;
       for(int i = 1; i <= m; i++){
          int a,b; cin >> a >> b;
          g[a].push_back(b);
          g[b].push_back(a);
       }
       int ans = 0;
       for(int i = 1; i <= n; i++){
          if(!vis[i]){
            vis[i] = true;
            dfs(i);
            ans += 1;
          }
       }
       cout << ans - 1 << '\n';
    }
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}
//g++ -DLOCAL -std=c++17 -Wshadow -Wall -o "c" "comp.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g


Measured memory_bytes: 9724
N,x=list(map(int,input().split()))
a=list(sorted(list(map(int,input().split()))))
if sum(a)<x:
    print(N-1)
elif sum(a)==x:
    print(N)
else:
    ans=0
    for i in range(N):
        if a[i]<=x:
            ans+=1
            x-=a[i]
        else:
            break
    print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	string ans;
	if (b < 0) {
		if ((b - a) % 2 != 0) {
			ans = "Positive";
		}
		else {
			ans = "Negative";
		}
	}
	if (0 < a) {
		ans = "Positive";
	}
	if (a <= 0 && 0 <= b) {
		ans = "Zero";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
int a[1000+100],k,n;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	//===========================================================
	read(n),read(k);
    rep(i,1,n) read(a[i]);
    sort(a+1,a+1+n);
    int sum=0; 
    rep(i,1,k) sum+=a[i];
    write(sum);
	//===========================================================
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
using namespace std;

int main(){
	int n;
	scanf("%d",&n);
	n=n%10;
	switch(n)
	{
	    case 3:
                printf("bon\n");
                break;
	    case 0:
	    case 1:
	    case 6:
	    case 8:
                printf("pon\n");
                break;
        default:
                printf("hon\n");
                break;
	}
	return 0;
}


Measured memory_bytes: 3688
def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    N, M = read_int_array()
    bulbs = [None]*M
    for i in range(M):
        k, *switches = read_int_array()
        bulbs[i] = switches
    P = read_int_array()
    switches = []
    ans = 0
    def build(i):
        nonlocal ans
        if i == N:
            if all(sum(switches[x-1] for x in bulbs[i]) % 2 == P[i] for i in range(M)):
                ans += 1
        else:
            switches.append(False)
            build(i+1)
            switches[-1] = True
            build(i+1)
            switches.pop()
    build(0)
    write(ans)

main()


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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b, c;
  cin >> a >> b >> c;

  cout << (c - (a - b) > 0 ? c - (a - b) : 0) << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

typedef long long int ll;

string s;
ll n;

int main(void){
	cin >> s;
	n = s.size();
	if (s[0]=='1' && s[n-1]=='0'){
		for(int i=0;i<n;i++){
			if (i >= n-2-i) break;
			if (s[i] != s[n-2-i]){
				cout << -1 << endl;
				return 0;
			}
		}
		ll idx = 1, lastidx;
		ll cnt = 1;
		for(int i=1;i<n;i++){
			if (s[i]=='1'){
				lastidx = idx;
				idx = i + 1;
				ll d = idx - lastidx;
				//cnt, cnt+1, ..., cnt+d-1 -> cnt+d
				for(int j=cnt;j<cnt+d;j++) cout << j << " " << cnt+d << endl;
				cnt += d;
			}
		}
		cout << cnt << " " << cnt+1 << endl;
	}else{
		cout << -1 << endl;
		return 0;
	}

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int k, a, b, h = 1, y = 0, cost, inc, res;

signed main() {
	cin >> k >> a >> b;
	// とりあえずa枚作ろうとする
	int t = min(a-1, k-1);
	h += t, k -= t;
	if (b-a>=2) cost = 2, inc = b-a;
	else cost = 2, inc = 2;
	res = h + k/2*inc + k%2;
	cout << res << endl;
}


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

struct Info
{
    string name;
    int p;
    int idx;
    Info(string inputted_name, int inputted_age, int index)
    {
        name = inputted_name;
        p = inputted_age;
        idx = index;
    }
};

bool cmp(const Info &a, const Info &b)
{
    if(a.name == b.name){
        return a.p > b.p;
    }else{
        return a.name < b.name;
    }
}

int main(){
    int N;
    cin >> N;
    vector<Info> info;
    string s[N];
    int p[N];
    for(int i = 0; i < N; i++){
        cin >> s[i] >> p[i];
        info.push_back(Info(s[i], p[i], i));
    }
    sort(info.begin(), info.end(), cmp);
    for(int i = 0; i < N; i++){
        cout << info[i].idx + 1 << endl;
    }


    return 0;
}

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

using namespace std;

int color[10][10];
int h, w, k;
int hh[10], ww[10];

int ans = 0;

int m_color(int sh, int sw, int hl, int wl);
void solve(int nh, int nw);
int main()
{
    scanf("%d%d%d", &h, &w, &k);

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char c;
            scanf("%c", &c);
            if(c == '.'){
                color[i][j] = 0;
            }
            else if(c == '#'){
                color[i][j] = 1;
            }
            else{
                j--;
            }
        }
    }
    solve(0, 0);
    printf("%d\n", ans);
}

int m_color(int hh[], int ww[])
{
    int co[10][10];
    memcpy(co, color, sizeof(int)*100);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(hh[i] || ww[j])
                co[i][j] = 0;
        }
    }
    int res = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++)
            res += co[i][j];
    }
    return res;
}

void solve(int nh, int nw)
{
    if(nw == w){
        if(m_color(hh, ww) == k)
            ans++;
        return;
    }
    if(nh==h || nw!=0){
        ww[nw] = 0;
        solve(nh, nw+1);
        ww[nw] = 1;
        solve(nh, nw+1);
        return;
    }
    else{
        hh[nh] = 0;
        solve(nh+1, nw);
        hh[nh] = 1;
        solve(nh+1, nw);
        return;
    }
}


Measured memory_bytes: 1712
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long a, b, c;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b >> c;
    if (a >= c || b >= c) {
        cout << "No" << E;
    }
    else {
        long long L = 4 * a;
        L *= b;
        long long R = c - a;
        R -= b;
        R = R * R;
        if (L < R) cout << "Yes" << E;
        else cout << "No" << E;
    }
    //system("pause");
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> arr(n);
  for (int i=0; i<n; i++) cin>>arr[i];
  long long int ans=0;
  for (int i=1; i<n; i++){
    if (arr[i]>=arr[i-1]) continue;
    else{
      ans+=(arr[i-1]-arr[i]);
      arr[i]=arr[i-1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
	double s, l;
	int s_r, l_r;
	int res;
	
	
	while(cin >> s >> l){
		if(s < 35.5){
			s_r = 0;
		}else if(s < 37.5){
			s_r = 1;
		}else if(s < 40){
			s_r = 2;
		}else if(s < 43){
			s_r = 3;
		}else if(s < 50){
			s_r = 4;
		}else if(s < 55){
			s_r = 5;
		}else if(s < 70){
			s_r = 6;
		}else{
			s_r = 7;
		}
		if(l < 71){
			l_r = 0;
		}else if(l < 77){
			l_r = 1;
		}else if(l < 83){
			l_r = 2;
		}else if(l < 89){
			l_r = 3;
		}else if(l < 105){
			l_r = 4;
		}else if(l < 116){
			l_r = 5;
		}else if(l < 148){
			l_r = 6;
		}else{
			l_r = 7;
		}
		
		res = max(s_r, l_r);
		
		switch(res){
			case 0:
				cout << "AAA" << endl;
				break;
			case 1:
				cout << "AA" << endl;
				break;
			case 2:
				cout << "A" << endl;
				break;
			case 3:
				cout << "B" << endl;
				break;
			case 4:
				cout << "C" << endl;
				break;
			case 5:
				cout << "D" << endl;
				break;
			case 6:
				cout << "E" << endl;
				break;
			case 7:
				cout << "NA" << endl;
				break;
		}
	}
}

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

using namespace std;

int main(){
  int N;
  cin>>N;
  int ans = 0;

  for(int i=1; i<=N; i++){
    if(i%2==1){
      int counter = 0;
      for(int j=1; j<=N; j++){
        if(i%j==0) counter++;
      }
      if(counter == 8) ans++;
    }
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
signed main(){
  int a[3],b[3],c;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  for(int i=0;i<3;i++){
    b[i]=a[i];
    }
  c=b[0]+b[1];
  cout<<c<<"\n";
  return(0);
}

Measured memory_bytes: 256
N = int(input())
A = [None] * N
B = [None] * N

for k in range(N):
  a,b = [int(i) for i in input().split()]
  A[k] = a
  B[k] = b

min_B = min(B) # 情報のうち最低点
min_B_rank = A[B.index(min_B)] # 情報のうち最低点を取った人の順位
print(min_B_rank + min_B) # 最低点を取った人の下に min_B - 1,...,0 点を取った人がいる場合

Measured memory_bytes: 10868
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <map>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int N;
    cin >> N;
    ll sum = 0;
    vector<int> as(N + 2, 0);
    rep(i, N){
        // as[0] = 0, as[N + 1] = 0
        cin >> as[i + 1];
        sum += abs(as[i] - as[i + 1]);
    }
    sum += abs(as[N]);

    rep(i, N){
        ll ans = sum;
        ans -= abs(as[i] - as[i + 1]);
        ans -= abs(as[i + 1] - as[i + 2]);
        ans += abs(as[i] - as[i + 2]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#define N 1000
#define M 100

typedef struct{
	int key;
	int num;
} ss;

void swap(ss* a,ss* b){
	ss tmp;
	tmp=*a;
	*a=*b;
	*b=tmp;
}

int main(void){
	int n,m,i,j,k;
	ss s[M];

	while(scanf("%d %d",&n,&m),n||m){

	for(i=0;i<m;i++){s[i].num=0;s[i].key=i+1;}

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&k);
			if(k==1) s[j].num++;
		}
	}


	for(i=0;i<m;i++){
		for(j=m-1;j>i;j--){
			if(s[j].num>s[j-1].num){
				swap(&s[j],&s[j-1]);
			}
		}
	}

	for(i=0;i<m;i++){
		if(i==m-1)printf("%d",s[i].key);
		else printf("%d ",s[i].key);
	}
	printf("\n");

	}
	return 0;
}

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

int main()
{
    double n, d;
    cin >> n >> d;
    cout << ceil(n / (2 * d + 1)) << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int n;
  cin>>n;
  ll a[n];
  int count=0;
  rep(i,n){
    cin>>a[i];
    for(int j=50;j>0;j--){
      ll b=pow(2,j);
      //  cout<<b<<endl;
      if(a[i]%b==0){
	count+=j;
	break;
      }
    }
    
  }
  cout<<count<<endl;


  return 0;
}


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

public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int	cnt = parseCnt();

		while(cnt-- > 0) {
			String	tmp = parseStdin();
			System.out.println(tmp.replaceAll("Hoshino", "Hoshina"));
		}
	}

	private static int parseCnt() {
		int		cnt = 0;
		String	str = null;

		if ((str = parseStdin()) != null) {
			cnt = Integer.parseInt(str);
		}

		return cnt;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) {
            		stdin = tmp;
            	}
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 16956
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static long loop(long N, long temp,long wari)
    {
        if (N / wari == 0)
        {
            Console.WriteLine(temp);
            return 0;
        }
        else
        {
            temp+=N / wari;
            return loop(N, temp, 5 * wari);
        }
    }
    static void Main(string[] args)
    {
        long N = long.Parse(Console.ReadLine());
        if (N % 2 == 1) { Console.WriteLine("0"); }
        else
        {
            loop(N, 0,10);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<ll>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int N;
  cin>>N;

  vector<ll> a(N);
  rep(i,N){
    cin>>a[i];
  }

  SORT(a);

  ll l1=-1;
  ll l2=-1;

  rep(i,N-1){
    if(a[i]==a[i+1]){
      if(l1==-1){
        l1=a[i];
        ++i;
      }
      else{
        l2=a[i];
        break;
      }
    }
  }

  cout<< ( l2!= -1 ? l1*l2 : 0 )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.nextLine());

		ArrayList<Integer> a = new ArrayList<>();

		String[] s = sc.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			a.add(Integer.parseInt(s[i]));
		}
		Collections.sort(a);

		while(a.size() > 1) {
			int min = a.get(0);
			for(int j=1;j<a.size();j++) {
				a.set(j, a.get(j) % min);
			}
			List<Integer> temp = new ArrayList<>();
			temp.add(0);
			a.removeAll(temp);
			Collections.sort(a);
		}

		System.out.println(a.get(0));
	}

}

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

using namespace std;

string a;
int ctr[26] = {};

int main()
{
  cin >> a;

  int64_t n = a.length();
  for (char c : a) ctr[c-'a']++;

  int64_t r = 1LL*n*(n-1)/2;
  for (int x : ctr) r -= 1LL*x*(x-1)/2;

  cout << r+1 << endl;

  return 0;
}


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

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

    int n;
    cin >> n;
    vector<double> X(n), Y(n);
    for(int i = 0; i < n; i++){
        cin >> X[i] >> Y[i];
    }


    vector<int> A(n);
    for(int i = 0; i < n; i++){
        A[i] = i;
    }

    sort(A.begin(), A.end());

    double ans = 0;
    do{
        double a = -1, b = -1, tmp = 0;
        for(int i = 0; i < n; i++){
            if(i == 0){
                a = X[A[i]];
                b = Y[A[i]];
            }else{
                double j1 = (a - X[A[i]]);
                double j2 = (b - Y[A[i]]);
                tmp += sqrt(j1 * j1 + j2 * j2);
            }
            a = X[A[i]];
            b = Y[A[i]];
        }
        ans += tmp;
    }while(next_permutation(A.begin(), A.end()));

    double g = 1;
    for(int i = 1; i <= n; i++){
        g *= i;
    }

    cout << fixed << setprecision(10) << ans / g << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<vector>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>>like(N,vector<bool>(M,false));
  for (int i = 0; i < N; i ++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j ++) {
      int a;
      cin >> a;
      like[i][a - 1] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i ++) {
    bool li = true;
    for (int j = 0; j < N; j ++) {
      if (!like[j][i]) {
        li = false;
      }
      if (!li) break;
    }
    if (li) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    ll n, t, a, h, ans;
    double ans_d;
    cin >> n >> t >> a;
    rep(i, n){
        cin >> h;
        double degree = abs(t - h * 0.006 - a);
        if(i == 0){
            ans = 0;
            ans_d = degree;
        }else{
            if(degree < ans_d){
                ans = i;
                ans_d = degree;
            }
        }

    }
    cout << ans + 1 << endl;
}



Measured memory_bytes: 256