akhauriyash/Code-Regression huggingface dataset:
// Date: 2020-03-16

#include <assert.h>
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

LL mod, n, dp[N], ans[N], fav[N];
VI g[N], L[N], R[N], son[N], ind[N];

void dfs1(int u, int fa) {
    dp[u] = 1;
    for(auto v : g[u]) if(v != fa) ind[u].pb(v);
    sort(all(ind[u]));
    for(auto v : ind[u]) {
        dfs1(v, u);
        son[u].pb((1+dp[v])%mod);
        dp[u] = 1LL * dp[u] * (1+dp[v]) % mod;
    }
    int sz = SZ(son[u]);
    if(sz) L[u].pb(son[u][0]), R[u].pb(son[u][sz-1]);
    rep(i, 1, sz-1) L[u].pb(1LL * L[u][i-1] * son[u][i] % mod);
    per(i, sz-2, 0) R[u].pb(1LL * R[u][sz-i-2] * son[u][i] % mod);
    assert(SZ(L[u]) == SZ(R[u]));
}

void dfs2(int u, int fa) {
    for(auto v : g[u]) if(v != fa) {
        int p = lower_bound(all(ind[u]), v)-ind[u].begin();
        int tmp = 1;
        if(p) tmp = 1LL * tmp * L[u][p-1] % mod;
        if(p < SZ(L[u])-1) tmp = 1LL * tmp * R[u][SZ(R[u])-2-p] % mod;
        fav[v] = 1LL * (1+fav[u]) * tmp % mod;
        dfs2(v, u);
    }
}

int main() {
    FIO;
    cin >> n >> mod;
    rep(i, 1, n-1) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    dfs1(1, 0);
    dfs2(1, 0);
    rep(i, 1, n) ans[i] = 1LL * dp[i] * (1 + fav[i]) % mod;
    rep(i, 1, n) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 36096
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    string S;
    cin >> S;
    int ans = 1000000;
    for(int i=0; i<S.size()-2; i++){
        string num = string({S[i], S[i+1], S[i+2]});
        if(ans > abs(753 - stoi(num))){
            ans = abs(753 - stoi(num));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    immutable int INF = 1 << 29;
    
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto G = new int[][](N, N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        G[s[0]-1][s[1]-1] = s[2];
        G[s[1]-1][s[0]-1] = s[2];
    }

    int cost_sum = 0;
    foreach (i; 0..N) foreach (j; i+1..N) cost_sum += G[i][j];
    
    auto cost = new int[](1<<N);
    foreach (mask; 0..(1<<N)) {
        foreach (i; 0..N) {
            foreach (j; i+1..N) {
                if (!(mask & (1 << i))) continue;
                if (!(mask & (1 << j))) continue;
                cost[mask] += G[i][j];
            }
        }
    }

    auto dp = new int[][](1<<N, N);
    foreach (i; 0..(1<<N)) dp[i].fill(-INF);
    foreach (i; 0..N) dp[1][0] = 0;

    auto masks = (1<<N).iota.array;
    masks.sort!((a, b) => a.popcnt < b.popcnt);

    foreach (mask; masks) {
        foreach (i; 0..N) {
            if (!(mask & (1 << i))) continue;
            
            foreach (j; 0..N) {
                if (mask & (1 << j)) continue;
                if (G[i][j] == 0) continue;
                dp[mask|(1<<j)][j] = max(dp[mask|(1<<j)][j], dp[mask][i] + G[i][j]);
            }
            
            int comp = (~mask) & ((1 << N) - 1);
            for (int U = (1 << N) - 1; U >= 0; --U) {
                U &= comp;
                dp[mask|U][i] = max(dp[mask|U][i], dp[mask][i] + cost[U|(1<<i)]);
            }            
        }
    }

    int ans = cost_sum - dp[(1<<N)-1][N-1];
    ans.writeln;
}


Measured memory_bytes: 5372
#include<iostream>
using namespace std;
int main() {
	int a, b, k;
	cin >> a;
	cin >> b;
	cin >> k;
	for (int i = 0; i < k/2; i++)
	{
		if (a % 2 == 1)a -= 1;
		a /= 2;
		b += a;
		if (b % 2 == 1)b -=1;
		b /= 2;
		a += b;
	}
	if (k % 2 == 1) {
		if (a % 2 == 1)a -= 1;
		a /= 2;
		b += a;
	}
	cout << a << " " << b;
}

Measured memory_bytes: 256
class MyUnionFind():
    __slots__ = ["par", "rank", "size"]

    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [1 for i in range(n + 1)]
        self.size = [1 for i in range(n + 1)]

    def find(self, c):
        if self.par[c] == c:
            return c

        ret = self.find(self.par[c])
        self.par[c] = ret
        return ret

    def union(self, x, y):
        xr = self.find(x)
        yr = self.find(y)
        if xr == yr:
            return

        if self.rank[yr] > self.rank[xr]:
            self.par[xr] = yr
            self.size[yr] += self.size[xr]
        else:
            self.par[yr] = xr
            self.size[xr] += self.size[yr]
            if self.rank[xr] == self.rank[yr]:
                self.rank[xr] += 1



def main():
    N, M = map(int, input().split())
    uf = MyUnionFind(N)
    for i in range(M):
        a, b = map(int, input().split())
        uf.union(a, b)

    print(max(uf.size))

if __name__ == '__main__':
    main()

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

using namespace std;

vector<int> G[110];

const int INF=1e9;

int d[110];
bool used[110];

void bfs(int x)
{
    fill(d,d+110,INF);
    d[x]=0;

    queue<pair<int,int> > q;

    q.push(make_pair(0,x));

    used[x]=true;

    while(!q.empty())
    {
        pair<int,int> tmp=q.front();q.pop();

        int dd=tmp.first,now=tmp.second;
        for(int i=0;i<G[now].size();i++)
        {
            if(!used[G[now][i]])
            {
                d[G[now][i]]=dd+1;
                q.push(make_pair(dd+1,G[now][i]));
                used[G[now][i]]=true;
            }
        }
    }
}


int main()
{
    int n;

    cin>>n;

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

        cin>>a>>b;

        for(int j=0;j<b;j++)
        {
            cin>>c;

            G[a].push_back(c);
        }
    }

    bfs(1);

    for(int i=1;i<=n;i++)
    {
        cout<<i<<" ";

        if(d[i]==INF)
        {
            cout<<"-1";
        }else
        {
            cout<<d[i];
        }
        cout<<endl;
    }

    return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
int main (){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    for (int i = 0; i < n; i++){
        cout << s[i];
    }
    cout << "\n";
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> v(4, 0);
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    
    if(s == "AC")
      v.at(0)++;
    else if(s == "WA")
      v.at(1)++;
    else if(s == "TLE")
      v.at(2)++;
    else
      v.at(3)++;
  }
  
  
  cout << "AC x " << v.at(0) << endl;
  cout << "WA x " << v.at(1) << endl;
  cout << "TLE x " << v.at(2) << endl;
  cout << "RE x " << v.at(3) << endl;
}


Measured memory_bytes: 3608
#!/usr/bin/env python3
#ABC128 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
stx = [LI() for _ in range(n)]
stx.sort(key = itemgetter(2))
d = [I() for _ in range(q)]
ans = [-1]*q
skip = [-1]*q
for s,t,x in stx:
    l,r = bl(d,s-x),bl(d,t-x)
    while l < r:
        if skip[l] == -1:
            skip[l] = r
            ans[l] = x
            l += 1
        else:
            l = skip[l]
print(*ans)

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    vector<int> ans(N);

    for(int i = 0;i < N;i++){
        ans[A[i] - 1] = i + 1;
    }
    for(int i=0; i < N; i++){
        cout<<ans[i]<<endl;
    }

}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long N, M, ANS = 0;
	vector<long long> A;
	vector<vector<long long> > V;
	vector<bool> B;
	cin >> N >> M;
	A.resize(N), V.resize(N), B.assign(N, false);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < M; i++) {
		long long X, Y;
		cin >> X >> Y;
		V[X].push_back(Y);
		V[Y].push_back(X);
	}
	if (N > M * 2 + 2) {
		cout << "Impossible" << endl;
		return 0;
	}
	if (N - M == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<vector<long long> > F(N - M);
	long long Cur = 0;
	for (int i = 0; i < N; i++) {
		if (!B[i]) {
			stack<long long> ST;
			ST.push(i);
			while (!ST.empty()) {
				long long P = ST.top();
				ST.pop();
				B[P] = true;
				F[Cur].push_back(A[P]);
				for (int NP : V[P]) {
					if (!B[NP]) ST.push(NP);
				}
			}
			Cur++;
		}
	}
	vector<long long> F2;
	for (int i = 0; i < N - M; i++) {
		sort(F[i].begin(), F[i].end());
		ANS += F[i][0];
		for (int j = 1; j < F[i].size(); j++) F2.push_back(F[i][j]);
	}
	sort(F2.begin(), F2.end());
	for (int i = 0; i < N - M - 2; i++) {
		ANS += F2[i];
	}
	cout << ANS << endl;
}

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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 5e5 + 1;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();

	for (int i = 1; i <= 5; ++i)
	{
		int x;
		cin >> x;
		if (x == 0) {
			cout << i << nl;
		}
	}
}


Measured memory_bytes: 3652
#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[fastout]
pub fn main() {
    input! {
        n: usize,
        s: Chars,
    }

    let r = s.iter().filter(|c| c == &&'R').count();
    let g = s.iter().filter(|c| c == &&'G').count();
    let b = s.iter().filter(|c| c == &&'B').count();

    let result = r * g * b;
    let no = (0..n)
        .map(|i| {
            (i + 1..n)
                .filter(|&j| j + j - i < n)
                .filter(|&j| s[i] != s[j] && s[i] != s[j + j - i] && s[j] != s[j + j - i])
                .count()
        })
        .sum::<usize>();

    println!("{}", result - no);
}


Measured memory_bytes: 2164
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int N, D;
  cin >> N >> D;
  float X[N][D];
  for(int i=0; i < N; i++){
    for(int j=0; j < D; j++){
      cin >> X[i][j];
    }
  }

  int ans = 0;
  for(int i=0; i < N; i++){
    for(int j = i+1; j < N; j++){
      float d = 0;
      for(int k=0; k < D; k++){
        d += pow(X[i][k]-X[j][k], 2);
      }
      // cout << d << endl;
      float sq;
      sq = sqrt(d);
      // cout << sq << endl;
      if(floor(sq) == sq){
        ans++;
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 384
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   int a;
  	cin>>a;
 
   ll ans = pow(a,2) + pow(a,3) + a;
   cout<<ans;

}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



Measured memory_bytes: 4020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set> 
#include<queue>
#include<cstdlib>
using namespace std;

 
int main()
{
	int n;
	scanf("%d",&n);
	int vv[105][105]={0},ans[105]={0},vis[105]={0};
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		while(y--)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			vv[x][a]=b;
		}
	} 
	fill(ans,ans+n,2000000000);
	ans[0]=0;
	while(1)
	{
		int v=-1;
		for(int u=0;u<n;u++)
		{
			if(vis[u]==0&&(v==-1||(ans[u]<ans[v]&&ans[u]!=0))) v=u;
		}
		if(v==-1) break;
		vis[v]=1;
		for(int u=0;u<n;u++)
		{
			if(vv[v][u]!=0) ans[u]=min(ans[u],ans[v]+vv[v][u]);
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%d %d\n",i,ans[i]);
	} 
	
	return 0;
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int k,x,i;
   cin>>k>>x;
   for(i=k-1;i>=0;i--)
   {
       cout<<x-i<<" ";
   }
   for(i=1;i<k;i++)
   {
       cout<<x+i<<" ";
   }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    ll ans = 0;
    if (N % 2 == 0) {
        ll f = 5;
        while (f <= N) {
            ans += N / 2 / f;
            f *= 5;
        }
    }

    write(ans);
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = 0
Max = 0
for i in range(n-1):
  if h[i]>=h[i+1]:
    ans += 1
  else:
    Max = max(ans,Max)
    ans = 0
 
Max = max(ans,Max)
print(Max)
         

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,inf=1e10;
ll n,ans;
pair<ll,ll> prfx[N],sfx[N],a[N];
inline pair<ll,ll> inter(pair<ll,ll> u,pair<ll,ll> v){
    pair<ll,ll> range = make_pair( max(v.first,u.first) , min(v.second,u.second) );
    range.second = max(range.first,range.second);
    return range;
}
inline void relax(pair<ll,ll> v,pair<ll,ll> u){
    ans = max(ans , v.second - v.first + u.second - u.first);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)cin>>a[i].first>>a[i].second,a[i].second++;
    sort(a,a+n);
    prfx[0]=make_pair(0,inf);
    for(ll i=0;i<n;i++)prfx[i+1]=inter(prfx[i],a[i]);
    sfx[n]=make_pair(0,inf);
    for(ll i=n-1;i>=0;i--)sfx[i]=inter(sfx[i+1],a[i]);
    for(ll i=0;i<n;i++)relax(a[i],inter(prfx[i],sfx[i+1]));
    for(ll i=1;i<n;i++)relax(prfx[i],sfx[i]);
    cout<<ans;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
using namespace std;

int main()
{
    ll d,t,s;
    cin>>d>>t>>s;
    if(d<=(t*s))
        cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }        
}

Measured memory_bytes: 3648
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int64_t solve(int64_t n, int64_t c, int64_t d) {
  int64_t res = n;
  res -= n/c;
  res -= n/d;
  res += n/(c / __gcd(c, d) * d);
  return res;
}

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;

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

  int64_t a, b, c, d;
  cin >> a >> b >> c >> d;

  int64_t x = solve(b, c, d);
  int64_t y = solve(a-1, c, d);

  cout << x - y << endl;

  return 0;
}

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

int gcd(int x, int y) {
	int b = min(x, y);
  	int a = max(x, y);
  	while (b > 0) {
        int r = a%b;
  		a = b;
  		b = r;
    }
	return a;
}

int main () {
  	int a, b;
	cin >> a;
    cin >> b;
	int g = gcd(a,b);
  	//cout << a << "," << b << "," << g  << endl;
  	long long ret = a / g;
  	ret *= b;
  	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll X;
        cin >> X;
        vll dp(X+1);
        vll costs = {0, 100, 101, 102, 103, 104, 105};
        dp[0] = 1;

        rep(i, 1, 7) {
                rep(j, 0, X+1) {
                        if (j-costs[i] >= 0) {
                                if (dp[j-costs[i]] == 1) dp[j] = 1;
                        }
                        
                        //dp[i][j] = dp[i-1][j];
                }
        }

        ll ans = dp[X] == 1 ? 1 : 0;
        cout << ans << endl;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S;
  
  reverse(S.begin(), S.end());
  string divide[4] = {"dream", "dreamer", "erase", "eraser"};
  for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());
  
  bool can = true;
  for (int i = 0; i < S.size();) {
    bool can2 = false;
    for (int j = 0; j < 4; j++) {
      if (S.substr(i, divide[j].size()) == divide[j]) {
        can2 = true;
        i += divide[j].size();
      }
    }
    if (!can2) {
      can = false;
      break;
    }
  }
  
  if (can) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 512
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ")
    val n=input[0].toInt()
    val t=input[1].toLong()
    val ts = readLine()!!.split(" ").map{ it.toLong() }

    var ans=t //最後の人の分
    for(i in 1..n-1){
        ans += Math.min(t,ts[i]-ts[i-1])
    }
    println(ans)
}

Measured memory_bytes: 81828
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int& val: arr)
        cin >> val;
    //  Ai + Aj = (i - j) or (j - i)
    // Ai - i == -j - Aj
    // Ai + i == j - Aj
    unordered_map<int, ll> target;
    unordered_map<int, ll> target2;
    map<pair<int, int>, ll> join;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if (target.count(arr[i]-i) > 0) {
            ans += target[arr[i]-i];
        }
        if (target2.count(arr[i]+i) > 0) {
            ans += target2[arr[i]+i];
        }
        if (join.count({arr[i]-i, arr[i]+i}) > 0)
            ans -= join[{arr[i]-i, arr[i]+i}];
        target[-i-arr[i]] += 1;
        target2[i-arr[i]] += 1;
        join[{-i-arr[i], i-arr[i]}] += 1;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 32108
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD 1000000007
#define nl cout<<bl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.b()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<bl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll fib(ll n)
{
    if(n < 2)
        return n;
    ll a = 0,b = 1,ans;
    int i = 1;
    while(i < n)
    {
        ans = (a+b) % MOD;
        a = b;
        b = ans;
        i++;
    }
    return ans;
} 
int main()
  {
      fastio();
      string s;
      cin>>s;
      if(s[1]=='R')
        cout<<"ABC\n";
      else
        cout<<"ARC\n";
      
  }


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvl vector<vector<ll>>
#define print(n) cout<<n<<endl
const int M=100010;
const int MOD=1000000007;
const int inf=1000000007;
const long long INF=1000000000000000007;
using ll=long long;


int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		int ans=0,s[110];
		rep(i,0,n)cin>>s[i];
		sort(s,s+n);
		rep(i,1,n-1)ans+=s[i];
		print(ans/(n-2));
	}
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll H, W, A, B;
  cin >> H >> W >> A >> B;
  rep(y, H) {
    rep(x, W) {
      if (x < A && y < B || x >= A && y >= B) {
        cout << "0";
      } else {
        cout << "1";
      }
    }
    cout << endl;
  }
  return 0;
}


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

int main(){
    string S, T;
    cin >> S >> T;
    int sTable[26], tTable[26];
    for(int i=0; i<26; i++){
        sTable[i] = -1;
        tTable[i] = -1;
    }
    char s, t;
    for(int i=0; i<S.size(); i++){
        s = S[i];
        t = T[i];
        if(sTable[s-'a'] == -1){
            sTable[s-'a'] = t - 'a';
        }else if(sTable[s-'a'] != t - 'a'){
            cout << "No";
            return 0;
        }
        if(tTable[t-'a'] == -1){
            tTable[t-'a'] = s - 'a';
        }else if(tTable[t-'a'] != s - 'a'){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int M=998244353,N=1000002;
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int INV(int x){return pw(x,M-2);}
int a,b;
signed main(){
	scanf("%d%d",&a,&b);
	if ((a+b)&1) puts("IMPOSSIBLE");
	else printf("%d",(a+b)/2);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define v vector<int>

using namespace std;

int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int a,b;
cin>>a>>b;
if(a==b){cout<<a+b <<"\n";}
else{
    cout<<max(a,b)+max(a,b)-1 <<"\n";
}
}

Measured memory_bytes: 3592
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


vector<pair<int,ll>> A;
vector<vector<ll>> dp;
int N;


int main() {
	cin >> N;
	A.resize(N);
	dp.resize(N+1);
	REP(i, 0, N + 1)dp[i].resize(N + 1, 0);
	REP(i, 0, N) {
		ll a;
		cin >> a;
		A[i] = pair<int, ll>(i + 1, a);
	}
	sort(A.begin(), A.end(), [](pair<int, ll> a, pair<int, ll> b) {return a.second > b.second; });
	REP(i, 0, N) dp[i + 1][0] = dp[i][0] + A[i].second * (N - i - A[i].first);
	REP(j, 0, N) dp[0][j + 1] = dp[0][j] + A[j].second * (A[j].first - j - 1);
	REP(i, 0, N) {
		REP(j, 0, N) {
			if (i + 1 + j + 1 > N) continue;
			dp[i + 1][j + 1] = max(
				dp[i][j + 1] + A[i + j + 1].second * (N - i - A[i + j + 1].first),
				dp[i + 1][j] + A[i + j + 1].second * (A[i + j + 1].first - j - 1)
				);
		}
	}
	ll ans = 0;
	REP(i, 0, N+1)ans = max(ans, dp[i][N - i]);
	PRI(ans);
	return 0;
}




Measured memory_bytes: 34932
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)

using namespace std;

int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


int gcd(int i,int j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

int ABC_swap(){
	LL X =linp();
	LL Y =linp();
	LL Z =linp();

	printf("%lld %lld %lld", Z, X, Y);
	return 0;
}

signed main() {

	ABC_swap();
	return 0;
}



Measured memory_bytes: 256
#include<iostream>

using  namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	int D[15];
	for (int i = 0; i < K; i++) {
		cin >> D[i];
	}

	int ans = N;

	while (true) {
		int cp = ans;
		bool not_emerge = true;
		while (cp != 0) {
			for (int i = 0; i < K; i++) {
				if (cp % 10 == D[i]) {
					not_emerge = false;
				}
			}
			cp /= 10;
		}
		if (not_emerge) {
			cout << ans << endl;
			return 0;
		}
		ans++;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a + b + c >= 22) {
		cout << "bust" << endl;
	} else {
		cout << "win" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int parent[200005], siz[200005];

int root(int x) {
  if(x==parent[x]) return x;
  else return parent[x] = root(parent[x]);
}

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

void unite(int x, int y) {
  x = root(x);
  y = root(y);
  if(siz[x]<siz[y]) swap(x, y);
  siz[x] += siz[y];
  parent[y] = x;
  return;
}

int main() {
  int N, Q;
  cin>>N>>Q;
  for(int i=0;i<N;++i) {
    parent[i] = i;
    siz[i] = 1;
  }
  int t, u, v;
  vector<bool> arr;
  for(int i=0;i<Q;++i) {
    cin>>t>>u>>v;
    if(t==0) {
      unite(u, v);
    }
    else {
      arr.push_back(same(u, v));
    }
  }
  for(int i=0;i<arr.size();++i) cout<<arr[i]<<endl;
}



Measured memory_bytes: 5120
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


r = ["U", "D", "R"]
l = ["U", "D", "L"]
s = input()

ans = "Yes"
for i in range(len(s)):
    if i % 2 == 0:
        if s[i] not in r:
            ans = "No"
    else:
        if s[i] not in l:
            ans = "No"
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
    ll ans =0;
	cin >> n;
    string s[n];
    fr(i,n){
      cin >> s[i];
      string a[10];
      fr(j,10){
        a[j]=s[i].substr(j, 1);
      }
      sort(a,a+10);
      string b;
      fr(j,10){
        b+=a[j];
      }
      s[i]=b;
    }
    sort(s,s+n);
    ll kai = 1;
    fr(i,n-1){
      if(s[i]==s[i+1]){
        kai++;
      }
      if(s[i]!=s[i+1]){
        ans += kai*(kai-1)/2;
        kai=1;
      }
      if(i==n-2){
        ans+=kai*(kai-1)/2;
      }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    long long A,B,C, K, Sum;

    cin >> A >> B >> C >> K;

    bool finish_flag = false;
    long long int i = 1;
    Sum = 0;
    while(i <= A){
        ++ Sum;
        
        if(i == K){
            cout << Sum << endl;
            return 0;
        }
        ++i;
    }

    while(i <= A+B){
        if(i == K){
            cout << Sum << endl;
            return 0;
        }
        ++i;
    }

    while(i <= A+B+C){
        --Sum;
        
        if(i == K){
            cout << Sum << endl;
            return 0;
        }
        ++i;
    }
    return 0;
}

Measured memory_bytes: 3636
import java.util.*
import kotlin.*


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = Scanner(System.`in`)
        val k = sc.nextInt()

        // kで割ってi余る数 桁和
        val min = Array(k) { Int.MAX_VALUE }
        val flag = Array(k) { false }
        val deq = ArrayDeque<Int>()
        min[1] = 1
        deq.add(1)

        while (deq.size > 0) {
            val p = deq.poll()
            if(flag[p]) continue
            flag[p] = true
            // 10倍 桁和は変わらない
            if (min[p] < min[(p * 10) % k]) {
                min[(p * 10) % k] = min[p]
                deq.push((p * 10) % k)
            }

            // +1 桁和 1増える
            // 一番下が9のときは探索済み
            if (min[p] + 1 < min[(p + 1) % k]) {
                min[(p + 1) % k] = min[p] + 1
                deq.add((p + 1) % k)
            }
        }
        println(min[0])
    }
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	cin >> n >> a >> m >> b >> k;
	t=m*60+b - n*60-a-k;
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 3632
//http://drken1215.hatenablog.com/entry/2019/03/23/175300
//勉強させて頂いた記事

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll N,M;
    cin>>N>>M;
    ll teisyutu_kaisuu=1LL<<M;
    ll each_time=1900LL*M+100LL*(N-M);
    cout<<each_time*teisyutu_kaisuu<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
from collections import defaultdict
from heapq import heappop, heappush

N = int(input())


class Graph(object):
    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    def __init__(self, graph, start):
        self.g = graph.graph

        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)

        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


g = Graph()
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    g.add_edge(a - 1, b - 1, c)
    g.add_edge(b - 1, a - 1, c)

Q, K = map(int, input().split())
d = Dijkstra(g, K - 1)
for _ in range(Q):
    x, y = map(int, input().split())
    ans = d.shortest_distance(x - 1) + d.shortest_distance(y - 1)
    print(ans)


Measured memory_bytes: 73752
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
*/

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
#pragma endregion

int main()
{
  init_main();

  int n;
  cin >> n;
  n %= 10;
  if (n == 3)
    cout << "bon\n";
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    cout << "pon\n";
  else
    cout << "hon\n";
  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(){
  int a,b,d,r;
  double f,j,n;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  j=a;
  n=b;
  f=j/n;
  printf("%d %d %f",d,r,f);
  return (0);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int S,W;
    cin >> S >> W;
    cout << (W>=S?"unsafe":"safe") << endl;
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  bool error[10][10];
  int puzzle[10][10];
  
  int T;
  cin >> T;
  while(T--){
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cin >> puzzle[i][j];
      }
    }
    
    memset(error, 0, sizeof(error));
    int check1[10];
    int check2[10];
    
    for(int i = 0 ; i < 9 ; i++){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int j = 0 ; j < 9 ; j++){
	check1[puzzle[i][j]]++;
	check2[puzzle[j][i]]++;
	
	if(check1[puzzle[i][j]] >= 2){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[i][k] == puzzle[i][j]) error[i][k] = true;
	  }
	}
	
	if(check2[puzzle[j][i]] >= 2){
	  for(int k = 0 ; k < 9 ; k++){
	    if(puzzle[k][i] == puzzle[j][i]) error[k][i] = true;
	  }
	}
	
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 0 ; j < 3 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 0 ; _j < 3 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 3 ; j < 6 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 3 ; _j < 6 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }

    for(int k = 0 ; k < 9 ; k+=3){
      memset(check1, 0, sizeof(check1));
      memset(check2, 0, sizeof(check2));
      for(int i = k ; i < k+3 ; i++){
	for(int j = 6 ; j < 9 ; j++){
	  check1[puzzle[i][j]]++;
	  if(check1[puzzle[i][j]] >= 2){
	    for(int _i = k ; _i < k+3 ; _i++){
	      for(int _j = 6 ; _j < 9 ; _j++){
		if(puzzle[i][j] == puzzle[_i][_j]) error[_i][_j] = true;
	      }
	    }
	  }
	}
      }
    }
	
    
    for(int i = 0 ; i < 9 ; i++){
      for(int j = 0 ; j < 9 ; j++){
	cout << ((error[i][j]) ? '*' : ' ') << puzzle[i][j];
      }
      cout << endl;
    }
    if(T)cout << endl;
  }
  return 0;
}

      

Measured memory_bytes: 0
import numpy as np
def resolve():
    n, k = map(int, input().split())
    h = np.array(list(map(int, input().split())))

    # 足場iにたどり着くまでの最小コスト
    # ただし足場は0番からn - 1番まで存在する
    dp = np.zeros(n, dtype=int)

    for i in range(1, n):
        base = max(i - k, 0)
        dp[i] = np.min(dp[base:i] + np.abs(h[base:i] - h[i]))

    print(dp[n - 1])
    
resolve()

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    string s;
    cin >> s;
    for(i=0;i<s.size();i++){
        cout << 'x';
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    s1 = round(h / 3) * w
    S1 = h * round(w / 3)
    h2 = h - round(h / 3)
    w2 = w - round(w / 3)
    if h2 % 2 == 0 or w % 2 == 0:
        s2 = h2 * w // 2
        s3 = s2
    else:
        h2, w = min(h2, w), max(h2, w)
        s2 = h2 * (w // 2)
        s3 = h2 * (w // 2 + 1)
    if h % 2 == 0 or w2 % 2 == 0:
        S2 = h * w2 // 2
        S3 = S2
    else:
        h, w2 = min(h, w2), max(h, w2)
        S2 = h * (w2 // 2)
        S3 = h * (w2 // 2 + 1)
    print(min(max(s1, s2, s3) - min(s1, s2, s3), max(S1, S2, S3) - min(S1, S2, S3)))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ld = long double;
using ll = long long;
using ui = unsigned int;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;
const double EPS = 1E-10;

template<class T, class S>
bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


int main(){
    int N, K, S; cin >> N >> K >> S;
    int SS = S + 1;
    if(S == 1000000000) SS = 1;
    REP(i, N){
        if(i) cout << " ";
        cout << (i<K ? S : SS);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(500).
01 maxlen     PIC 9(10) VALUE 100 COMP.
01 cur        PIC 9(10) VALUE 1 COMP.
01 i          PIC 9(10) VALUE 1 COMP.
01 j          PIC 9(10) COMP.
01 len        PIC 9(10) COMP.
01 accum      PIC 9(10) VALUE ZERO COMP.
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.
01 N          PIC 9(10).
01 M          PIC 9(10).
01 A1.
   03 A11 OCCURS 100 DEPENDING ON N.
      05 A    PIC 9(10) COMP.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO N M.
  MOVE N TO maxlen.
  ACCEPT ln.
  PERFORM maxlen TIMES
    PERFORM VARYING j FROM cur BY 1 UNTIL ln(j:1) = SPACE
    END-PERFORM
    COMPUTE len = j - cur
    MOVE ln(cur:len) TO A(i)
    ADD A(i) TO accum
    COMPUTE cur = j + 1
    ADD 1 TO i
  END-PERFORM.
  SORT A11 ON DESCENDING A.
  IF accum / (4 * M) <= A(M) THEN
     DISPLAY "Yes"
  ELSE
     DISPLAY "No"
  END-IF.
  STOP RUN.


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
    
  ll n,k;
  cin>>n>>k;

  ll ans=min(n%k,abs(k-(n%k)));

  cout<<ans<<endl;

  return 0;  
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

inline int mod(ll n, int k) {
    n %= k;
    if (n < 0) { n += k; }
    return (int)n;
}

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

    ll n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 0 << endl;
        return 0;
    }

    map<int, int> cnt;
    vi memory;
    if (n >= k) {
        memory.reserve(k - 1);
        rep(i, 0, k - 1) { memory[i] = -1; }
    }

    ll sum = 0;
    ll ans = 0;

    rep(i, 0, n) {
        ll a;
        cin >> a;
        a %= k;

        sum = mod(sum + a, k);
        ++cnt[mod(a - sum + i, k)];

        if (n >= k) {
            if (memory[i % (k - 1)] != -1) { --cnt[memory[i % (k - 1)]]; }
            memory[i % (k - 1)] = mod(a - sum + i, k);
        }

        ans += cnt[mod(i + 1 - sum, k)];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9600