akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

bool ps(string str){
	for(ll i=0 , j=str.length()-1;i<j;i++,j--){
		if(str[i]!=str[j])return 0;
	}
	return 1;
}

bool check(string str , ll n ){
	string str1,str2;
	str1=str.substr(0,(n-1)/2);
	str2=str.substr((n+1)/2);
	// cerr<<str1<<" "<<str2<<" "<<str;
	if(ps(str1) && ps(str2) && ps(str))return 1;
	return 0;
}

int main(){
	//mahakal(),fast;
	
	ll n ;
	cin>> n ;
	long double a=n/3.0,b=n/3.0,c=n/3.0;
	long double ans = a*b*c;
	cout<<fixed<<setprecision(14)<<ans<<endl;
	return 0;
}

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

int main(){
  string s; cin>>s;
  long long ans=0,t=0,n; n=s.size();
  for(int i=0;i<(1<<(n-1));i++){
    t=s[0]-'0';
    for(int j=0;j<n;j++){
      if(j==n-1||i&1<<j){
        ans+=t;
        t=0;
      }
      t*=10;
      t+=s[j+1]-'0';
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


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

    if(K==1) pl(0)
    else {
        pl(N-K)
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> v[n];
  rep(i,m) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
  }
  ll s,t;
  cin >> s >> t;
  s--,t--;
  ll d[n][3];
  rep(i,n)rep(j,3)d[i][j]=MAX;
  queue<P> que;
  que.push(P(s,0));
  d[s][0]=0;
  while(!que.empty()) {
    P p=que.front();que.pop();
    ll x=p.F,k=p.S;
    rep(i,v[x].size()) {
      ll y=v[x][i];
      if(d[y][(k+1)%3]>d[x][k]+1) {
        d[y][(k+1)%3]=d[x][k]+1;
        que.push(P(y,(k+1)%3));
      }
    }
  }
  if(d[t][0]==MAX) pr(-1);
  else pr(d[t][0]/3);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

const int INF = 1 << 25;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int b[50][50];
int dist[50][50][50][50];

int W, H;

struct S {
	int x1, y1, x2, y2, d;
};

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

	while(cin >> W >> H, W + H) {
		int sx[2], sy[2];
		for(int i = 0; i < 2; i++) {
			cin >> sx[i] >> sy[i];
			sx[i]--, sy[i]--;
		}
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> b[i][j];
			}
		}

		fill((int*)begin(dist), (int*)end(dist), INF);
		dist[sy[0]][sx[0]][sy[1]][sx[1]];
		queue<S> q;
		q.push({ sx[0], sy[0], sx[1], sy[1], 0 });
		while(q.size()) {
			int x[2] = { q.front().x1, q.front().x2 };
			int y[2] = { q.front().y1, q.front().y2 };
			int d = q.front().d;
			q.pop();
			if(d == 99) break;
			if(dist[y[0]][x[0]][y[1]][x[1]] < d) continue;
			for(int k = 0; k < 4; k++) {
				int nx[2] = { x[0] + dx[k], x[1] - dx[k] };
				int ny[2] = { y[0] + dy[k], y[1] - dy[k] };
				for(int i = 0; i < 2; i++) {
					if(nx[i] < 0 || W <= nx[i] || b[ny[i]][nx[i]]) nx[i] = x[i];
					if(ny[i] < 0 || H <= ny[i] || b[ny[i]][nx[i]]) ny[i] = y[i];
				}
				if(dist[ny[0]][nx[0]][ny[1]][nx[1]] > d + 1) {
					dist[ny[0]][nx[0]][ny[1]][nx[1]] = d + 1;
					q.push({ nx[0], ny[0], nx[1], ny[1], d + 1 });
				}
			}
		}

		int ans = INF;
		for(int y = 0; y < H; y++) {
			for(int x = 0; x < W; x++) {
				ans = min(ans, dist[y][x][y][x]);
			}
		}
		if(ans != INF) {
			cout << ans << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

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

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

  ll H; cin >> H;
  ll ans = 0;
  ll cnt = 1;
  while (H > 0) {
    ans += cnt;
    cnt *= 2;
    H /= 2;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  long long A, B, T;

  cin >> A >> B >> T;
  long long N=0;
  long long C = T / A;
  for (long long i=0;i<C;++i) {
    N += B;    
  }
  cout << N << std::endl;

  return 0;
}

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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=n;
    if(x>=b) x=b-1;
    cout<<a*x/b;
}


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

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

    vector< long long > arr(n);
    for(int i=0;i<n;i++)cin>>arr[i];

    long long l(1),r(1e9+7);

    while(l<=r)
    {
        long long mid=l+(r-l)/2;
        long long cnt(0);
        for(int i=0;i<n;i++)
            cnt+=max( double(0) , ceil((1.0*arr[i]-mid*b)/(a-b)) );
      //  cout<<l<<" "<<r<<" "<<cnt<<" "<<mid<<"\n";
        if(cnt<=mid)
        r=mid-1;
        else
        l=mid+1;
    }
    cout<<l;
    return 0;
}


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

enum state {Await,Accum};
typedef enum state State;

int main(){

    char x[200001];
    scanf("%s", x);

    int res = 0;
    size_t state = 0;
    for (int i = 0; x[i] != '\0'; ++i) {
        if (x[i] == 'S') {
            ++state;
        } else if (state > 0) {
            --state;
            ++res;
        }
    }


    printf("%lu\n", strlen(x)-2*res);
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int a, b, h;
    io.read(a, b, h);
    cout << (a + b) * h / 2;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = np.array([int(i) for i in input().split()])

    max_dp = np.max(A) + 1
    dp = np.zeros(max_dp, dtype="int32")

    for a in A:
        if dp[a] >= 2:
            continue
        fancy = np.arange(a, max_dp, a)
        dp[fancy] += 2
        dp[a] -= 1
    print(np.sum(dp == 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 51288
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll n,k;
    cin >> n >> k;
    ll i;
    ll ans=1;
    for(i=0;i<n;i++){
      ans=min(ans*2,ans+k);
    }
    cout << ans <<endl;
    return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);

  int odd_count = 0;
  for (int i = 0; i < N; i++) {
    int A = 0;
    scanf("%d", &A);
    if (A % 2 != 0) odd_count++;
  }

  if (odd_count % 2 == 0)
    printf("YES");
  else
    printf("NO");
}

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

int n, i = 1, ans;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	cin >> n;
	int a[n + 1];
	vector<bool> v(n + 1, 0);
	
	rep(i, 1, n)
		cin >> a[i];

	while (!v[i] && !v[2]) {
		v[i] = 1;
		i = a[i];
		ans++;
	}
	cout << ans * v[2] - 1;
}

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

typedef long long ll;
typedef vector<int> vi;

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

;int main(){
    int n;
    ll k;
    cin >> n >> k;
    vector<pair<int, int>> vp;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        vp.push_back(make_pair(a, b));
    }

    sort(vp.begin(), vp.end());
    int aa[100000], bb[100000]; 
    rep(i, n){
        aa[i] = vp[i].first;
        bb[i] = vp[i].second;
    }

    rep(i, n){
        if(bb[i] >= k){
            cout << aa[i] << endl;
            return 0;
        }
        else{
            k -= bb[i];
        }
    }

    return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, k;
    cin >> n >> k;
    vll a(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }
    ll id = 0, cur = 0, syu;
    vll first(n, -1);
    while (1) {
        id++;
        cur = a[cur];
        if (first[cur] != -1) {
            syu = id - first[cur];
            break;
        }
        first[cur] = id;
    }
    // cout << cur << " " << first[cur] << " " << syu << endl;
    ll res = 0, mem = min(k, first[cur] + (k - first[cur]) % syu);
    REP(i, mem) {
        res = a[res];
    }
    res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6368
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String s1 = s.next();
        int count = 0, res = 0;
        int count1 = 0, res1 = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (s1.charAt(i) == '-') {
                count++;
            } else {
                count1++;
            }

        }
        System.out.println(-count + count1);

    }
}


Measured memory_bytes: 21716
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) long long((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;

set<int> fact(ll m) {
    set<int> ret;
    for (ll i = 2; i * i <= m; i++) {
        if (m % i == 0) {
            while (m % i == 0) {
                ret.insert(i);
                m /= i;
            }
        }
    }
    if (m != 1) {
        ret.insert(m);
        m = 1;
    }
    return ret;
}

int main() {
    ll a, b;
    cin >> a >> b;
    set<int> dicA = fact(a), dicB = fact(b);
    int cnt = 0;
    for (auto i : dicA) {
        if (dicB.find(i) != dicB.end()) cnt++;
    }
    OUT(cnt + 1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int now_p, int N, bool visited[nmax])
{
    bool all_visited = true;
    rep(i,N)
    {
        if (!visited[i]) all_visited = false;
    }
    if (all_visited) return 1;
    int ret = 0;
    rep(i,N) {
        if (!graph[now_p][i]) continue;
        if (visited[i]) continue;
        visited[i] = true;

        ret += dfs(i, N, visited);
        visited[i] = false;
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    rep(i,n) rep(j,n) graph[i][j] = false;
    rep(i,m)
    {
        int x,y;
        cin >> x >> y;
        --x;--y;
        graph[x][y] = true;
        graph[y][x] = true; 
    }
    bool visited[n];
    rep(i,8) visited[i]=false;
    visited[0] = true;
    
    cout << dfs(0, n, visited) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int x, y;
   scanf("%d%d", &x, &y);
   int a, b;
   for(a = 0; a <= x; a++){
       b = x - a;
       if(y == 2*a + 4*b){
          printf("Yes\n"); 
          return 0;
        }
   }
   printf("No\n");
   return 0;
}

Measured memory_bytes: 1664
A,B,C = [int(x) for x in input().split()]
K = int(input())
for b in range(0,K+1):
    if A < B * 2**b:
        kb = b
        break
if B * 2**kb < C * 2**(K-kb):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi; 
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_B() {}

// The maximum count of dividing n by 2
int func(int n) {
    if (n % 2 == 1) return 0;
    return func(n / 2) + 1;
}

int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
   
    int cnt = 0;
    int ans = 0;
    FOR(i,1,N+1) {
        //cnt = max(cnt, func(i));
        int t = func(i);
        if (t >= cnt) {
            cnt = t;
            ans = i;
        }
    }

    //int ans = 0x01 << cnt;
    cout << ans << endl;

    return 0;
}

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

int main(){

    string g;
    int y, m, d;
    while(cin >> g){
        if(g=="#")break;
        cin >> y >> m >> d;
        int hoge = y * 10000 + m * 100 + d;
        if(hoge > 310430){
            cout << "?" << " " << y - 30 << " " << m << " " << d << endl;
        }
        else{
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3176
#include <iostream>
 
using namespace std;
 
int main() {
  int N, NN, a = 0; cin >> N;
  NN = N;
  while(N > 0) {
    a += N % 10;
    N /= 10;
  }
  if(NN % a == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long i,n,j,k,c=0;
 cin>>n;
 long long A[n],B[n];
 for(i=0;i<n;i++)
 cin>>A[i];
 for(i=0;i<n;i++)
 cin>>B[i];
for(i=0;i<n;i++)
  if(A[i]-B[i]>0) c+=(A[i]-B[i]);

cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3596
fun main(args: Array<String>) = yorukatsu17b()

fun yorukatsu17b() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (1..h).map { readLine()!!.toCharArray() }

    val answer = grid.mapIndexed { y, row ->
        row.mapIndexed { x, c ->
            if (c == '#') c else {
                around.map { y + it.first to x + it.second }
                    .filter { it.first in 0 until h && it.second in 0 until w }
                    .count { grid[it.first][it.second] == '#' }
            }
        }.joinToString("")
    }.joinToString(System.lineSeparator())

    println(answer)
}

private val around = (-1..1).map { i1 -> (-1..1).map { i2 -> i1 to i2 } }.flatten().filterNot { it == 0 to 0 }


Measured memory_bytes: 38756
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
#include<climits>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#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 mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul    = unsigned long;
using ll    = long long;
using ull   = unsigned long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using vull   = vector<ull>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)



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

	int n;
	cin >> n;

	vull a(n);
	REP(i, n){
		cin >> a[i];
		if(a[i]==0){
			cout << 0 << endl;
			return 0;
		}
	}

	ull ans = 1;
	REP(i, n){
//		if(ans)

		ans *= a[i];
		if(ans < 1 || ans > 1000000000000000000LL){
			cout << -1 << endl;
			return 0;
		}
	}

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3976
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(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 debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    cout << n / 3 << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ll n;
    cin >> n;
    vi num(200);
    rep(i, 100) {
        num[i] = i+1;
    }
    n++;

    int now = 0, cou = 0;
    ll x = 1;
    while(n) {
        if(n&1) {
            num[100+now+cou] = 100-cou;
            cou++;
        }
        now++;
        n >>= 1;
    }
    now -= 2;
    rep(i, now) {
        int j = 100;
        while(num[j]) j++;
        num[j] = i+1;
    }

    vi::iterator itr = find(all(num), 0);
    int m = itr-num.begin()+1;
    cout << m << endl;
    rep(i, m) {
        if(i == m-1) i++;
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
n0=0
print(n0)
s=input()
if s=='Vacant':
    exit()
sl=s    # 席lに座っている人の性別
l,r=0,n # 開区間
m=(l+r)//2 # 中央の座標
print(m)
sm=input()
while sm!='Vacant' and l<r:
    if sm==sl and (m-l)%2==0:
        l=m
        sl=sm
    elif sm!=sl and (m-l)%2==1:
        l=m
        sl=sm
    else:
        r=m
    m=(l+r)//2
    print(m)
    sm=input()
if l>=r:
    print(l,r)


Measured memory_bytes: 3660
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define vvii vector<vector<pii>>
#define vvll vector<vector<ll>>
#define umap unordered_map
#define uset unordered_set
#ifdef LOCAL
#define debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define debugrep(i, a, b) for (int i = a; i < b; i++)
#define check(...) assert(__VA_ARGS__)
#else
#define debug(fmt, ...)
#define debugrep(i, a, b)
#define check(...)
#endif

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a + b >= k) {
        cout << min(a, k);
    } else {
        cout << a - (k - a - b);
    }
}


Measured memory_bytes: 3192
import heapq
t = int(input())
for _ in range(t):
    n = int(input())
    L, R = [], []
    N = [[] for j in range(n)]
    P = [[] for j in range(n + 1)]
    for i in range(n):
        k, l, r = map(int, input().split())
        if l - r > 0:
            N[k - 1].append(i)
        else:
            P[k].append(i)
        L.append(l)
        R.append(r)
    ans = sum([min(L[i], R[i]) for i in range(n)])
    S, T = [], []
    for j in range(n):
        for i in N[j]:
            heapq.heappush(S, L[i] - R[i])
        for i in P[n - 1 - j]:
            heapq.heappush(T, R[i] - L[i])
        while len(S) > j + 1:
            heapq.heappop(S)
        while len(T) > j + 1:
            heapq.heappop(T)
    print(ans + sum(S) + sum(T))


Measured memory_bytes: 139800
n, x, y = map(int, input().split())
ans = [[n]*n for i in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j] = abs(i-j)

ans[x-1][y-1] = 1
ans[y-1][x-1] = 1
for i in range(n):
  for j in range(n):
    if ans[i][j] > ans[i][x-1]+ans[x-1][j]:
      ans[i][j] = ans[i][x-1]+ans[x-1][j]
    
for i in range(n):
  for j in range(n):
    if ans[i][j] > ans[i][y-1]+ans[y-1][j]:
      ans[i][j] = ans[i][y-1]+ans[y-1][j]

answer = [0]*(n-1)
for i in range(n):
  for j in range(n):
    if ans[i][j] == n or ans[i][j] == 0:
      continue
    answer[ans[i][j]-1] += 1
for i in range(n-1):
  print(answer[i]//2)

Measured memory_bytes: 77788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <string.h>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

#ifndef INT_MAX
#  define INT_MAX std::numeric_limits<int>().max()
#endif
#ifndef INT_MIN
#  define INT_MIN std::numeric_limits<int>().min()
#endif
#define LL_MAX std::numeric_limits<ll>().max()
#define LL_MIN std::numeric_limits<ll>().min()
#define INF LL_MAX

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
// 配列の初期化
#define ZERO(p) memset(p, 0, sizeof(p))
// 配列の初期化(-1)
#define MINUS(p) memset(p, 1, sizeof(p))

int N;

int main()
{
    int max_a = -10000;
    int min_a = 100000;
    cin >> N;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        max_a = max(max_a, tmp);
        min_a = min(min_a, tmp);
    }
    printf("%d\n", max_a - min_a);
    return 0;
}


Measured memory_bytes: 384
n,k   = map(int,input().split())
mod = 10**9+7
kaijou = [1]
gyakugen = [1]
for i in range(1,n+1):
    nextk = kaijou[-1]*i%mod
    kaijou.append(nextk)
    nextg = pow(i,mod-2,mod)
    gyakugen.append(nextg*gyakugen[-1]%mod)
def nck(n,k,mod,kaijou,gyakugen):
    if n<= k:return 1
    return kaijou[n]*gyakugen[n-k]%mod*gyakugen[k]%mod
for i in range(1,k+1):
    if n-k+1 < i or k < i:
        print(0)
        continue
    ans = nck(n-k+1,i,mod,kaijou,gyakugen)*nck(k-1,i-1,mod,kaijou,gyakugen)%mod
    print(ans)
    

Measured memory_bytes: 41840
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll n2 = 0, n4 = 0;
    rep(i,n){
        if(v[i]%4==0) n4++;
        else if(v[i]%2==0) n2++;
    }
    if(n4*2+1 >=n){
        cout << "Yes" << endl;
        return 0;
    }
    else if(n4>=1){
        if(n2>=n-n4*2)cout<<"Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    else if(n2>=n){
        cout << "Yes" << endl;
        return 0;
    }
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

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

bool solve(string s){
    int N = s.size();
    
    for(int i = 0; i < N; i++){
        if (s[i] != s[N-1-i]) return false; 
    }
    
    int first = 0, end = (N - 1) / 2;
    for(int i = 0; i < end; i++){
        if (s[i] != s[end-1-i]) return false; 
    }
    
    first = (N + 3) / 2 - 1 , end = N;
    for(int i = first; i < N; i++){
        if (s[i] != s[end-1-i]) return false; 
    }
    
    return true;
}

int main(void){
    int N, M; cin >> N >> M;
    
    int ans = N * (N - 1) / 2 + M * (M - 1) / 2;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
s = list(map(int, input().split("/")))

s[0] = 2018

if s[2] >= 10:
    a = str(s[0]) + "/0" + str(s[1]) + "/" + str(s[2])
    print(a)
else:
    a = str(s[0]) + "/0" + str(s[1]) + "/0" + str(s[2])
    print(a)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

//const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	ll N;
	cin >> N;
	ll q1 = 0;
	ll q2 = (N - 1) / 2;
	string res1, res2;
	cout << q1 << endl;
	cin >> res1;
	if (res1 == "Vacant"){
		return 0;
	}
	cout << q2 << endl;
	cin >> res2;
	if (res2 == "Vacant"){
		return 0;
	}
	ll p1, p2;
	string p1res, p2res;
	if (res1 == res2 && (q2 - q1) % 2 == 1){
		p1 = q1;
		p2 = q2;
		p1res = res1;
		p2res = res2;
	}
	else if (res1 != res2 && (q2 - q1) % 2 == 0){
		p1 = q1;
		p2 = q2;
		p1res = res1;
		p2res = res2;
	}
	else{
		p1 = q2;
		p2 = N;
		p1res = res2;
		p2res = res1;
	}
	ll p3;
	string p3res;
	while (1){
		p3 = p1 + (p2 - p1) / 2;
		cout << p3 << endl;
		cin >> p3res;
		if (p3res == "Vacant"){
			return 0;
		}
		if (p1res == p3res && (p3 - p1) % 2 == 1){
			p2 =  p3;
			p2res = p3res;
			continue;
		}
		else if (p1res != p3res && (p3 - p1) % 2 == 0){
			p2 = p3;
			p2res = p3res;
			continue;
		}
		else{
			p1 = p3;
			p1res = p3res;
			continue;
		}
	}

	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  int ans = 0;
  rep(i,1,n-1){
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
    if (p[i - 1] > p[i] && p[i] > p[i + 1]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int k,a,b;
    cin>>k>>a>>b;
    bool ok=false;
    for(int i=a; i<=b; ++i){
        if(i%k==0)ok=true;
    }
    cout<<(ok?"OK":"NG")<<endl;
    return 0;
}

Measured memory_bytes: 3632
P = 2019
S = input()
N = len(S)
 
if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1
    print(ans)
    exit()
 
num = [0] * P
num[0] = 1
now, ans = 0, 0
_10 = 1
for i in range(N-1, -1, -1):
    now = (now + int(S[i]) * _10) % P
    _10 *= 10
    _10 %= P
    ans += num[now]
    num[now] += 1
 
print(ans)

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	long long x,y;
	while(~scanf("%lld%lld",&x,&y)){
		int ans=0;
		while(y>=x) x*=2,ans++;
		printf("%d\n",ans);
	}
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	int ans=0;
	if(a%2==0) {
	if(a/2<b||a<b) {
		ans=1;
	}
	}
	else {
		if((a+1)/2<b||a<b) {
			ans=1;
		}
	}
	System.out.println(ans==1?"NO":"YES");
}
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int n, cnt[26]; char s[maxn];
inline int inc(int x, int y) {x += y; return x >= mod ? x - mod : x;}
inline int mul(int x, int y) {return (ll)x * y % mod;}
int main()
{
	scanf("%d\n%s", &n, s + 1);
	for (int i = 1; i <= n; i ++)
		++ cnt[s[i] - 'a'];
	int ans = 1;
	for (int c = 0; c < 26; c ++)
		ans = mul(ans, cnt[c] + 1);
	ans = inc(ans, mod - 1);
	printf("%d\n", ans);
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(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};

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

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, m, x, y, r, k[114514];
bool c[114514];

int main() {
	cin >> n >> m;
	c[1] = true;
	fill(k, k+114514, 1);
	rep(i,m) {
		cin >> x >> y;
		if (c[x]) c[y] = true;
		k[x]--, k[y]++;
		if (k[x]==0) c[x] = false;
	}
	cout << accumulate(c, c+114514, 0) << ln;
}

Measured memory_bytes: 896
n = int(input())
ans = [0 for _ in range(n+1)]

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      a = x**2+y**2+z**2+x*y+y*z+z*x
      if a <= n:
        ans[a] += 1
for i in range(1,n+1):
  print(ans[i])


Measured memory_bytes: 69424
import sys

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

d = [[sys.maxsize for _ in range(N)] for _ in range(N)]

for i in range(N):
  for j in range(N):
    d[i][j] = min(abs(j-i), abs(X-i) + 1 + abs(j-Y))

answer = [0 for _ in range(N-1)]

for h in range(N):
  for i in range(h+1, N):
    if h != i:
      answer[d[h][i]-1] += 1

for k in range(N-1):
  print(answer[k])

Measured memory_bytes: 82012
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;

  int a = (N*100)/108;
  int b = (int)a*1.08;
  int c = (int)(a+1)*1.08;

  if(b == N){
    cout << a << endl;
  }else if(c == N){
    cout << a+1 << endl;
  }else{
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> A(N),B(M);
  rep(i,N){
    int a,b;
    cin >> a >> b;
    A.at(i) = make_pair(a,b);
  }
  rep(i,M){
    int c,d;
    cin >> c >> d;
    B.at(i) = make_pair(c,d);
  }
  vector<int> ans(N);

    rep(i,N){
      int min_length = 1e9;
      rep(j,M){
        int length = abs(A.at(i).first - B.at(j).first) 
          + abs(A.at(i).second - B.at(j).second);
        if(length < min_length){
          min_length = length;
          ans.at(i) = j + 1;
        }
      }
    }
  rep(i,N){
    cout << ans.at(i) << endl;
  }

return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, x = MAP()
a = LIST()
count = 0
def reduce_candy(i): # iとi+1のキャンディを減らす
	global count
	if sum_near[i] <= x: # 減らす必要なし
		pass 
	elif sum_near[i] - a[i] <= x: # 左のボックスから全部減らすと条件クリアの場合
		if not i == 0:
			sum_near[i-1] -= sum_near[i] - x
		a[i] -= sum_near[i] - x
		count += sum_near[i] - x
		sum_near[i] = x
	else: # 左のボックスと右のボックスの両方から取り出す必要あり
		if not i == 0:
			sum_near[i-1] -= a[i]
		sum_near[i] -= a[i]
		count += a[i]
		a[i] = 0
		a[i+1] -= sum_near[i] - x
		count += sum_near[i] - x
		sum_near[i] = x
sum_near = []
for i in range(N-1):
	sum_near.append(a[i] + a[i+1])

for i in range(N-2, -1, -1):
	reduce_candy(i)
	# print(count)
	# print(sum_near)
print(count)

Measured memory_bytes: 15036
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define inf 2e18;
#define PI acos(-1)
const int M = 1000000007;
const int N=2e5+5;
//#define local
#ifdef local
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif
void solve()
{
    int n , m  , i ,j;
    cin >> n >> m;
    int a[m];
    int sum=0;
    for(i=0 ;i<m ;i++)
    {
        cin >> a[i];
        sum+=a[i];
    }
    if(sum > n){
        cout << -1 << endl;
    }
    else {
        cout << n - sum << endl;
    }
}

signed main()
{
    int tc=1 , i ,j;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++)
    {
        solve();
    }
}


Measured memory_bytes: 3688
#include<cstdio>
using namespace std;
int main()
{
//	freopen("1.txt","r",stdin);
	int a,b,ans=0,n=0;
	scanf("%d%d",&a,&b);
	for(;n+1<b;++ans)
		n--,n+=a;
	printf("%d",ans);
	return 0;
}

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

main(){
  double moun=0;
  double  max = 0;
  double  min = 100000;
  while(cin >> moun){
    
    if(moun >= max)max = moun;
    if(moun <= min)min = moun;

  }
  printf("%.1f\n",(max - min));
  
}

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

int main(void){
  int x, a, b;
  scanf("%d %d %d",&x,&a,&b);
  if(abs(a-x)>abs(b-x)) printf("B\n");
  else printf("A\n");

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>


int main()
{
	int n, m;
	int h, h_bk;;
	int *box;
	int count;
	int i, j;


	scanf("%d", &n);

	box = (int *)malloc(sizeof(int) * n);

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

	m = 0;
	for(h = 1; h <= n; h = h * 3 + 1)
		m++;
	h_bk = h / 3;

	count = 0;
	for(; h >= 1; h /= 3){
		for(i = h; i < n; i++){
			j = i;
			while(j >= h && box[j - h] > box[j]){
				box[j - h] ^= box[j];
				box[j] ^= box[j - h];
				box[j - h] ^= box[j];
				j -= h;
				count++;
			}
		}
	}


	printf("%d\n", m);

	// 間隔の数列を表示
	for(i = h_bk; i >= 1; i /= 3){
		printf("%d", i);
		if(i != 1)
			printf(" ");
		else
			printf("\n");
	}

	// 交換回数の表示
	printf("%d\n", count);;

	// 整列結果
	for(i = 0; i < n; i++){
		printf("%d\n", box[i]);
/*		if(i != n - 1)
			printf(" ");
		else
			printf("\n");
*/
	}
	
	return 0;
}


Measured memory_bytes: 5652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <cstring>
#include <sstream>

using namespace std;

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

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};

const double EPS = 1e-9;

int solve(vector<int> vec){
    return accumulate(all(vec),0);
}

int main(){
    vector<int> vec(10);
    for(int i=0;i<10;i++){
        cin >> vec[i];
    }
    cout << solve(vec) << endl;
    return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main()
{
     string s,t,u;
     int a,b;
     cin>>s>>t;
     cin>>a>>b;
     cin>>u;
     if(s==u)
          cout<<a-1<<' '<<b;
     else
          cout<<a<<' '<<b-1;


}


Measured memory_bytes: 256
class _Node {
  constructor(key, left = null, right = null) {
    this.key = key;
    this.left = left;
    this.right = right;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    this.root = new BinaryTree.Node(key);
    this.insert = (key) => {
      let x = this.root, y;
      let newNode = new BinaryTree.Node(key);
      while (x !== null) {
        y = x;
        x = x[key < x.key ? 'left' : 'right'];
      }
      y[key < y.key ? 'left' : 'right'] = newNode;
    };
  }

  find(key, n = this.root) {
    if (n === null) return false;
    if (n.key === key) return true;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    console.log(str);
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch(cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    default: tree.print();
    }
  });
})();



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

#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;

int main() {

  int N,M;
  string s;
  
  cin >> N >> M;
  cin >> s;
  
  vector<int> ans;
  
  int i = N;
  
  while(i > 0) {
    int j = max(0,i-M);
    while(j < i && s[j] == '1') j++;
    
    if(j == i) {
      printf("-1\n");
      return 0;
    }
    
    ans.push_back(i-j);
    i = j;
  }
  
  for(auto it = ans.rbegin(); it != ans.rend(); ++it) {
    printf("%d ", *it);
  }
  
  printf("\n");

  return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <ctype.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

using namespace std;
int main() {
	string s; cin >> s;
	s[0] = '2';
	s[1] = '0';
	s[2] = '1';
	s[3] = '8';
	cout << s << endl;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#define double long double
#define ll long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int mod=1e9+7;
const int M=200005;
int n,k;
int a[M];
bool chk(double x)
{
    ll cnt=0;
    f(i,1,n)
    {
        double val=a[i];
        int pc=ceil(val/x);
        cnt+=(pc-1);
    }
    if(cnt>k)return false;
    return true;
}
 main()

{
    fast
    int mx=1;
    scanf("%d%d",&n,&k);
    f(i,1,n)scanf("%d",&a[i]),mx=max(mx,a[i]);
    double lo=0.1;
    double hi=mx;
    int tmp=1000;
    double mn=mx;
    while(tmp--)
    {
       double mid=(lo+hi)/2.00;
       if(chk(mid))
       {
           hi=mid-0.1;
           mn=min(mn,mid);
       }
       else
       {
           lo=mid+0.1;
       }
    }

    int ses=ceil(mn);
    printf("%d\n",ses);
    return 0;

}





































Measured memory_bytes: 4592