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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll n, pr[600000], pl[600000];
pair<ll, ll> p[600000];

ll solve() {
  ll r = 0;
  sort(p, p + n);
  pl[0] = p[0].first;
  pr[0] = p[0].second;
  for (int i = 1; i < n; i++)
    pl[i] = max(pl[i - 1], p[i].first), pr[i] = min(pr[i - 1], p[i].second);
  ll sl = p[n - 1].first, sr = p[n - 1].second;
  for (int i = n - 2; i >= 0; i--) {
    r = max(r, max(sr - sl + 1, 0LL) + max(pr[i] - pl[i] + 1, 0LL));
    sl = max(sl, p[i].first);
    sr = min(sr, p[i].second);
  }
  return r;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  ll r = 0;
  int bi;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
    r = max(r, p[i].second - p[i].first + 1);
    if (p[i].second - p[i].first + 1 == r)
      bi = i;
  }
  ll ll = 0, rr = 1e9;
  for (int i = 0; i < n; i++)
    if (i != bi)
      ll = max(ll, p[i].first), rr = min(rr, p[i].second);
  r += max(0LL, rr - ll + 1);
  r = max(r, solve());
  for (int i = 0; i < n; i++)
    swap(p[i].first, p[i].second), p[i].first = 1e9 - p[i].first, p[i].second = 1e9 - p[i].second;
  r = max(r, solve());
  cout << r << "\n";
}


Measured memory_bytes: 7936
#include<iostream>
#include<cstdio>
using namespace std;
int ans[300100];
int main()
{
	int k,n;scanf("%d%d",&k,&n);
	if(!(k&1))
	{
		printf("%d ",k/2);
		for(int i=2;i<=n;i++)printf("%d ",k);
	}
	else
	{
		for(int i=1;i<=n;i++)ans[i]=(k>>1)+1;
		int s=n;
		for(int i=1;i<=n/2;i++)
		{
			while(ans[s]==0)s--;
			if(ans[s]==1)
			{
				ans[s]--;s--;continue;
			}
			ans[s]--;for(int i=s+1;i<=n;i++)ans[i]=k;s=n;
		}
		for(int i=1;i<=n;i++)if(ans[i]!=0)printf("%d ",ans[i]);
	}
	return 0;
 } 

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 1 << 21;
int np = 0;
vector<int> f;

struct Node {
	int x, y, node;
};
Node p[500001];

struct TNode {
	int location, l, r;
};
TNode T[500001];

bool cmp1(Node a, Node b) {
	return a.x < b.x;
}

bool cmp2(Node a, Node b) {
	return a.y < b.y;
}

bool cmp3(Node a, Node b) {
	return a.node < b.node;
}

int make2DTree(int l, int r, int depth)
{
	if (l >= r)
		return NIL;
	int mid = (l + r) / 2;
	int t = np++;

	if (depth % 2 == 0)
		sort(p + l, p + r, cmp1);
	else
		sort(p + l, p + r, cmp2);

	T[t].location = p[mid].node;
	T[t].l = make2DTree(l, mid, depth + 1);
	T[t].r = make2DTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth)
{
	int x, y;
	x = p[T[v].location].x;
	y = p[T[v].location].y;
	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		f.push_back(T[v].location);
	}
	if (depth % 2 == 0) {
		if (T[v].l != NIL && sx <= x)
			find(T[v].l, sx, tx, sy, ty, depth + 1);
		if (T[v].r != NIL && x <= tx)
			find(T[v].r, sx, tx, sy, ty, depth + 1);
	}
	else {
		if (T[v].l != NIL && sy <= y)
			find(T[v].l, sx, tx, sy, ty, depth + 1);
		if (T[v].r != NIL && y <= ty)
			find(T[v].r, sx, tx, sy, ty, depth + 1);
	}
}

int main(void)
{
	int n, q, sx, tx, sy, ty, t;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &p[i].x, &p[i].y);
		p[i].node = i;
	}
	t = make2DTree(0, n, 0);
	sort(p, p + n, cmp3);
	cin >> q;
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		find(t, sx, tx, sy, ty, 0);
		if (!f.empty()) {
			sort(f.begin(), f.end());
			for (vector<int>::iterator it = f.begin(); it != f.end(); it++) {
				printf("%d\n", *it);
			}
			f.clear();	
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 14516
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++) cout<<(s[i]=='?'?'D':s[i]);
    cout<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3788
n = int(input())
a = [0]+list(map(int, input().split()))+[0]

nums = [0]*(n+1)
for i in range(n+1): nums[i] = abs(a[i]-a[i+1])

t = sum(nums)
for i in range(1,n+1):
  ans = t - (nums[i-1]+nums[i]) + abs(a[i-1]-a[i+1])
  print(ans)

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll num[q];
    ll f[q];
    char c[q];

    rep(i, q) {
        cin >> num[i];
        if ( num[i] == 2 ) {
            cin >> f[i] >> c[i];
        }
    }
    ll top = 0;
    rep(i, q) {
        if ( num[i] == 1 ) {
            top = !top;
        } else {
            if (top) {
                if ( f[i] == 1 ) {
                    s.insert(s.end(), c[i]);
                } else {
                    s.insert(s.begin(), c[i]);
                }
            } else {
                if ( f[i] == 1 ) {
                    s.insert(s.begin(), c[i]);
                } else {
                    s.insert(s.end(), c[i]);
                }
            }
        }
    }

    if (top) {
        reverse(ALL(s));
    }

    cout << s << endl;
    return 0;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  string T;
  for(char &c : S) {
    if(c == 'B' && !T.empty()) T.pop_back();
    else if(c == '0') T += "0";
    else if(c == '1') T += "1";
  }
  cout << T << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<int, pair<int,int>> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int n, m, sum = 0;
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum > n) cout << -1;
    else cout << n - sum;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  string s;
  cin>>s;
  int dp[(int)2e5+10];
  dp[0]=0;
  dp[1]=1;
  dp[2]=(s[0]==s[1]? 1:2);
  for (int i = 2; i < s.size(); ++i)
  {
    if(s[i-1]!=s[i]){
      dp[i+1]=dp[i]+1;
    }
    else{
      dp[i+1]=dp[i-2]+2;
    }
  }
  cout<<dp[s.size()];
}

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

int main(){
    int n;
    cin>>n;
    int cnt=1;
    int ans=0;
    int a;
    rep(i,n){
        cin>>a;
        if(a!=cnt){
            ans++;
        }else{
            cnt++;
        }
    }
    if(ans==n) cout<<-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#define INT_INF 1000000000
#define DOUBLE_INF 1e18
#define MOD 1000000007
#define mod(x) ((x % MOD) + MOD) % MOD

using namespace std;

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

int main()
{
  double n, m, d;
  cin >> n >> m >> d;

  double ans = 0;
  if (d == 0) {
    ans = (m - 1) / n;
  } else {
    ans = 2 * (n - d) * (m - 1) / (n * n);
  }

  cout << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int a,b;
	int sum;
	
	cin >> a >> b ;

	sum = a * b;

	if( sum % 2 == 0 ) {
		cout << "Even" << endl;
	}else{
		cout << "Odd" << endl;
	}
	
	return 0;
}
	

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<stdio.h>
using namespace std;

struct node
{
	int m1,m2;
};

int n;
int a[1000011];

node dp[1000011];

void add(int now,int x)
{
	if(dp[now].m1==x || dp[now].m2==x)return ;
	if(a[x]>a[dp[now].m1])
	{
		dp[now].m2=dp[now].m1;
		dp[now].m1=x;
	}
	else if(a[x]>a[dp[now].m2])
	{
		dp[now].m2=x;
	}
}

int main()
{
	int i,j,k;
	scanf("%d",&n);
	
	
	memset(dp,-1,sizeof(dp));
	for(i=0;i<(1<<n);i++)
	{
		scanf("%d",&a[i]);
		add(i,i);
	}
	
	
	for(i=0;i<(1<<n);i++)
	{
		for(j=0;j<n;j++)
		{
			if((i&(1<<j))!=0)
			{
				add(i,dp[i^(1<<j)].m1);
				add(i,dp[i^(1<<j)].m2);
			}
		}
	}
	
	
	int ans=-1;
	for(i=1;i<(1<<n);i++)
	{
		ans=max(ans,a[dp[i].m1]+a[dp[i].m2]);
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define fr first
#define sc second

const int mod = 1e9 + 7;
using namespace std;

double dp[3001][3001];
int n;
double arr[3003];

int main(){
    scanf("%d",&n);
    for(int i = 0;i< n;i++){
        scanf("%lf",&arr[i]);
    }
    for(int i = 0;i<=n/2;i++)dp[n][i] = 1;
    for(int i = n - 1;i >= 0;i--){
        for(int j = 0;j <= n;j++)dp[i][j] = dp[i+1][j] * arr[i] + dp[i+1][j+1]*(1.0-arr[i]);
    }
    cout << fixed << setprecision(9) << dp[0][0];
    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;

void solve(){
  ll n, k, ans = 0; cin >> n >> k;
  for(int i = 1; i <= n; i++){
    if(i <= k) continue;
    ans += (i - k) * (n / i);
    if(n % i != 0){
      if(n % i + 1 > k){
        ans += (n % i + 1) - k;
        if(k == 0) ans--;
      }
    }
  }
  cout << ans << endl;
  return;
}

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


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

const int DIM = 3e5 + 5;

int arr[DIM];

int main(void)
{
    int n; cin >> n;
    for (int i = 1; i <= n * 3; ++i)
        cin >> arr[i];
    
    sort(arr + 1, arr + n * 3 + 1, greater<int>());
    
    long long sum = 0;
    for (int i = 2; i <= n * 2; i += 2)
        sum += arr[i];
    
    cout << sum << endl;
    return 0;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> vec(n);
    rep(i,n) scanf("%d", &vec.at(i));
    bool OK[2];
    rep(j,2) {
        int i=0, m=1;
        OK[j] = false;
        while (i<m) {
            if (i == n-1) {OK[j] = true; break;}
            m = max(m, i+1+vec.at(i)/10);
            i++;
        }
        reverse(all(vec));
    }
    if (OK[0] && OK[1]) printf("yes\n");
    else printf("no\n");
}


Measured memory_bytes: 3872
n, m = map(int, input().split())
out = set(int(input()) for _ in range(m))
mod = 1000000007
table = [1,1]
for step in range(2, n+1):
    ans = 0
    if step - 1 not in out:
        ans += table[step-1]
    if step - 2 not in out:
        ans += table[step-2]
    ans %= mod
    table.append(ans)

print(table[n])


Measured memory_bytes: 11884
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX + 1];

void maxHeapify(int i){
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    
    if ( l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if ( r <= H && A[r] > A[largest]) largest = r;
    
    if ( largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if ( H < 1 ) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key){
    if (key < A[i]) return;
    A[i] = key;
    while ( i > 1&& A[i/2] < A[i] ){
        swap(A[i], A[i/2]);
        i = i/2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main() {
    int key;
    char com[10];
    
    while ( 1 ){
        scanf("%s", com);
        if ( com[0] == 'e' && com[1] == 'n' ) break;
        if ( com[0] == 'i' ){
            scanf("%d", &key);
            insert(key);
        } else{
            printf("%d\n", extract());
        }
    }
    
    return 0;
}


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

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else 
    #define D(a) 8 
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int a,b,c; cin >> a >> b >> c;
    cout << (b-a == c-b ? "YES" : "NO") << endl;
	
	return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;

int main()
{
	cin>>n;
	if(n==1)cout<<"Hello World"<<endl;
	else
	{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
a_list = list(S)
a_ct = 0
b_ct = 0
c_ct = 0

for i in range(0,3):
    if a_list[i] == 'a':
        a_ct = a_ct + 1

for i in range(0,3):
    if a_list[i] == 'b':
        b_ct = b_ct + 1

for i in range(0,3):
    if a_list[i] == 'c':
        c_ct = c_ct + 1

if a_ct == 1 and b_ct == 1 and c_ct == 1:
    print('Yes')
else:
    print('No')

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

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

    if(N == 105){
        cout << 1 << endl;
    }
    else if(N < 105){
        cout << 0 << endl;
    }
    else{
        int count = 0;
        int total = 0;
        for(int j = 1; j <= N; j++){
            for(int i = 1; i <= N; i++){
                if(j % i == 0){
                    count++;
                }
            }
            if(count == 8){
                total++;
            }
            count = 0;
            j++;
        }
        cout << total << endl;
    }
}

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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
    // cout << fixed << setprecision(10) << ans << endl;
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

ll sum(vll &v) {return accumulate(all(v), 0LL);}

int main(){
    ll x, ans=0;
    cin >> x;
    ans += (x/500)*1000;
    ans += (x%500/5)*5;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_CHAR_MAX		100005									// 最大文字数

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Str[D_CHAR_MAX];									// 文字列
static int siCCnt;												// 文字数
static int siRCnt;												// 回転数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 文字数・回転数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siCCnt, &siRCnt);

	// 文字列 - 取得
	fgets(&sc1Str[1], sizeof(sc1Str) - 1, szpFpI);

	// 幸福人数・グループ数 - 取得
	int liHCnt = 0;
	int liGCnt = 0;
	for (i = 1; i <= siCCnt; i++) {
		if (sc1Str[i] == sc1Str[i - 1]) {
			liHCnt++;
		}
		else {
			liGCnt++;
		}
	}

	// ２グループ回転
	int liRCnt = (liGCnt - 1) / 2;
	if (liRCnt > siRCnt) {
		liRCnt = siRCnt;
	}
	liHCnt += liRCnt * 2;
	liGCnt -= liRCnt * 2;
	siRCnt -= liRCnt;

	// １グループ回転
	if (liGCnt > 1 && siRCnt > 0) {
		liHCnt++;
		liGCnt--;
		siRCnt--;
	}

	return liHCnt;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, T, A;
    cin >> N >> T >> A;
    ll ans = -1;
    double diff = INT_MAX;
    for (ll i = 0; i < N; i++) {
        ll H;
        cin >> H;
        double t = T - H * 0.006;
        double d = abs(t - A);
        if (d < diff) {
            ans = i;
            diff = d;
        }
    }

    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n, a, b, c, A[100000], B[100000], C[100000];
int main()
{
    //freopen("VACATION.inp", "r", stdin);
    cin >> n;
    cin >> a >> b >> c;
    A[0] = a; B[0] = b; C[0] = c;
    n--;
    int j = 1;
    while (n > 0)
    {
        cin >> a >> b >> c;
        A[j] = max(B[j-1], C[j-1]) + a;
        B[j] = max(A[j-1], C[j-1]) + b;
        C[j] = max(A[j-1], B[j-1]) + c;
        j++;
        n--;
    }
    cout << max(A[j-1], max(B[j-1], C[j-1]));
    return 0;
}


Measured memory_bytes: 1408
def resolve():
    '''
    code here
    '''
    S = input()
    T = input()

    for i in range(len(T)):
        new_T = T[i:] + T[:i]
        if new_T == S:
            print('Yes')
            break
    else:
        print('No')

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

ll n, t;

int main() {
	cin >> n >> t;
	ll ans = 0;
	ll l = 0, r = 0;
	REP(i, n) {
		ll tt;
		cin >> tt;
		if (r < tt) {
			ans += (r - l);
			l = tt;
		}
		r = tt + t;
	}
	ans += (r - l);
	cout << ans << endl;
}

Measured memory_bytes: 384
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    if (N % 2 == 0)
    {
        cout << N / 2 << endl;
    }
    else
    {
        cout << N / 2 + 1 << endl;
    }
    return;
}

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


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

int main(){
  char S[30] = {};
  scanf("%s", S);

  for(int i = 0; i < strlen(S); i++){
    for(int j = i + 1; j < strlen(S); j++){

      if(S[i] == S[j]){
        printf("no\n");
        return 0;
      }

    }
  }

  printf("yes\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
char dat[100][100];
int main(){
    int a, b, t, k;
    cin >> a >> b;
    for (int i=0; i<100; i++)
        for (int j=0; j<100; j++)
            dat[i][j] = '.';
    for (t=0; t<b; t++)
        dat[(t%50)*2+1][(t/50)*2+1] = '#';
    for (k=0; k<a-1; k++) {
        dat[(k%50)*2+1][(k/50)*2] = '#';
        dat[(k%50)*2][(k/50)*2+1] = '#';
        dat[(t%50)*2+1][(t/50)*2+1] = '#';
        t++;
    }
    if (a > 1)
        t--, dat[(t%50)*2+1][(t/50)*2+1] = '.';
    cout << "100 100" << endl;
    for (int i=0; i<100; i++) {
        for (int j=0; j<100; j++)
            cout << dat[i][j];
        cout << '\n';
    }
}

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

int main()
{
	stack<int> train ;
	int i ;

	while( cin >> i )
	{
		if( i != 0 )
		{
			train.push(i) ;
		}
		else
		{
			cout << train.top() << "\n" ;
			train.pop() ;
		}
	}
	return 0 ;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
 
 
 
 
 
 
int main()
{
	int n;
	cin>>n;
	long double a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	long double p = 1;
    long double max = pow(10,18);
	for (int i = 0; i < n; ++i)
	{
		p = p*a[i];
		if(p == 0)
		{
			cout<<"0";
			return 0;
		}
		if(p > max)
		{
			cout<<"-1";
			return 0;

		}
	}
	if(p > max)
		cout<<"-1";
	else
	{
		cout<<fixed<<setprecision(0)<<p;
	}
 
	
	return 0;
}
 
 

Measured memory_bytes: 5288
#include<stdio.h>
int main(void)
{
    int r,D,i;
    int num; //x2000の時の数
    
    scanf("%d",&r);
    scanf("%d",&D);
    scanf("%d",&num);
    
    for(i=1;i<=10;i++){
        num=r*num-D;
        printf("%d\n",num);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// CHAR_MAX  = 127
// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    int n, x, y;
    cin >> n >> x >> y;

    map<int, int> mp;

    rep(i, 1, n) {
        rep(j, i, n + 1) {
            int d = min(j - i, abs(i - x) + abs(j - y) + 1);
            mp[d] += 1;
        }
    }

    for (int k = 1; k < n; k++) {
        cout << mp[k] << '\n';
    }

    return 0;
}


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

int main() {    
    int N, X; cin >> N >> X;
    vector<int> L(N, -1);
    ll sum = 0;
    rep(i,N) cin >> L.at(i);
    for(int i=0; i<N; i++){
        sum += L.at(i);
        
        if(X<sum) {
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << N+1 << endl;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(ll i=(x);i<(y);i++)
#define RREP(i,x,y) for(ll i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

long long modPow(long long a, long long x, long long p) {
    long long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

long long modInverse(long long a, long long p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}

long long modFactorial(long long a, long long p) {
    long long fact = 1;
    for (long long i=2; i<=a; i++) {
        fact *= i;
        fact %= p;
    }
    return fact;
}

long long combination(long long n, long long k, long long p) {
    // calculates C(n,k) mod p (assuming p is prime).

    long long numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    long long denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}


class EAlmostEverywhereZero {
public:
    void solve(std::istream& in, std::ostream& out) {
        string N;
        int K;
        in >> N >> K;

        // dp[by top i digits][already k non zero digit][already smaller than N]
        vector<vector<vector<ll>>> dp(N.size()+1, vector<vector<ll>>(K+2, vector<ll>(2, 0)));
        dp[0][0][0] = 1;
        REP(i,1,N.size()+1) {
            REP(smaller, 0, 2) {
                REP(k,0,K+1) {
                    REP(x,0,(smaller ? 10 : (N[i-1] - '0' + 1))) {
                        dp[i][k + (x != 0)][smaller || x < (N[i-1] - '0')] += dp[i-1][k][smaller];
                    }
                }
            }
        }
        out << (dp[N.size()][K][1] + dp[N.size()][K][0]) << "\n";
    }
};


signed main() {
    EAlmostEverywhereZero solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){
        cout<<1<<endl;
    }else if(a==b || b==c || c==a){
        cout<<2<<endl;
    }else{
        cout<<3<<endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a[1010];
int main(){
	int n,k,i,ans=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(i=1;i<=k;i++)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    int n, i, a[100000], p, j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    if(n==2)
    {
        i=a[1];
    }
    else
    {
    for(i=a[1];;i--)
    {
        p=1;
        for(j=0;j<n;j++)
        {
            if(a[j]%i!=0)
            {
               p=p+1;
            }
            if(p==3)
            break;
        }
        if(p==1||p==2)
            break;
    }
    }
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 640
import collections

def main() :
	N = int(input())
	li = [int(i) for i in input().split()]

	c = collections.Counter(li)

	total_count = 0
	for key in c.keys() :
		count = c[key]

		if (count == key) :
			continue
		elif (count > key) :
			total_count += (count - key)
		else  :
			# all remove
			total_count += count

	print(total_count)


main()



Measured memory_bytes: 18676
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    // let stdin = stdin.lock();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().unwrap_or_else(|_| panic!("Faild to parse {}", s))
}

fn main(){
    let n: usize = read();
    let m: usize = read();
    let mut from1 = vec![false; n + 1];
    let mut fromn = vec![false; n + 1];
    for _ in 0..m {
        let a: usize = read();
        let b: usize = read();
        from1[b] |= a == 1;
        from1[a] |= b == 1;
        fromn[b] |= a == n;
        fromn[a] |= b == n;
    }
    let flg = from1.iter().zip(fromn.iter()).fold(false, |acc, (&a, &b)| acc || a && b);
    println!("{}", if flg { "POSSIBLE" } else { "IMPOSSIBLE" });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
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; }

int main()
{
  //input
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  //main
  
  
  // output
  if(e-a > k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
B = []
C = []
for i, a in enumerate(A):
  B.append(i+1+a)
  C.append(i+1-a)
cb = Counter(B)
cc = Counter(C)
ans = 0
for k, v in cb.items():
  ans += v*cc[k]
print(ans)

Measured memory_bytes: 63284
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

string s;

int main()
{
    cin >> s;
    cout << (s.size() % 2 == (s[0] == s[s.size() - 1]) ? "Second" : "First") << "\n";
}

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

int main() {
    int N; cin >> N;
    vector<pair<int,int>> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i).first;
        A.at(i).second = i;
    }
    sort(A.begin(),A.end());
    for(int i = 0; i < N; i++)
        if(i != N-1)
            cout << A.at(i).second+1 << " ";
        else {
            cout << A.at(i).second+1 << endl;
        }
}


Measured memory_bytes: 1664
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}
int a,b,c;
main(){
	cin>>a;
	dump((a/2)*(a-a/2));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N;
  ll A, B; cin >> N >> A >> B;
  vector<ll> X(N);
  rep(i, N) cin >> X[i];

  ll ans = 0LL;
  rep(i, N-1) {
    ll dist = A * (X[i+1] - X[i]);
    ans += min(dist, B);
  }

  cout << ans << endl;

  return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> road(N);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    road.at(a-1) += 1;
    road.at(b-1) += 1;
  }
  for(int i = 0; i < N; i++){
    cout << road.at(i) << endl;
  }
}


Measured memory_bytes: 3592
from collections import Counter
from functools import reduce
import operator
product = lambda it: reduce(operator.mul,it,1)

def comb(n, max_k, mod):
    """
    (n,k) := n個からk個選ぶ組み合わせ
    k = 0~max_Kまでを計算して返す
    """
    res = [1]*(max_k+1)
    t = 1
    for i in range(max_k+1):
        res[i] *= t
        t *= n-i
        t %= mod

    n = reduce(lambda x,y: (x*y)%mod, range(1,max_k+1), 1)
    n = pow(n, mod-2, mod)

    for i in reversed(range(max_k+1)):
        res[i] *= n
        res[i] %= mod
        n *= i
        n %= mod
    return res

# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

MOD = 10**9+7
N,M = map(int,input().split())

factors = Counter(prime_factors(M))

res = 1

for c in factors.values():
    res *= comb(N-1+c,c,MOD)[-1]
    res %= MOD

print(res)

Measured memory_bytes: 9464
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T> *A) {
  for (auto itr = A->begin(); itr < A->end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(vector<T> *A) {
  for (auto itr = A->begin(); itr < A->end(); ++itr) cout << *itr << " ";
  cout << endl;
}

static inline void MainTask() {
  uint32_t n;
  cin >> n;
  vector<uint32_t> d(n);
  ArrayInput(&d);
  sort(d.begin(), d.end());
  cout << d[n / 2] - d[(n / 2) - 1] << endl;
}

int main() {
  MainTask();

  return 0;
}


Measured memory_bytes: 640
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
from collections import deque
#======================================================#
def main():
    h, w = MII()
    ch, cw = MII()
    dh, dw = MII()
    maze = [IS() for _ in range(h)]
    dq = deque([(ch-1, cw-1)])
    check = [[-1]*w for i in range(h)]
    check[ch-1][cw-1] = 0
    count = 0

    # 判定式
    inMaze = lambda x,y: 0 <= y < h and 0 <= x < w
    isWall = lambda x,y: maze[y][x] == '#'
    isChecked = lambda x,y: check[y][x] != -1
    allCheck = lambda x,y: (not inMaze(x,y)) or isWall(x,y) or isChecked(x,y)

    # 移動先
    walk = [(0,1), (0,-1), (1,0), (-1,0)]
    warp = [(dy, dx) for dy in range(-2,3) for dx in range(-2,3)]

    while True:
        walked = []
        while dq:
            y, x = dq.popleft()
            walked.append((y, x))
            for dy, dx in walk:
                ny = y+dy
                nx = x+dx
                if allCheck(nx, ny):
                    continue
                check[ny][nx] = count
                dq.appendleft((ny, nx))

        count += 1
        for y, x in walked:
            for dy, dx in warp:
                ny = y+dy
                nx = x+dx
                if allCheck(nx, ny):
                    continue
                check[ny][nx] = count
                dq.append((ny, nx))
        if not dq:
            break

    print(check[dh-1][dw-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 84948
#include<stdio.h>
int main(void) {
  int x,a,b;
  scanf("%d %d %d",&x,&a,&b);
  if(b-a<=0){
    printf("delicious\n");
  }else if(b-a<=x){
    printf("safe\n");
  }else{
    printf("dangerous\n");
  }
  return 0;
}

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005

ll dp[10005][101][2];
vector<int> digit;
int d;
ll solve(int id,int sum,int y){
if(id<0){
    if(sum%d==0)
        return 1;
    return 0;
}
if(dp[id][sum][y]!=-1)return dp[id][sum][y];
ll ways=0;
int k=y?digit[id]:9;
for(int i=0; i<=k; ++i){
    int ny=(digit[id]==i)?y:0;
    int nsum=(sum+i)%d;
    ways=(ways+solve(id-1,nsum,ny))%mod;
}
return dp[id][sum][y]=ways;
}


int main(){
sp;
    string a;
    cin>>a>>d;
    memset(dp,-1,sizeof dp);
    for(int i=a.size()-1; i>-1; --i)digit.pb(a[i]-'0');
    ll x=solve(a.size()-1,0,1);
    cout<<(x-1+mod)%mod<<"\n";
return 0;}


Measured memory_bytes: 17152
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
cnt = 0

(N - 1).downto(0) do |i|
  k = i + 1

  # 次の街のモンスターが残る or ちょうど倒す
  if A[k] >= B[i]
    cnt += B[i]
    A[k] -= B[i]
    next
  end

  # 勇者が倒せる数を調整しておく
  B[i] -= A[k]

  # 次の街のモンスターを倒しきったことにする
  cnt += A[k]
  A[k] = 0

  # 今の街のモンスターが残る or ちょうど倒す
  if A[i] >= B[i]
    cnt += B[i]
    A[i] -= B[i]
    next
  end

  # 今の街のモンスターを倒し切ったことにする
  cnt += A[i]
  A[i] = 0
end

puts cnt

Measured memory_bytes: 15380
N, A, B = map(int, input().split())
count0, count1 = 0, 0
a = input()
for val in a:
    if val is 'a' and count0+count1 < A+B:
        count0 += 1
        print('Yes')
    elif val is 'b' and count1 < B and count0+count1 < A+B:
        count1 += 1
        print('Yes')
    else:
        print('No')
    


Measured memory_bytes: 9296
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
char s[10010];
int szS;


int main()
{
	scanf("%d\n", &n);
	scanf("%s\n", s);
	szS = strlen(s);
	
	for (int i = 0 ; i < szS ; i++)
	{
		s[i] = 'A' + (s[i] - 'A' + n) % 26;
	}
	
	printf("%s\n", s);
	
		
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
	int n, num[101] = {0};
	int mode[100] = {0};

	while (cin >> n) {
		num[n]++;
	}
	for (int i = 1; i <= 101; i++) {
		if (num[i] != 0) {
			if (num[i] == num[mode[0]]) {
				for (int j = 0; j < 100; j++) {
					if (mode[j] == 0) {
						mode[j] = i;
						break;
					}
				}
			}
			else if (num[i] > num[mode[0]]) {
				for (int j = 0; j < 100; j++) {
					mode[j] = 0;
				}
				mode[0] = i;
			}
		}
	}
	for (int i = 0; i < 100; i++) {
		cout << mode[i] << endl;
		if (mode[i + 1] == 0) {
			break;
		}
	}
}

Measured memory_bytes: 3040
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1000000000
 
using namespace std;

// bool chkcom( int x ,int y , int a , int b )
// {
//     if ( (x <= a && y >= b) || ( x > a && x < b && y >= b ) || ( y > a && y < b && x <= a ))
//     {
//         return true;
//     }
//     else
//     {
//         return false;
//     }
// }
 
signed main()
{
    fast;
    int n;
    cin>>n;

    vector< pair<int,int> > p;

    for ( int i = 0 ; i < n ; i++ )
    {
        int a,b;
        cin>>a>>b;

        p.push_back(make_pair(a+b,a-b));
    }

    sort(p.begin(),p.end());
    int curr = -inf;
    int ans = 0;
    for ( int i = 0 ; i < p.size() ; i++ )
    {
        if ( curr <= p[i].second )
        {
            curr = p[i].first;
            ans++;
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2420
N, M, Q = gets.split.map(&:to_i)
S = Q.times.map { gets.split.map(&:to_i) }

def calc_score(nums)
  score = 0

  S.each do |a, b, c, d|
    next if nums[b] - nums[a] != c

    score += d
  end

  score
end

def dfs(n, nums)
  score = 0

  if n == N + 1
    return calc_score(nums)
  else
    (nums[n - 1]..M).each do |m|
      nums[n] = m
      s = dfs(n + 1, nums)
      score = s if score < s
    end
  end

  score
end

nums = Array.new(N + 1, -1)
nums[0] = 1
puts dfs(1, nums)


Measured memory_bytes: 14180
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define fone for(i=0;i<n;i++)
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N          = 5000*100+1;
const ll N2      = 1000*1000;
const ld PI  = 3.14159265;
const ll R   = 250;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
    }

    int main()
    {
      int n,m;
      cin>>n>>m;
      if(n==m)
      {
        cout<<"Yes";
      }
      else
      {
        cout<<"No";
      }

return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cstring>
#include <cstdio>
#include <map>
  
using namespace std; 
  
int main() 
{ 
    int n, k;

    scanf("%d %d", &n, &k);
    
    int a[n];

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

    int maior = 0;

    for(int i = 0; i < n; i++){
	    if(a[i] >= k){
		    maior++;
	    }
    }

    printf("%d\n", maior);
    return 0; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

void solver(int n, vector<int> a) {
  ll ans = 0;
  int mx = 0;
  REP(i,n) {
    if (mx <= a[i]) {
      mx = a[i];
    } else {
      ans += mx - a[i];
    }
  }
  COUT(ans);

  return;
}

int main() {
  IOS;
  int n; cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  solver(n,a);

  return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <cmath>


int main () {
    int n, k;
    std::cin >> n >> k;
    int h[n], dp[n];

    for (int i = 0; i < n; ++i) {
        std::cin >> h[i];
        dp[i] = 1000000000;
    }

    dp[0] = 0;

    for(int i = 0; i < n; ++i) {
        for(int j = 1; j <= k && i+j < n; ++j){
            if (dp[i+j] > dp[i] + std::abs(h[i] - h[i+j])) {
                dp[i+j] = dp[i] + std::abs(h[i] - h[i+j]);
            }
        }
    }

    std::cout << dp[n-1] << std::endl;

}

Measured memory_bytes: 4400