akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N = gete(int)

    g = [["."] * N for _ in range(N)]

    d = dict()

    d[(3, 1)] = (".zz", "z..", "z..")
    d[(3, 2)] = ("aab", "b.b", "baa")
    d[(4, 3)] = ("aaba", "ccba", "abcc", "abaa")
    d[(5, 3)] = ("aabbc", "bc..c", "bc..b", "a.ccb", "abbaa")

    if N == 2:
        print(-1)
        return
    elif N == 3:
        for i in range(3):
            for j in range(3):
                g[i][j] = d[(3, 1)][i][j]
    elif N & 1 == 0:
        # N >= 4 and N even.
        # N = 2*(3*m + 2*n)
        n, m = 0, 0
        while 6 * m <= N:
            if (N - 6 * m) % 4 == 0:
                n = (N - 6 * m) // 4
                break
            m += 1
        # TODO: display
        for k in range(m):
            for i in range(3):
                for j in range(3):
                    g[6 * k + i][6 * k + j] = d[(3, 1)][i][j]
                    g[6 * k + 3 + i][6 * k + 3 + j] = d[(3, 1)][i][j]
                    g[6 * k + i][6 * k + 3 + j] = d[(3, 2)][i][j]
                    g[6 * k + 3 + i][6 * k + j] = d[(3, 2)][i][j]
        for k in range(n):
            for i in range(4):
                for j in range(4):
                    g[6 * m + 4 * k + i][6 * m + 4 * k + j] = d[(4, 3)][i][j]

    elif N == 7:
        # TODO: display
        _s = "aabbcc."
        for i in range(N):
            g[i][6] = _s[i]
            g[6][i] = _s[i]
        for k in range(2):
            for l in range(2):
                for i in range(3):
                    for j in range(3):
                        g[3 * k + i][3 * l + j] = d[(3, 1)][i][j]

    elif N == 11:
        # TODO: display
        for k in range(1):
            for i in range(3):
                for j in range(3):
                    g[6 * k + i][6 * k + j] = d[(3, 1)][i][j]
                    g[6 * k + 3 + i][6 * k + 3 + j] = d[(3, 1)][i][j]
                    g[6 * k + i][6 * k + 3 + j] = d[(3, 2)][i][j]
                    g[6 * k + 3 + i][6 * k + j] = d[(3, 2)][i][j]
        for k in range(1):
            for i in range(5):
                for j in range(5):
                    g[6 + i][6 + j] = d[(5, 3)][i][j]

    else:
        # N != 7, 11 and even
        # N = 5*m + 4*n
        n, m = 0, 0
        while 5 * m <= N:
            if (N - 5 * m) % 4 == 0:
                n = (N - 5 * m) // 4
                break
            m += 1
        # TODO: display
        for k in range(m):
            for i in range(5):
                for j in range(5):
                    g[5 * k + i][5 * k + j] = d[(5, 3)][i][j]
        for k in range(n):
            for i in range(4):
                for j in range(4):
                    g[5 * m + 4 * k + i][5 * m + 4 * k + j] = d[(4, 3)][i][j]

    print(*["".join(g[i]) for i in range(N)], sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 53104
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T&x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long s64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define gc (c=getchar())
int read()
{
	char c;
	while(gc<'-');
	if(c=='-')
	{
		int x=gc-'0';
		while(gc>='0')x=x*10+c-'0';
		return -x;
	}
	int x=c-'0';
	while(gc>='0')x=x*10+c-'0';
	return x;
}
#undef gc

const int N=700+5;
bool lk[N][N];
bool dp[N];
int col[N];
int c[2];

int n;
void dfs(int x,int nc)
{
	if(col[x]!=-1)
	{
		if(col[x]!=nc)
		{
			puts("-1");
			exit(0);
		}
		return ;
	}
	col[x]=nc;
	++c[nc];
	rep(y,1,n)
	if(lk[x][y])dfs(y,nc^1);
}

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	int m;
	cin>>n>>m;
	rep(i,1,n)
	rep(j,1,n)lk[i][j]=i!=j;
	rep(i,1,m)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		lk[x][y]=lk[y][x]=0;
	}
	rep(i,1,n)col[i]=-1;
	dp[0]=1;
	rep(x,1,n)
	if(col[x]==-1)
	{
		c[0]=c[1]=0;
		dfs(x,0);
		per(i,n,0)
		{
			bool ans=0;
			rep(j,0,1)
			if(c[j]<=i)ans|=dp[i-c[j]];
			dp[i]=ans;
		}
	}
	int ans=0;
	rep(x,0,n)
	if(dp[x])chmax(ans,x*(n-x));
	cout<<n*(n-1)/2-ans;
}		



Measured memory_bytes: 768
#include <stdio.h>
int main(){
    int w,h,x,y,r;
    scanf( "%d %d %d %d %d" , &w , &h , &x , &y , &r );

    if( y + r <= h &&  0 <= y - r && x + r <= w && 0 <= x - r ){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


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

int main() {
  int h,w,inf=100000,ans=0;
  pair<int,int> v;
  cin >> h >> w;
  vector<vector<char>> a(h+2,vector<char>(w+2));
  vector<vector<int>> b(h+2,vector<int>(w+2));
  queue<pair<int,int>> l;
  vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
  for (int i=0;i<h+2;i++){
      for (int j=0;j<w+2;j++){
          b.at(i).at(j)=0;
      }
  }
  for (int i=1;i<h+1;i++){
    for (int j=1;j<w+1;j++){
      cin >> a.at(i).at(j);
      if (a.at(i).at(j)=='.') {
        b.at(i).at(j)=inf;
      }
      if (a.at(i).at(j)=='#'){
        v.first=j;v.second=i;
        l.push(v);
      }
    }
  } 
  while (!l.empty()){
    int x=l.front().second;
    int y=l.front().first;
    l.pop();
  for (int i=0;i<4;i++){
    if (b.at(x).at(y)+1<b.at(x+dx.at(i)).at(y+dy.at(i))){
      b.at(x+dx.at(i)).at(y+dy.at(i))=b.at(x).at(y)+1;
      ans=b.at(x).at(y)+1;
      v.second=x+dx.at(i);v.first=y+dy.at(i);
      l.push(v);
    }
  }
  }
   cout << ans << endl;
}

Measured memory_bytes: 13456
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int n, x;
	cin >> n >> x;
	int l[n];
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	
	int d = 0;
	int count = 1;
	for (int i = 0; i < n; i++) {
		d += l[i];
		if (d <= x) {
			count++;
		}
	}
	
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for(int (i)=(l);(i)<=(r);(i)++)
#define MOD 1000000007
using namespace std;
#define ll long long
ll inv(ll a){
  ll t=1;
  while (a>1){
    t=t*(MOD-MOD/a)%MOD;
    a=MOD%a;
  }
  return t;
}
ll comb(ll n,ll k){
  if (k>n-k) k=n-k;
  ll nu=1,de=1;
  rep(i,1,k+1){
    nu=nu*(n+1-i)%MOD;
    de=de*i%MOD;
  }
  return nu*inv(de)%MOD;
}
ll nHr(ll n, ll r){
    return comb(n+r-1,r);
}
int main(){
    ll x,y,i=-1,j=-1;
    cin>>x>>y;
    if((2*x-y)%3==0)i=(2*x-y)/3;
    if((2*y-x)%3==0)j=(2*y-x)/3;
    if(i<0||j<0)cout<< "0" <<endl;
    else cout<< comb(i+j,j) <<endl;
}

Measured memory_bytes: 256
fun trace(a: IntArray) = println(a.joinToString(separator = " "))

fun insertionSort(a: IntArray?) {
    a?.let {
        trace(a)
        for (i in 1 until a.size) {
            val pivotVal = a[i]
            val pivotIdx = (a.slice(0 until i)).indexOfFirst { it > pivotVal }
            if (pivotIdx != -1) {
                (i downTo pivotIdx+1).forEach { a[it] = a[it-1] }
                a[pivotIdx] = pivotVal
            }
            trace(a)
        }
    }
}

fun main(args: Array<String>) {
    readLine()
    readLine()
            ?.split("""\s+""".toRegex())
            ?.map { it.toInt() }
            ?.toIntArray()
            ?.let { insertionSort(it) }

}


Measured memory_bytes: 33548
#include <iostream>
#include <vector>
#include <functional>
#include <queue>
#include <utility>

constexpr int INF = 1000000000;
using Pair = std::pair<int, int>;

int n, k;

int v[101][101];
int c[101];
int dijkstra(int st, int en) {
    for(int i = 0; i < n; ++i) {
        c[i] = INF;
    }
    c[st] = 0;

    std::priority_queue<Pair, std::vector<Pair>, std::greater<Pair>> que;
    que.push({0, st});

    while(!que.empty()) {
        auto p = que.top(); que.pop();

        if(c[p.second] < p.first) {
            continue;
        }

        for(int i = 0; i < n; ++i) {
            if(v[p.second][i] && c[p.second] + v[p.second][i] < c[i]) {
                c[i] = c[p.second] + v[p.second][i];
                que.push({c[i], i});
            }
        }
    }
    
    return c[en];
}

int main() {
    while(std::cin >> n >> k, n + k) {
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            v[i][j] = 0;
        }
    }

    int c, p, q, r;
    for(int i = 0; i < k; ++i) {
        std::cin >> c >> p >> q;
        --p, --q;
        if(c) {
            std::cin >> r;

            if(v[p][q]) {
                v[p][q] = v[q][p] = std::min(v[p][q], r);
            }else {
                v[p][q] = v[q][p] = r;
            }
        }else {
            r = dijkstra(p, q);

            std::cout << (r == INF ? -1 : r) << std::endl;
        }
    }
    }
}

Measured memory_bytes: 2972
// B - Not Found
// https://atcoder.jp/contests/abc071/tasks/abc071_b
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  // SORT(s);
  // set<char> g;
  vlli d(26, 0);
  rep(i, 0, s.size())
  {
    count = s[i] - 97;
    d[count]++;
  }
  rep(i, 0, 26)
  {
    if (d[i] == 0)
    {
      t = (d[i] + i) + 97;
      cout << t << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll tmp = 100, res = 0;
  while (tmp < n) {
    res++;
    tmp *= 1.01;
  }
  cout << res << endl;
}

Measured memory_bytes: 3636
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/4;
    public static final int inf = Integer.MAX_VALUE/4;

    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        int k = in.ni();
        for (int i = 0; i < s.length; i++) {
            if(k==0) break;
            if(i == s.length-1){
                s[i] = (char)((s[i]+k-'a')%('z'-'a'+1)+'a');
            }else{
                if(s[i]=='a') continue;
                if('z'-s[i]+1<=k){
                    k -= 'z'-s[i]+1;
                    s[i] = 'a';
                }
            }
        }
        out.println(new String(s));
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 25172
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
   int s,w;
   cin >> s >>w;
   
   if(w >= s) cout << "unsafe\n";
   else cout << "safe\n";
   
   
   return 0;
}

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

int main()
{
    long long  N;
    long long  P[100005], J[100005];

    while ( cin >> N, N != 0 ) {
        long long sum = 0;
        for ( int i = 0; i < N; i++ ) {
            cin >> P[i];
            sum += P[i];
        }

        for ( int i = 0; i < N - 1; i++ ) {
            cin >> J[i];
        }

        sort(J, J + N - 1, greater < long long  >  ());
        long long  maxv = N * sum;
        for ( int i = 0; i < N - 1; i++ ) {
            sum += J[i];
            maxv = max(maxv, (N - i - 1) * sum);
        }
        cout << maxv << endl;
    }

    return ( 0 );
}



Measured memory_bytes: 4032
#include <iostream>
#include <vector>

using namespace std;

bool Spr(vector< vector<int> >& dp, int s, int a, int b)
{
    int akt = a;
    for (int i = 0; i < 18; ++i)
        if ((s & (1 << i)) > 0)
            akt = dp[i][akt];
    if (akt >= b)
        return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int L;
    cin >> L;
    vector< vector<int> > dp(18, vector<int>(n));
    for (int l = 0, p = 0; l < n; ++l)
    {
        while (p < n && a[p] - a[l] <= L)
            ++p;
        --p;
        dp[0][l] = p;
    }
    for (int i = 1; i < 18; ++i)
        for (int j = 0; j < n; ++j)
            dp[i][j] = dp[i - 1][dp[i - 1][j]];
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        if (a > b)
            swap(a, b);
        int l = 1, p = n, s, r = -1;
        while (l <= p)
        {
            s = (l + p) / 2;
            if (Spr(dp, s, a, b))
            {
                r = s;
                p = s - 1;
            }
            else
                l = s + 1;
        }
        cout << r << endl;
    }
    return 0;
}


Measured memory_bytes: 8312
macro_rules! input {
    // ?
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };

    // stdinの生成 値の読み込み開始
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    // ?
    ($next:expr) => {};
    // ?
    ($next:expr, ) => {};

    // 変数名:型の読み込みの繰り返し
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    // 値を読み込むベース 型,の繰り返し
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    // 配列の読み込み
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    // 文字列Vec<char>の読み込み
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    // usize1?の読み込み
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    // 指定した型で読み込み
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
    };

    println!("{}", solve(n));
}

fn solve(n: usize) -> usize {
    return n / 2 * (n / 2 + n % 2);
}

macro_rules! tests {
    ($($name:ident:[$( $args:expr ),*] => $output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output,super::solve($($args),*));
                }
            )*
        }
    }
}


tests! {
    //テスト名:[引数]=>expected
    test1:[3]=>2,
    test2:[6]=>9,
    test3:[11]=>30,
    test4:[50]=>625,
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

#include <stdio.h>

using namespace std;

typedef long long ll;

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

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

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

    int a = (int) ((N * 100.0 + 100) / 108.0); // this may be wrong
    // int a = (int) ((N * 100.0 + 99) / 108.0);
    int b = (int) ( a * 108.0 / 100.0);

    if (N == b) {
        cout << a << endl;
    } else {
        cout << ":(" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
s = input()
n = len(s)
f1 = True
for i in range(n//2):
    if s[i] != s[n-i-1]:
        f1 = False
f2 = True
for i in range((n-1)//4):
    if s[i] != s[(n-1)//2-1-i]:
        f2 = False
f3 = True
nn = n - (n+3)//2
for i in range(nn//2):
    if s[i] != s[n-i-1]:
        f3 = False
if f1 and f2 and f3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    dist = [-1] * N
    dist[0] = 0
    queue = deque([0])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist[nv] == -1:
                dist[nv] = dist[v] + 1
                queue.append(nv)

    if dist[N - 1] in (1, 2):
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 59564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll n, p;
    cin >> n >> p;
    if(n == 1){
        cout << p << endl;
        return 0;
    }
    ll ans = 1;    
    for (ll i = 2; i <= sqrt(p); i++){
        ll cnt = 0;
        while(!(p % i)){
            p /= i;
            cnt++;
        }
        ans *= pow(i, cnt/n);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        n: usize, m: u64, q: usize,
        qs: [(Usize1, Usize1, u64, u64); q]
    }
    let mut sq = Vec::new();
    let mut st = vec![Some(1), None];
    let mut an = 0;
    while let Some(ins) = st.pop() {
        if let Some(x) = ins {
            sq.push(x);
            st.push(None);
            if sq.len() == n {
                let sc = qs
                    .iter()
                    .map(|&(a, b, c, d)| if sq[b] - sq[a] == c { d } else { 0 })
                    .sum();
                an = an.max(sc);
            } else {
                for x in (x..=m).rev() {
                    st.push(Some(x));
                }
            }
        } else {
            sq.pop();
        }
    }
    println!("{}", an)
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
 
using namespace std;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = 4*atan(1);
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
// ll gcd(ll a, ll b) { 
//     if (a == 0) return b; 
//     return gcd(b % a, a); 
// }
// ll f(ll x) {
// 	x%=MOD;
// 	if(x<0)x+=MOD;
// 	return x;
// }
// ll power(int base, int power) {
// 	ll prod = 1;
// 	ll b = base;
// 	while(power) {
// 		if (power & 1) {
// 			prod = f(prod*b);
// 		}
// 		b = f(b*b);
// 		power/=2;
// 	}
// 	return prod;
// }
// struct line {
//     int m, c;
//     ll eval(int x) { return 1LL * m * x + c; }
//     double intersectX(line l) { return (double) (c - l.c) / (l.m - m); }
//0 is white, 1 is black
ll down[2][100001],up[2][100001];
int n,m;
vector<int> adj[100001];
ll pre[2][100001], suf[2][100001], prv[2];
ll mul(ll a, ll b) {
	return (a*b)%m;
}
ll add(ll a, ll b) {
	return (a+b)%m;
}
void dfs(int cur, int par) {
	down[0][cur] = 1, down[1][cur] = 1;
	for (int i : adj[cur]) {
		if (i==par) continue;
		dfs(i,cur);
		down[0][cur] = mul(down[0][cur],down[0][i]);
		down[1][cur] = mul(down[1][cur],add(down[1][i],down[0][i]));
	}
	prv[0] = 1, prv[1] = 1;
	for (int i = 0; i < adj[cur].size(); i++) {
		if (adj[cur][i]==par)continue;
		pre[0][adj[cur][i]] = prv[0];
		pre[1][adj[cur][i]] = prv[1];
		prv[0] = mul(prv[0],down[0][adj[cur][i]]);
		prv[1] = mul(prv[1],add(down[0][adj[cur][i]],down[1][adj[cur][i]]));
	}
	prv[0] = 1, prv[1] = 1;
	for (int i = adj[cur].size()-1; i>=0; i--) {
		if (adj[cur][i]==par)continue;
		suf[0][adj[cur][i]] = prv[0];
		suf[1][adj[cur][i]] = prv[1];
		prv[0] = mul(prv[0],down[0][adj[cur][i]]);
		prv[1] = mul(prv[1],add(down[0][adj[cur][i]],down[1][adj[cur][i]]));
	}
}
void dfs2(int cur ,int par) {
	for (int i : adj[cur]) {
		if (i==par)continue;
		up[0][i] = mul(up[0][cur],mul(pre[0][i],suf[0][i]));
		up[1][i] = add(mul(up[0][cur],mul(pre[0][i],suf[0][i])),mul(up[1][cur],mul(pre[1][i],suf[1][i])));
		dfs2(i,cur);
	}
}
void solve() {
	scanf("%d %d",&n,&m);
	for (int i = 1,x,y; i < n; i++) {
		scanf("%d %d",&x,&y);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	up[0][1] = up[1][1] = 1;
	dfs(1,0);
	dfs2(1,0);
	for (int i = 1; i <= n; i++) {
		// cout << down[0][i] << " " << down[1][i] << " " << up[0][i] << " " << up[1][i] << " " << pre[0][i] << " " << pre[1][i] << " " << suf[0][i] << " " << suf[1][i] << endl;
		printf("%lld\n",mul(down[1][i],up[1][i]));
	}
}
int main() {
	int t=1;
	// cin >> t;
	for (int i = 1; i <= t; i++) { 
		// cout << "Case #" << i << ": ";
		solve();
	}
}

Measured memory_bytes: 18560
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nq = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nq[0];
        var q = nq[1];
        var adjList = new List<int>[n + 1];
        for (int i = 1; i < adjList.Length; ++i)
        {
            adjList[i] = new List<int>();
        }
        for (int i = 1; i < n; ++i)
        {
            var ab = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var a = ab[0];
            var b = ab[1];
            adjList[a].Add(b);
            adjList[b].Add(a);
        }
        var queries = new Tuple<int, int>[q];
        for (int i = 0; i < queries.Length; ++i)
        {
            var px = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            queries[i] = Tuple.Create(px[0], px[1]);
        }

        var selfPoints = new long[adjList.Length];
        for (int i = 0; i < queries.Length; ++i)
        {
            selfPoints[queries[i].Item1] += queries[i].Item2;
        }

        var ancestralPoints = new long[adjList.Length];
        for (int i = 1; i < ancestralPoints.Length; ++i)
        {
            ancestralPoints[i] = long.MinValue;
        }
        var bfs = new Queue<int>();
        bfs.Enqueue(1);
        ancestralPoints[1] = selfPoints[1];
        while (bfs.Any())
        {
            int v = bfs.Dequeue();
            for (int j = 0; j < adjList[v].Count; ++j)
            {
                int u = adjList[v][j];
                if (ancestralPoints[u] >= 0)
                {
                    continue;
                }

                ancestralPoints[u] = ancestralPoints[v] + selfPoints[u];
                bfs.Enqueue(u);
            }
        }

        Console.WriteLine(string.Join(" ", ancestralPoints.Skip(1)));
    }
}


Measured memory_bytes: 59084
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int ans[26],n,a[200006];
ll pos=0,cnt=0;
int main()
{
	scanf("%d",&n);
	int k=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		int flag=1;
		for(int j=0;j<=20;j++)
		{
			if(a[i]&(1<<j)) ans[j]++;
			if(ans[j]>1) {flag=0;}
		}
		if(!flag)
		{
			pos+=cnt;
			while(k<i)
			{
				int ok=1;
				for(int j=0;j<=20;j++)
				{
					ans[j]-=(a[k]&(1<<j))?1:0;
					if(ans[j]>1) ok=0;
				}
				k++;
				cnt--;
				if(ok) break;
				else pos+=cnt;
			}
		}
		cnt++;
	}
	printf("%lld\n",pos+((1+cnt)*cnt/2));
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair                                                     
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;

int main()
{
	int r,c,n;
	cin>>r>>c>>n;
	int x=max(r,c);
	double y=(double)n/x;
	int ans=ceil(y);
	cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>

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

  double d1v = 1;
  for(int i = 2; i <= N; i++) d1v = d1v * (i + 1) / i + 1;

  double xv = d1v * (2 * N - 1) / 2;

  printf("%.20lf\n", D1 * d1v + X * xv);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int h[100010];
bool flag[100010];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){cin>>h[i];flag[i]=true;}
	for(int i=0;i<m;i++)
	{
		int a,b;cin>>a>>b;a--;b--;
		if(h[a]<=h[b])flag[a]=false;
		if(h[a]>=h[b])flag[b]=false;
	}
	
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(flag[i])ans++;
	}
	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 4120
#include <stdio.h>

int main() {
	int i, j, hita = 4, hitb = 4, hitx = 4, hity = 4, cont = 0;
	char S[6];

	scanf("%s", &S);
	
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 4; j++) {
			if (hita != i && hitb != i && hitx != i && hity != i) {
				if (i != j && S[i] == S[j]) {
					if (cont == 0) {
						hita = i;
						hitb = j;
					} else {
						hitx = i;;
						hity = j;
					}
					cont++;
				}
			}
		}
	}

	printf(cont == 2 ? "Yes\n" : "No\n");

	return 0;
}

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

int main(){
  long long n,i,cur,ans;
  cin >> n;
  vector<pair<long long,long long>> a(n);
  for(i=0; i<n; i++){
    cin >> a[i].second >> a[i].first;
  }
  sort(a.begin(),a.end());
  for(i=0; i<n;i++){
    cur=a[i].first;
    ans+=a[i].second;
    if(cur<ans){
      cout << "No"; return 0;
    }
  }
  cout << "Yes";
}
  
  

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((ll)(1e16))
#define pi (2*acos(0))
#define M ((ll)(1e9 + 7))
#define NN ((ll)(305))
#define N ((int)(3e5 + 10))
#define eps 0
#define logn 20


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;


typedef tree < ll,  null_type,  less < ll >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;

int dp[100][105];


int call(int mask, int i, int n)
{
    if(i==n) return 1;
    mask = mask%64;
    if(dp[mask][i]!=-1) return dp[mask][i];

    dp[mask][i] = 0;

    int vis[3];
    memset(vis,0,sizeof vis);
    if(mask%16==1 || mask%16==4 || (i>2 && (mask/16)%4==0 && (mask%4==1 || (mask/4)%4==1))) vis[2] = 1;
    if(mask%16==2) vis[1] = 1;
    for(int c = 0; c<3; c++){
        if(i<2 || vis[c]==0){
            dp[mask][i] += call(mask*4 + c,i+1,n);
            if(dp[mask][i]>=M) dp[mask][i] -= M;
        }
    }
    dp[mask][i] += call(mask*4 + 3,i+1,n);
    if(dp[mask][i]>=M) dp[mask][i] -= M;
    return dp[mask][i];
}

int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,-1,sizeof dp);
    printf("%d\n",call(0,0,n));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char ch;
    
    while(1){
        scanf("%c", &ch);
        if (ch == '\n') break;
        if('a' <= ch && ch <= 'z') ch -= 32;
        else if('A' <= ch && ch <= 'Z') ch += 32;
        printf("%c", ch);
    }
    puts("");
    return 0;
}


Measured memory_bytes: 2084
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine());

        long sum = 0;

        for (long rem = 1; true; ++rem)
        {
            long r;
            var quo = Math.DivRem(n - rem, rem, out r);
            if (quo <= rem)
                break;
            if (r == 0)
                sum += quo;
        }

        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
long long n,d;
int ans;
int main()
{
	cin>>n>>d;
	for(int i=1;i<=n;i++)
	{
		long long x,y;
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d)
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

using ll = long long;
using P = pair<ll,ll>;

void solve(long long K, std::string S){
    if(S.size()<=K){
        cout << S <<endl;
        return;
    }
    string ans ="";
    for(int i=0;i<K;i++){
        ans += S[i];
    }
    ans +="...";
    cout << ans << endl;

}

int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	string kata;
	int i;
	cin>>kata;
	for(i=0;i<kata.length();i+=2){
		printf("%c",kata[i]);
	}
	printf("\n");
	return 0;
};

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef pair<PII, int> PPI;
typedef pair<int, PII> PIP;

const int INF = 3e18;

int n, a, b;
int mx, mn;
signed main()
{
  cin >> n >> a >> b;

  mx = a + b * (n - 1);
  mn = a * (n - 1) + b;

  cout << max(mx - mn + 1, 0ll) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] tasks = new int[3];
        for (int i = 0; i < 3; i++) {
            tasks[i] = sc.nextInt();
        }

        Arrays.sort(tasks);
        int min = Math.abs(tasks[0] - tasks[1]) + Math.abs(tasks[1] - tasks[2]);
        System.out.println(min);
    }
}


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

main(){
	while(true){
		int t;
		cin>>t;
		if(t == 0){
			break;
		}
		
		int n;
		cin>>n;
		for(int i=0; i<n; ++i){
			int s, e;
			cin>>s>>e;
			t -= e-s;
		}
		
		if(t<=0){
			puts("OK");
		}else{
			cout << t << endl;
		}
	}
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define MOD                 1000000007LL
#define EPS                 1e-9
#define io                  ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAXN = 1e5+5;

int main(){
	io;
	int n;
	cin >> n;
	cout << 48 - n << endl;
	return 0;
}

Measured memory_bytes: 892
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
count = 0
for i in range(n):
    a = list(map(int, input().split()))
    if c + sum([a[i] * b[i] for i in range(m)]) > 0:
        count += 1
print(count)



Measured memory_bytes: 2940
"""
author : halo2halo
date : 29, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8').rstrip()
ans=S[0]+str(len(S[1:len(S)-1]))+S[-1]

print(ans)

Measured memory_bytes: 3060
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a;
    map <int, int> kk;
    REP1(i,9){
        REP1(j,9){
            kk[i*j]++;
        }
    }
    cin >> a;
    if(kk[a]>0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int N , K, totalMoveValue = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    
    int robotA, robotB;
    robotA = x * 2;
    robotB = abs((x - K) *2);
        
    if (robotA < robotB) {
      totalMoveValue += robotA;
    } else {
      totalMoveValue += robotB;
    }
  }
  
  cout << totalMoveValue << endl;
}


Measured memory_bytes: 256
n = int(input())
s = [(i == "W")*1 for i in list(input())]
c = [0]*(n+1)
for i in range(n):
    c[i+1] = c[i] + s[i]
ans = float("inf")
for i in range(n):
    t = c[i] + (n-i-1-c[-1]+c[i+1])
    ans = min(ans,t)
print(ans)

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


void solve(long long X, long long A, long long B){
    cout << (X - A) % B << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(X, A, B);
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n>>m;
    double ans=0;
    ll kkl=1900*m+100*(n-m);
    double cl=1;
    for(int i=0;i<m;i++){
        cl/=2;
    }
    double cl2=1-cl;
    double x=1;
    for(int i=1;i<1000;i++){
        if(i!=1){
            x*=cl2;
        }
        ans+=kkl*i*cl*x;
    }
    cout<<round(ans)<<endl;
}


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

int main(void){
    int n,a;
    int ans=0;
    cin>>n;
    int j=1;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a==j){
            j++;
        }
        else{
            ans++;
        }
    }
    if(j==1) cout<<-1;
    else{
        cout<<ans;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
typedef vector<pairs> p;


ll gcd(ll A,ll B){
    if (A%B==0)return(B);
    else return(gcd(B,A%B));
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}

bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;

    ll r = 0, b = 0;
    for(ll i=0;i<n;++i){
        if(s[i] == 'R'){
            r++;
        }else if(s[i] == 'B'){
            b++;
        }
    }
    string ans = "No";
    if(r > b){
        ans = "Yes";
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
<?php
 
fscanf(STDIN,"%s %s",$s,$t);
fscanf(STDIN,"%d %d",$a,$b);
fscanf(STDIN,"%s",$u);

if($u === $s){
  $a--;
}elseif($u === $t){
  $b--;
}
echo $a." ".$b;
  
  
?>

Measured memory_bytes: 3828
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
A,B = input().split()
A = int(A)
B = int(B.replace(".",""))

ans = (A*B)//100

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) > abs(x - b)) {
    cout << 'B' << endl;
  } else {
    cout << 'A' << endl;
  }
  return 0;
}


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

int N;

int flog(int i, vector<int> &dp, vector<int> &h){
    if(i==0){
        return 0;
    }
    
    if(dp[i] !=-1){
        return dp[i];
    }

    if(i==1){
        dp[i] = flog(i-1 , dp ,h) + abs(h[i]-h[i-1]);
    }else{
        dp[i] = min(abs(h[i]-h[i-2])+flog(i-2, dp ,h), abs(h[i]-h[i-1]) + flog(i-1, dp ,h));    
    }
    //cout << "dp[" << i <<"]" << dp[i] << endl;

    return dp[i];
}


int main(){
    cin >> N;
    vector<int> dp(N,-1);
    vector<int> h(N);
    
    rep(i,N){
        int x; cin >> x;
        h[i] = x;
    }

    int ans = flog(N-1, dp ,h);
    cout << ans << endl;
}


Measured memory_bytes: 11928
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define rep1(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL_MAX 9223372036854775807
#define LL_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    cout << n*n*n << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,t;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s>>t;
    s+=t;
    ans=stoi(s);
    rep(i,1000){
        if(i*i==ans){
            Cout("Yes");
            return 0;
        }
    }
    Cout("No");
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }
    ll t[D] = {};
    rep(i, 0, D) {
        int mx = -1;
        rep(j, 0, 26) {
            if (mx < s[i][j]) {
                mx = s[i][j];
                t[i] = j + 1;
            }
        }
    }
    /*vector<int> last_day(26, -1);
    rep(i, 0, D) {
        if (i != 0) score[i] = score[i - 1];
        score[i] += s[i][t[i]];
        last_day[t[i]] = i;
        int decrease = 0;
        rep(j, 0, 26) {
            decrease += c[j] * (i - last_day[j]);
        }
        score[i] -= decrease;
    }*/
    rep(i, 0, D) {
        cout << t[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3672
def sub():
    INF = 10 ** 12
    N, K = map(int, input().split())
    hs = [int(e) for e in input().split()]
    optimal_values = [INF for _ in range(N)]
    optimal_values[0] = 0
    for i in range(0, N):
        for j in range(1, K + 1):
            p = i + j
            if p < N:
                optimal_values[p] = min(
                    optimal_values[p], optimal_values[i] + abs(hs[p] - hs[i])
                )
            else:
                break
    print(optimal_values[-1])
    # print(optimal_values)


sub()


Measured memory_bytes: 56544
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convertstring(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}
map< int64_t, int > prime_factor(int64_t n) {
	map< int64_t, int > ret;
	for (int64_t i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
vector<ll> divisor(ll n) {
	vector<ll>res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i != 0)continue;
		res.push_back(i);
		if (i * i != n)res.push_back(n / i);
	}
	return res;
}

int K;
int main()
{
	ll ans = 0;
	cin >> K;
	for (int a = 1; a <= K; a++) {
		for (int b = a; b <= K; b++) {
			for (int c = b; c <= K; c++) {
				if (a != b && b != c && a != c) {
					int res = gcd(a, b);
					ans += gcd(c, res) * 6;
				}
				else if (a == b && b == c) {
					int res = gcd(a, b);
					ans += gcd(c, res);
				}
				else {
					int res = gcd(a, b);
					ans += gcd(c, res)*3;
				}
				//cout << ans<<" "<<a<<b<<c << endl;
			}
		}
	}
	cout << ans << endl;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int n,m;
	cin >> n >> m;
	string a,b;
	
	for(int i=1; i<=m ; i++)
	{
		char c = n + '0';
		a += c;
	}
	
	for(int i=1; i<=n ; i++)
	{
		char c = m + '0';
		b += c;
	}
	
	if(a <= b)
		cout << a;
	else
		cout << b;
}



Measured memory_bytes: 256