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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define RREP(i, a, n) for(int i = (int)(n); i >= a; i--)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

#define MAX 510000
long long fac[MAX], finv[MAX], inv[MAX];

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


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

    ll ans = 1;
    RREP(i, 2, N )
    {
        ans *= COM(i, i-1);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12160
#include <stdio.h>
int main(void){
    int x=0;
    char a,b,c;
    scanf("%c%c%c",&a,&b,&c);
    if(a=='A')x++;
    if(b=='A')x++;
    if(c=='A')x++;

    if(x==3 || x==0)printf("No");
    else printf("Yes");

    return 0;
}




Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>

using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
bool E[200][200];
int state[200];
int N;
int dist[200][200];
bool dfs(int v,int f,int st){
	state[v] = st;
	for(int i=0;i<N;i++){
		if(E[v][i]){
			if(state[i] == 0){
				if(!dfs(i,v,3-st)){
					return false;
				}
			}
			else if(state[i] == st){
				return false;
			}
		}
	}
	return true;
}
bool finished[200];
void Calc(){
	N = rei();
	for(int i=0;i<N;i++){
		string S = res();
		for(int j=0;j<N;j++){
			if(S[j] == '1'){
				E[i][j] = true;
			}
		}
	}
	bool OK = true;
	for(int i=0;i<N;i++){
		if(state[i] == 0){
			OK &= dfs(i,-1,1);
		}
	}
	if(!OK){
		cout << -1 << endl;
		return;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			dist[i][j] = E[i][j] ? 1 : 1000000;
		}
	}
	for(int i=0;i<N;i++){
		for(int k=0;k<N;k++){
			for(int j=0;j<N;j++){
				dist[j][k] = min(dist[j][k],dist[j][i]+dist[i][k]);
			}
		}
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i != j){
				ans = max(ans,dist[i][j]+1);
			}
		}
	}
	cout << ans << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 512
# vim: fileencoding=utf-8


def main():
    s = list(input())
    t = list(input())
    s.sort()
    t.sort(reverse=True)
    l = len(s)
    tl = len(t)
    if l > tl:
        l = tl
    for i in range(l):
        if s[i] == t[i]:
            continue
        if t[i] > s[i]:
            print("Yes")
            return
        print("No")
        return
    if l == tl:
        print("No")
        return
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 61956
#include<stdio.h>
#include<stdlib.h>
#define N 500000

int cnt=0;

void merge(int *A, int left, int mid, int right){
    int n1,n2;
    int i, j, k;
 
    n1 = mid - left;
    n2 = right - mid;
 
    int L[N/2+2], R[N/2+2];
 
    for(i=0; i<n1; i++)   L[i] = A[left + i];
    for(i=0; i<n2; i++)   R[i] = A[mid + i];
 
    L[n1] = 1000000000;
    R[n2] = 1000000000;
    i = j = 0;
    for(k=left; k<right; k++){
        cnt++; 
        if( L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        } 
    }
}

void mergeSort(int *A, int left, int right){
    int mid;
    if(left+1 < right){
        mid = (left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

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

    mergeSort(A, 0, n);

    printf("%d", A[0]);
    for(i=1;i<n;i++) printf(" %d", A[i]);
    printf("\n%d\n", cnt);
    return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Tue Mar  3 01:57:57 JST 2020
 **/

signed main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    REP(i, n) cin >> a[i];
    vector<Int> acc(2 * n + 1);
    REP(i, 2 * n) acc[i + 1] = acc[i] + a[i % n];
    auto check = [&](Int mid) -> bool {
        REP(i, n) {
            auto it = acc.begin() + i;
            it = lower_bound(acc.begin(), acc.end(), *it + mid);
            if (it - acc.begin() > i + n) continue;
            it = lower_bound(acc.begin(), acc.end(), *it + mid);
            if (it - acc.begin() > i + n) continue;
            it = lower_bound(acc.begin(), acc.end(), *it + mid);
            if (it - acc.begin() <= i + n) return true;
        }
        return false;
    };
    Int ok = 0, ng = 1e18;
    while (abs(ok - ng) > 1) {
        Int mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
}



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

int main(){
  int W,H,N;
  cin>>W>>H>>N;
  
  
  vector<vector<int>> S(H,vector<int>(W,0));
  
  for(int i=0;i<N;i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      for(int k=0;k<x;k++){
        for(int l=0;l<H;l++){
          S.at(l).at(k) = 1;
        }
      }
    }
    if(a==2){
      for(int k=x;k<W;k++){
        for(int l=0;l<H;l++){
          S.at(l).at(k) = 1;
        }
      }
    }
    if(a==3){
      for(int k=0;k<W;k++){
        for(int l=0;l<y;l++){
          S.at(l).at(k) = 1;
        }
      }
    }
    if(a==4){
      for(int k=0;k<W;k++){
        for(int l=y;l<H;l++){
          S.at(l).at(k) = 1;
        }
      }
    }
  }
  int ans = 0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S.at(i).at(j) == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
  
  
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(str, input().split()))
    i = 0
    while True:
        if i == N:
            break
        print(A[0][i],end='')
        print(A[1][i],end='')
        i += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
N, K = map(int, input().split())
p = input().split()
bubun = [0 for i in range(N)]
sums= [0 for i in range(N+K)]
E=0
S=0

for i in range(N):
    p[i] = int(p[i])
    


sums[0] = p[0]
for i in range(N-1):
    sums[i+1] = sums[i] + p[i+1]

for i in range(N):
    if i == 0:
        bubun[i] = sums[K-1]
    else:
        bubun[i] = sums[i+K-1]-sums[i-1]

for i in range(N):

    if bubun[i] > S:
        S = bubun[i]


E=(S+K)/2

print(E)



    


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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<vector<int>> vec(n+1,vector<int>(m));
  rep(i,n+1){
    rep(j,m){
      cin >> vec.at(i).at(j);
    }
  }
  int sum =0;
  
  for (int i = 1;i<n+1;i++){
    int a=0;
    rep(j,m){
      a+=vec.at(0).at(j)*vec.at(i).at(j);
    }
    if (a+c>0){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

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

int main(){
  ll N, X;
  cin >> N >> X;
  vector<ll> x;
  rep(i, N){
    ll xi;
    cin >> xi;
    x.push_back(abs(xi - X));
  }
  ll ans = x[0];
  rep(i, N) ans = gcd(ans, x[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
d = {0: lambda x, y: max(x, y),
     1: lambda x, y: min(x, y)}

while True:
    n = int(input())
    if n == 0:
        break
    ans = [0, 500]
    for _ in range(n):
        score = sum(map(int, input().split()))
        ans = [d[i](ans[i], score) for i in range(2)]
    print(*ans)

Measured memory_bytes: 7736
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

class UF
{
private:
    int         num;
    vector<int> par;
    vector<int> siz;
public:
    //vector<int> val;
public:
    UF(int n): num(n) {
        par.resize(n);
        siz.resize(n);
        //val.resize(n);
        int i;
        for(i=0; i<n; i++) {
            par[i]=i; siz[i]=1;
            //val[i]=0;
        }
    }
	
    int find(int x) {
        if(x==par[x]) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(siz[x]<siz[y]) {
            par[x]=y;
            siz[y]=siz[x]+siz[y];
            //val[y]=val[x]+val[y];
        }
        else {
            par[y]=x;
            siz[x]=siz[x]+siz[y];
            //val[x]=val[x]+val[y];
        }
    }

    bool same(int x, int y) {
        return find(x)==find(y);
    }

    int size(int x) {
        return siz[find(x)];
    }

    int ngroup() {
    //int ngroup( int& ans ) {
        int count=0;
        int i;
        for(i=0; i<num; i++) {
            if(par[i]==i) {
                count++;
                //ans += (val[i]? siz[i]: siz[i]-1);
            }
        }
        return count;
    }
};

void solve()
{
    int n,m;
    scanf("%d%d", &n, &m);
    vector<int> p(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%d", &p[i]); p[i]--;
    }
    UF uf(n);
    for (i = 0; i < m; i++) {
        int x, y;
        scanf("%d%d", &x, &y); x--; y--;
        uf.unite(x, y);
    }

    int cnt = 0;
    for (i = 0; i < n; i++) {
        if (uf.same(i, p[i])) {
            cnt++;
        }
    }
    printf("%d\n", cnt);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

#include <iostream>
#include <fstream>

#include <iostream>

class hitachi2020_b {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int A, B, M;
	    in >> A >> B >> M;

	    int a[A], b[B];

	    for(int i = 0; i < A; i++){
	        in >> a[i];
	    }
	    for(int i = 0; i < B; i++){
	        in >> b[i];
	    }

	    int m[M][3];
	    for(int i = 0; i < M; i++){
	        in >> m[i][0] >> m[i][1] >> m[i][2];
	    }

	    int n_min_a = a[0], n_min_b = b[0];

	    for(int i = 1; i < A; i++){
	        if(n_min_a > a[i]){
	            n_min_a = a[i];
	        }
	    }
	    for(int i = 0; i < B; i++){
	        if(n_min_b > b[i]){
	            n_min_b = b[i];
	        }
	    }

	    int sum_a = n_min_a + n_min_b;


	    int n_min_c = sum_a;
	    for(int i = 0; i < M; i++){
	        int aa = a[m[i][0] -1] + b[m[i][1] -1];
            int temp = aa - m[i][2];
            if(temp < n_min_c){
                n_min_c = temp;
            }
	    }

	    if(n_min_c < 0)
	        n_min_c = 0;

	    if(sum_a > n_min_c){
	        out << n_min_c;
	    }else{
	        out << sum_a;
	    }


	}
};


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


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

int a, b, c, k, ans;

int main() {
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if (k <= a) {
        ans = k;
    } else if (k > a && k - a <= b) {
        ans = a;
    } else {
        ans = a - (k - a - b);
    }
    printf("%d\n", ans);
    return 0;
}

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


class Mo {
public:

    const int mod = (int) 1e9 + 7;
    
    inline int add(int a, int b) const {
        a += b;
        return a < mod ? a : a - mod; 
    }
    
    inline int sub(int a, int b) const {
        a -= b;
        return a < 0 ? a + mod : a;
    }
    
    inline int mul(long long a, long long b) const {
        a *= b;
        return a < mod ? a : a - a / mod * mod;
    }
    
    inline int pow_mod(long long a, long long b) const {
        long long res = 1;
        res %= mod;
        while (b) {
            if (b & 1) {
                res = mul(res, a);
            }
            a = mul(a, a);
            b >>= 1;
        }
        return res;
    }
    
    inline int inv(int a) const {
        return pow_mod(a, mod - 2);
    }
    
    vector<int> fact, finv;
    void init_comb_1(int n = 1000000) {
        fact.resize(n + 5);
        finv.resize(n + 5);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) {
            fact[i] = mul(fact[i - 1], i);
        }
        finv[n] = inv(fact[n]);
        for (int i = n - 1; i >= 0; i--) {
            finv[i] = mul(finv[i + 1], i + 1);
        }
    }
    
    
    inline int P1(int n, int m) {
        if (n < m)
            return 0;
        return mul(fact[n], finv[n - m]);
    }
    
    ////  M
    //
    ////  N
    
    // if n is not big, don't forget init_comb_1 !
    inline int C1(int n, int m) {
        if (n < m) return 0;
        return mul(mul(fact[n], finv[m]), finv[n - m]);
    }
    
    // if n is big
    inline int C2(int n, int m) {
        if (n < m) return 0;
        if (m > n - m) {
            m = n - m;
        }
        int a = 1, b = 1;
        for (int i = 1; i <= m; i++) {
            a = mul(a, n - i + 1);
            b = mul(b, i);
        }
        return mul(a, inv(b));
    }
} mo;

int main() {
    mo.init_comb_1();
    int n, m;
    cin >> n >> m;
    int ans = mo.P1(m, n);
    int cur = 0;
    for (int i = 0; i <= n; i++) {
        if (i & 1) {
            cur = mo.sub(cur, mo.mul(mo.C1(n, i), mo.P1(m - i, n - i)));
        } else {
            cur = mo.add(cur, mo.mul(mo.C1(n, i), mo.P1(m - i, n - i)));
        }
    }
    cout << mo.mul(ans, cur) << endl;
    return 0;
}


Measured memory_bytes: 10856
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>

using namespace std;

bool fun(int X, int Y, vector<int> &dp)
{
	
	if(Y == 0 && X==0)
		return true;
	if (X == 0 || Y<2*X || Y > 4*X)
		return false;

	if (!dp[X])
		return false;
	if (fun(X - 1, Y - 2, dp))
	{
		return true;
	}
	if (fun(X - 1, Y - 4, dp))
	{
		return true;
	}

	dp[X] = false;
	return false;
}

bool fun2(int X, int Y)
{
	int i, j;
	for (i = 0; i <= X; i++)
	{
		j = X - i;
		if (i * 2 + j * 4 == Y)
			return true;
	}
	return false;
}

void Sol2()
{
	int X, Y;
	cin >> X >> Y;
	vector<int>  dp(101,1);

	bool ret = fun(X, Y,dp);
	//bool ret = fun2(X, Y);

	if (ret)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main()
{
    #define endl '\n'
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(0);
    {
        //freopen("handmade09", "r", stdin);
       // freopen("out.txt", "w", stdout);
        //Sol1();
        Sol2();
        //Sol3();
        //Sol4();
        //Sol5();
        //Sol6();
    }
    //cin.get();
}

Measured memory_bytes: 3128
#include <cstdio>
#include <iostream>
#include <algorithm>
typedef long long ll;

int n,l,c0,c1,c2,x[300005],t[300005];

int main()
{
    scanf("%d%d",&n,&l);
    for(int i=1;i<=n;++i)scanf("%d",&x[i]);
    ll z=1;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&t[i]),z+=t[i]/(l<<1),t[i]%=(l<<1);
        if(!t[i])continue;
        ++z;
        bool f=t[i]<=((l-x[i])<<1),g=t[i]<=(x[i]<<1);
        if(i==n){z-=f;break;}
        if(g)++c0,c2+=f;
        else c1+=f;
        while(c0-c2<c1+c2)
            if(c2)--c2;
            else --c1;
    }
    std::cout<<(z-c1-c2)*(l<<1)<<std::endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof a) ;
#define vi vector<int>
#define ull unsigned long long
#define ll long long 
#define db double 
#define ldb long double
#define fl float
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lrep(i,a,b) for(ll i=a;i<b;i++)
//#define mod 1000000007
#define mpr make_pair
#define pb push_back
#define fr first
#define sn second
#define bpp(x) __builtin_popcountll(x)
const ldb PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899863;
const int INF = 1e9+7;
bool ok(string &s ,int l ,int r)
{
while(s[l]==s[r]) l++,r--;
return l>=r; 
}/*
ll por(ll a,int b)
{
ll res=1,M=998244353;
while(b)
{
if(b&1)
res=(res*a)%M;
a=(a*a)%M;
b/=2;
}
return res;
}
void rev(vector<int>&arr,int l,int r)
{
    for(;l<r;l++,r--) swap(arr[l],arr[r]);
}
*/
int prime[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,97,101,103};
int add(int a,int b) // integer range
{
long x=a+b;
if(x>=INF)
x-=INF;
return x;
}
/*
goto e;


e:
;
*/
void solve()
{
ll n,k; cin>>n>>k;
ll x=n%k;
cout<<min(x,k-x);
return;
}
int main()
{
ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
//	cin>>t;
while(t--)
{
solve();
}
return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    lines = stdin.readlines()
    T = int(lines[0].split()[1])
    tn = [int(ti) for ti in lines[1].split()]
    ans = 0
    for t1, t2 in zip(tn[0:], tn[1:]):
        ans += min(T, t2 - t1)
    ans += T
    print(ans)
    return


main()


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

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for (int i = 0; i < 101; i++) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << endl;
			break;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << endl;
			break;
		}
	}
}


Measured memory_bytes: 3636
program main
    integer(8):: n,i,c_m
    integer(8),allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    c_m = 0
    do i=1,n
        if (a(i) < 0) c_m=c_m+1
    end do

    if (mod(c_m,2_8) == 0) then
        print*, sum(abs(a(:)))
    else
        print*, sum(abs(a(:))) - 2*minval(abs(a(:)))
    end if
end program


Measured memory_bytes: 1536
import sys
N=int(input())
A=[int(i) for i in input().split()]
if sum(A)%((N*(N+1))//2)!=0:
    print('NO')
    sys.exit()
k=sum(A)//((N*(N+1))//2)
B=[0]*N
for i in range(N):
    B[i]=A[i]-A[i-1]
for a in B:
    if a-k<=0 and (k-a)%N==0:
        continue
    print('NO')
    sys.exit()
print('YES')

Measured memory_bytes: 62704
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

int main(int argc, char* argv[])
{
    ll n, M;
    scanf("%lld%lld", &n, &M);
    vector<ll> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());
    vector<ll> s(n+1);
    for(i=0; i<n; i++) {
        s[i+1]=s[i]+a[i];
    }

    ll l=-1;
    ll r=a[n-1]*2+100;
    while(r-l>1) {
        ll m=(l+r)/2;

        ll cnt=0, sum=0;
        for(i=0; i<n; i++) {
            int k=lower_bound(a.begin(), a.end(), m-a[i])-a.begin();
            cnt+=n-k;
            sum+=(n-k)*a[i]+s[n]-s[k];
        }
        if(cnt<=M) {
            r=m;
        }
        else {
            l=m;
        }
    }

    {
        ll m=r;
        ll cnt=0, sum=0;
        for(i=0; i<n; i++) {
            int k=lower_bound(a.begin(), a.end(), m-a[i])-a.begin();
            cnt+=n-k;
            sum+=(n-k)*a[i]+s[n]-s[k];
        }
        if(M>cnt) {
            sum+=(M-cnt)*(m-1);
        }
        printf("%lld\n", sum);
    }

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

vector<int> memo, memo2(200000, -1);

int solve(int N);

int main()
{
    int N;
    cin >> N;
    memo.push_back(1);
    int c1 = 6, c2 = 9;
    while (c1 <= 100000)
    {
        memo.push_back(c1);
        c1 *= 6;
    }
    while (c2 <= 100000)
    {
        memo.push_back(c2);
        c2 *= 9;
    }

    cout << solve(N) << endl;
}

int solve(int N)
{
    if (N < 0)
    {
        return 100000;
    }
    else if (N == 0)
    {
        return memo2.at(N) = 0;
    }
    else if (memo2.at(N) != -1)
    {
        return memo2.at(N);
    }
    int ans = 100000;
    for (auto a : memo)
    {
        ans = min(ans, solve(N - a) + 1);
    }

    return memo2.at(N) = ans;
}

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

using namespace std;
struct edge
{
	int v,next;
}vs[300000];
int sign[100010][15],q;
int n,m,st[100010],ee,col[100010];
inline void addedge(int u,int v)
{
	vs[++ee].v=v ;vs[ee].next=st[u]; st[u]=ee;
}
void calc(int u,int d,int c)
{
	if(sign[u][d]) return ;
	sign[u][d]=1;
	if(d==0)
	{
		col[u]=c; return;
	}
	calc(u,d-1,c);
	for(int i=st[u];i;i=vs[i].next)
		calc(vs[i].v,d-1,c);
}
void work(int cnt)
{
	if(cnt==0) return ;
	int u,d,c; scanf("%d%d%d",&u,&d,&c);
	work(cnt-1);
	calc(u,d,c);
}
int main()
{
//	freopen("read.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v; scanf("%d%d",&u,&v);
		 addedge(u,v); addedge(v,u); 
	}
	scanf("%d",&q); work(q);
	for(int i=1;i<=n;i++) printf("%d\n",col[i]);
	return 0 ;
} 


Measured memory_bytes: 11904
WIDTH = 0
DEPTH = 1

while True:
    N, W, D = [int(x) for x in input().split()]
    if N == W == D == 0:    break
    if N == 0:
        print(W * D)
        continue

    p, s = zip(*[[int(x) for x in input().split()] for _ in range(N)])

    # cake[i] =  [識別番号iのケーキの 幅, 奥行き]
    # i = 0はダミー
    cake = [[0, 0], [W, D]] + [None] * N

    for i in range(N):
        id = p[i]   # カットするケーキの識別番号
        w, d = cake[id] # カットするケーキの幅と奥行き
        l = s[i]    # 切り方

        # id+1以降のケーキの番号振り直し
        for j in range(id, i + 1):
            cake[j] = cake[j + 1][:]
        cake[i + 1] = None

        # ケーキをカット＆番号を振る
        l = l % (w + d)
        if l < w:  # 上から見て縦方向に切る
            w_min = min(l, w - l)  # id: i + 1
            cake[i + 1] = [w_min, d]
            cake[i + 2] = [w - w_min, d]
        else:  # 上から見て横方向に切る
            l -= w
            d_min = min(l, d - l)
            cake[i + 1] = [w, d_min]
            cake[i + 2] = [w, d - d_min]

    area = [w * d for (w, d) in cake]
    area.sort()
    print(" ".join(map(str, area[1:])))



Measured memory_bytes: 5624
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

a,b,c,k = map(int, input().split())

if k%2==0:
    ans = a-b
else:
    ans = b-a

if abs(ans)>10**18:
    print('Unfair')
else:
    print(ans)


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    string ss = s+s;
    vector<set<int>> pos(26);
    for(int i = 0; i < 2*n; ++i) pos[ss[i]-'a'].insert(i);
  

    ll idx = -1;
    ll loop = 0;
    for(int i = 0; i < m; ++i){
        if(pos[t[i]-'a'].empty()){
            ppp(-1);
            return 0;
        }
        auto itr = pos[t[i]-'a'].upper_bound(idx);
        if(itr == pos[t[i]-'a'].end()){
            ppp(-1);
            return 0;
        }
        idx = *itr;
        loop += idx / n;
        idx %= n;
    }
    ppp(loop*n+idx+1);

    return 0;
}


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

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

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

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

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

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



int n, a, b[4];
double dp[301][301][301];

// 寿司が1〜3個乗った皿がx,y,z個ある状態から全ての寿司を食い切るまでの操作回数の期待値
double rec(int x, int y, int z) {
	if (dp[x][y][z]>=0) return dp[x][y][z];
	if (x+y+z==0) return 0;
	double res = n;
	if (x) res += rec(x-1,y,z) * x;
	if (y) res += rec(x+1,y-1,z) * y;
	if (z) res += rec(x,y+1,z-1) * z;
	res *= 1. / (x+y+z);
	return dp[x][y][z] = res;
}

signed main() {
	cin >> n;
	rep(i,n) {
		cin >> a;
		b[a]++;
	}
	memset(dp, -1, sizeof(dp));
	printf("%.14lf\n", rec(b[1],b[2],b[3]));
}

Measured memory_bytes: 213376
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		while (true) {
			if (a % 2 != 0) {
				break;
			}
			ans++;
			a /= 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //String str = sc.next();
        int A = sc.nextInt();
        int V = sc.nextInt();
        int B = sc.nextInt();
        int W = sc.nextInt();
        long T = sc.nextLong();
        
        if(V<=W){
            System.out.println("NO");
        }else{
            long L = Math.abs(A-B);
            long S = V - W;
            if(/*L%S==0 &&*/ L <= T*S){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
            //System.out.println(A+":"+B+":"+L);
        }
    }
}

Measured memory_bytes: 35716
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    if n % 10 == n / 100 {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
	cin>>N;
	N<1000;
	N=N%10;
	if(N==2||N==4||N==5||N==7||N==9)
	{
	cout<<"hon";
	}
	else if(N==3)
	{
		cout<<"bon";
	}
	else
	{
		cout<<"pon";
	}
}

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

int main() {
    int n, nmin, nmax;
    while (cin >> n >> nmin >> nmax, n) {
        vector<int> P(n);
        for (int i = 0; i < n; ++i) cin >> P[i];

        int diff = 0;
        int res = -1;
        for (int i = nmin - 1; i <= nmax - 1; ++i) {
            if (diff <= P[i] - P[i + 1]) {
                diff = P[i] - P[i + 1];
                res = i + 1;
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    int R, G, B, N;
    scanf("%d %d %d %d", &R, &G, &B, &N);
    
    // 2. 組み合わせをカウント.
    int ans = 0;
    rep(r, (N / R) + 1){
        rep(g, (N / G) + 1){
            int b = N - R * r - G * g;
            if(b >= 0 && b % B == 0) ans++;
        }
    }
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
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; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);

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

ll Lcm(ll a, ll b) {
	return a*b/Gcd(a,b);
}

int main() {
	ll n,m;
	cin >> n >> m;
	ll a[n];
	rep(i,n) cin >> a[i];

	int flag = 1,cnt = -1;
	for(int i = 0; i < n; i++){
		int tmp = a[i];
		if(cnt == -1){
			cnt = 0;
			while(tmp%2 == 0) { tmp /= 2; cnt++; }
		}else{
			int c = 0;
			while(tmp%2 == 0) { tmp /= 2; c++; }
			if(cnt != c) flag = 0;
		}
	}

	ll num = a[0]/2;
	if(num > m) flag = 0;
	for(int i = 1; i < n; i++){
		num = Lcm(num,a[i]/2);
		if(num > m){
			flag = 0;
			break;
		}
	}

	if(!flag) cout << 0 << endl;
	else cout << (m+num)/(2*num) << endl;
	
	return 0;
}

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

int main(){
  long long A, B, C;
  cin >> A >> B >> C;
  long long count = 0;
  for(;A % 2 == 0 && B % 2 == 0 && C % 2 == 0;){
    if(A == B && B == C){
      count = -1;
      break;
    }
    long long a, b, c;
    a = A / 2;
    b = B / 2;
    c = C / 2;
    A = b + c;
    B = a + c;
    C = a + b;
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3568
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]

#逆順にしたもの追加
ab += [[b,a] for a,b in ab]

#辺id付きで、idがfrom,abi[from]=[to1,to2,...] のリスト
abi = [[] for _ in range(n+1)]
for i,(a,b) in enumerate(ab):
    abi[a].append(b)



#再起のlimitを上げる
import sys
sys.setrecursionlimit(4100000)

def dfs(idx=1,visitted=[1],cnt=1):
    ret = 0
    if cnt==n:
        return 1
    for to in abi[idx]:
        if to not in visitted:
            ret += dfs(to,visitted+[to],cnt+1)
    return ret
print(dfs())

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

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

    int h, n;
    cin >> h >> n;
    int sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
    }

    if(h<=sum) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int search(int A , int B){
		for(int x = 1 ; x <= 10000 ; ++x){
			int tax8 =  x * 8 / 100;
			int tax10 = x * 10 / 100;
			if(tax8 == A && tax10 == B){
				return x;
			}
		}
		return -1;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		System.out.println(search(A, B));
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL M; cin >> M;
		if (M % 2) { cout << -1 << endl; return; }
		vector<pair<UL, UL>> E(M);
		rep(i, M) { cin >> E[i].first >> E[i].second; E[i].first--; E[i].second--; }
		vector<vector<UL>> E2(N);
		rep(i, M) {
			E2[E[i].first].push_back(i);
			E2[E[i].second].push_back(i);
		}
		vector<UL> E3(N, (UL)-1); E3[0] = 0;
		stack<UL> S;
		queue<UL> Q; Q.push(0);
		while (Q.size()) {
			UL p = Q.front(); Q.pop();
			for (UL e : E2[p]) {
				UL nx = E[e].first + E[e].second - p;
				if (E3[nx] != (UL)-1) continue;
				E3[nx] = e;
				Q.push(nx);
				S.push(nx);
			}
		}
		vector<UL> Deg(N);
		rep(i, M) { Deg[E[i].first]++; }
		while (S.size()) {
			UL p = S.top(); S.pop();
			if (Deg[p] % 2 == 0) continue;
			UL e = E3[p];
			Deg[E[e].first]--;
			swap(E[e].first, E[e].second);
			Deg[E[e].first]++;
		}
		rep(i, M) {
			cout << (E[i].first + 1) << " " << (E[i].second + 1) << endl;
		}
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 8960
H,W=[int(s) for s in input().split()]
game=[input() for i in range(H)]
ans=[[] for i in range(H)]
direction=[[1,1],[1,0],[0,1],[1,-1,],[-1,1],[-1,0],[0,-1],[-1,-1]]
for i in range(H):
  for j in range(W):
    if game[i][j]=='#':
      ans[i].append('#')
      continue
    count=0
    for e in direction:
      y=i+e[0]
      x=j+e[1]
      if (x<0 or x>=W or y<0 or y>=H):
        continue
      if game[y][x]=='#':
        count+=1
    ans[i].append(count)
for i in range(H):
  print(*ans[i],sep='')
    
      
      
    

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

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

    int a,b,c,d;
    cin >> a >> b >> c >> d;
    
    int ans = min(b,d) - max(a, c);
    
    if(ans < 0) ans = 0;
    
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back 
#define mp make_pair
#define f first
#define s second
#define sz(x) ((int)x.size())
const ll maxint=2e18;
const ll minint =-2e18;
/*******\
(͡ ° ͜ʖ ͡ °) : Hello there, relax.
\*     */

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    ll n = min(k,x/d);
    k -= n;
    x -= (n*d);
    if(k == 0){
        cout<<x;
        exit(0);
    }
    if(k&1){
        cout<<abs(x-d);
    }else{
        cout<<x;
    }
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)8e3+5;
const int Q = 102;
const int logN = 19;

int dp[N][62];
void solve() {
    int n;
    ll k;
    cin>>n>>k;
    REP(i,1,n) {
        cin>>dp[i][0];
    }
    REP(k,1,61) {
        REP(i,1,n) {
            dp[i][k] = dp[dp[i][k-1]][k-1];
        }
    }
    REP(i,1,1) {
        int d = i;
        REP(j,0,61) {
            if((1LL<<j)&k) {
                d = dp[d][j];
            }
        }
        cout<<d<<" ";
    }
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 52048
n,c,k=map(int,input().split())
lista=[int(input())for i in range(n)]
listb=sorted(lista)
count=0
bustime=0
buspeople=0
for i in listb:
    if buspeople==0 or bustime<i:
        count+=1
        buspeople=c-1
        bustime=i+k
    else :
        buspeople-=1
print(count)

Measured memory_bytes: 51032
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop=0; loop<(int)ar.size(); loop++) cout << "[" << loop << "]:" << ar[loop] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop=0; loop<(int)ar.size(); loop++) { cout << ar[loop]; if(loop<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

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

    int a, b, c, d;
    string s;
    cin >> s;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';

    vector<bool> op(3, false);
    op[0] = true;

    int ans;
    while(true){
        ans = a;
        if(op[0]) ans += b;
        else ans -= b;

        if(op[1]) ans += c;
        else ans -= c;

        if(op[2]) ans += d;
        else ans -= d;

        if(ans == 7){
            break;
        }

        if(op[0] == false){
            op[0] = true;
        }else{
            op[0] = false;
            if(op[1] == false){
                op[1] = true;
            }else{
                op[1] = false;
                if(op[2] == false){
                    op[2] = true;
                }else{
                    op[2] = false;
                }
            }
        }
    }

    cout << a;
    if(op[0]) cout << '+';
    else cout << '-';

    cout << b;
    if(op[1]) cout << '+';
    else cout << '-';

    cout << c;
    if(op[2]) cout << '+';
    else cout << '-';

    cout << d << "=7";

 
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline 

n = int(input())
s = input()
#a = [int(i) for i in readline().split()]
#m = [[int(i) for i in readline().split()] for _ in range(n)]


res1 = [0]*10
res2 = [0]*100
res3 = [0]*1000

for i in s:
    i = int(i)
    for x in range(100):
        if res2[x] == 1:
            res3[x*10+i] |= 1

    for x in range(10):
        if res1[x] == 1:
            res2[x*10+i] |= 1
        
    res1[i] |= 1


print(sum(res3))    




Measured memory_bytes: 3188
Imports System
Module ABC153B
	Sub Main()
		Dim inputs() As String
		Dim h,n,sum As Integer
		inputs = Console.ReadLine().Split()
		h = Integer.Parse(inputs(0))
		n = Integer.Parse(inputs(1))
		inputs = Console.ReadLine().Split()
		sum = 0
		For i As Integer = 0 To n-1
			sum += Integer.Parse(inputs(i))
		Next

		If sum >= h
			Console.WriteLine("Yes")
		Else
			Console.WriteLine("No")
		End If
	End Sub
End Module


Measured memory_bytes: 16480
#include <stdio.h>

int main() {
	int N;
	long long int ans=0;
	scanf("%d", &N);
	for (long long int i = 1; i <= N; i++)if (i % 3 != 0 && i % 5 != 0)ans += i;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1732