akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
vector<int> ckd;
vector<int> tps;
int dfs (int crr) {
  ckd[crr] = true;
  for (int nxt: grh[crr]) {
    if (!ckd[nxt]) {
      dfs(nxt);
    }
  }
  tps.push_back(crr);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  grh.resize(n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    grh[--x].push_back(--y);
  }
  ckd.resize(n, false);
  for (int i = 0; i < n; i++) {
    if (!ckd[i]) {
      dfs(i);
    }
  }
  vector<int> dp(n, 0);
  for (int i = 1; i < n; i++) {
    int crr = tps[i];
    for (int nxt : grh[crr]) {
      dp[crr] = max(dp[crr], dp[nxt] + 1);
    }
  }
  int maxv = 0;
  for (int i = 0; i < n; i++) {
    maxv = max(maxv, dp[i]);
  }
  cout << maxv << '\n';
  return 0;
}

Measured memory_bytes: 9080
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n; i++){
			a[i]=sc.nextInt();
		}
		Arrays.sort(a);
		for(int i=0; i<n-1; i++){
			if(a[i]==a[i+1]){
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}


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

int main(){
    int x, n, v;
    cin >> x >> n;
    set<int> st;

    for(int i = 0; i < n; i++){
        cin >> v;
        st.insert(v);
    }

    for(int i = 0; ; i++){
        int l, r;
        l = x - i;
        r = x + i;

        if(st.find(l) == st.end()){
            cout << l << endl;
            break;
        }
        if(st.find(r) == st.end()){
            cout << r << endl;
            break;
        }
    }
    return 0;
}

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

int A[10000];
int main() {
    int N, M;
    cin >> N >> M;

    for (int i=0; i < M; ++i) cin >> A[i];

//   int day = N;
//   for (int i=0; i < M; ++i) {
//       day -= A[i];
//       if (day <= 0) {
//           day = -1;
//           break;
//       }
//   }
    int sum = 0;
    for (int i=0; i < M; ++i) {
        sum += A[i];
    }
    if (sum <= N) cout << (N-sum) << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 9223372036854775807
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
ll dp[105][100005];
int main()
{
	boost
	ll n,W;
	cin>>n>>W;
	ll wt[n],v[n];
	ll i,j;
	for(i=0; i<n; i++)
		cin>>wt[i]>>v[i];
	ll maxi=0;
	for(i=0; i<=n; i++)
	{
		for(j=0; j<=W; j++)
		{
			if(i==0)
				dp[i][j]=0;
			else if(j>=wt[i-1])
				dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
			else
				dp[i][j]=dp[i-1][j];
		}
	}
	cout<<dp[n][W]<<endl;
	return 0;
}

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

main(){
	string s;
	bool tbd;
	cin >> s;
	if(s[5]-'0'==1){
		tbd=true;
	}else if(s[6]-'0'>4){
		tbd=true;
	}else{
		tbd=false;
	}

	if(tbd==true){
		cout << "TBD" <<endl;
	}else{
		cout << "Heisei" <<endl;
	}

}




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

int main() {
  int a, b;
  cin >> a >> b;
  if (a - b <= 0)
    cout << 0 << endl;
  else
    cout << a - b << endl;
}

Measured memory_bytes: 3588
n = gets.to_i 
a = gets.split.map(&:to_i)
colors = Array.new(8, 0)
ra = 0
total = 0
#puts n
#puts a
n.times do |i|
  if a[i] >= 3200
    ra += 1
  else
    colors[ a[i] / 400 ] = 1
  end
end
8.times do |i|
	total = total + colors[i]
end
cmax = total + ra
if total < 1
	total = 1
end
puts puts "#{total} #{cmax}"
#puts total
#puts cmax

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>
#include <numeric>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); }
	ul lcm(const ul &a,const ul &b) { return (a/gcd(a,b))*b; } // a/gcd(a,b)*b <=> (a*b)/gcd(a,b)
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		for(ul i = 2;i*i < n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}
	ll rho_method(const ll &n)
	{
		auto f = [&](const ll &xi){ return (xi*xi+1)%n; };
		ll x = 2, y = 2, d = 1;
		while(d == 1)
		{
			x = f(x);
			y = f(f(y));
			d = lamlib::gcd(lamlib::abs(x-y),n);
		}
		return d;
	}
	// 素因数分解(試し割)
	std::vector<ll> prime_factorization_trial(const ll &n)
	{
		ll num = n;
		std::vector<ll> prime;
		for(ll i = 2;i*i <= n;++i)
		{
			while((num%i) == 0)
			{
				prime.emplace_back(i);
				num /= i;
			}
		}
		if(num > 1) prime.emplace_back(num);
		return prime;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

int main(int argc,char *argv[])
{
	int ans = 0;
	for(int i = 0;i < 5;++i)
	{
		int tmp;
		std::cin >> tmp;
		if(tmp == 0) ans = i+1;
	}

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

Measured memory_bytes: 3620
def bs(a,s):
    l = 0
    r = len(s)
    while l < r:
        m = (l+r)//2
        if s[m] == a:
            return True
        elif s[m] > a:
            r = m
        else:
            l = m + 1
    return False

n = int(input())
s = list(map(int,input().split()))
q = int(input())
X = list(map(int,input().split()))

ans = 0
for x in X:
    if bs(x,s):
        ans += 1
print(ans)


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a) a.begin(),a.end()
using ll=long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int cntodd=0;
    int cntf=0;
    for(int i=0;i<n;i++){
        if(a[i]%4==0) cntf++;
        if(a[i]%2==1) cntodd++;
    }
    if(cntodd<=cntf || cntf==cntodd-1 && cntf+cntodd==n) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)
import numpy as np
# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    n, a, b, c, d = map(int, input().split())
    # stringのindexとして扱う
    a = a - 1
    b = b - 1
    c = c - 1
    d = d - 1
    s = input()

    # aからCの間、bからdの間までの二連岩の存在確認
    if s[a:c+1].find("##") > -1 or s[b:d+1].find("##") > -1:
        print("No")
    else:
        # 二連岩がない場合は、ABDCの飛び越えパターンだけが問題になる
        if b < d and d < c:
            # 飛び越え不可能な場合はNOになる
            # bからdの間で飛び越える必要があり、...があると飛び越えできる
            # bスタートではなく、b-1からかぞえて...があればよい
            # dエンドではなく、d+1がおわりで...でも飛び越えできる
            if s[b-1:d+2].find("...") > -1:
                print("Yes")
            else:
                print("No")
        else:
            print("Yes")
solve()

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

int isPrime(int x);

int main() {
    
    int N; 
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int x;
        scanf("%d", &x);
        if (isPrime(x)) sum++;
    }

    cout << sum << '\n';
}

int isPrime(int x) {

    if (x < 2) return 0;
    else if (x == 2) return 1;
    if (x % 2  == 0) return 0;
    for (int i = 3; i*i <= x; i+=2) {
        if (x % i == 0) return 0;
    }
    return 1;
}



Measured memory_bytes: 3132
#include<stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if(b>a){
        d=b;
        b=a;
        a=d;

    }
    if(c>a){
        d=c;
        c=a;
        a=d;
    }
    if(c>b){
        d=c;
        c=b;
        b=d;
    }
    if(a>c){
        d=a;
        a=c;
        c=d;
    }
    if(b>c){
        d=b;
        b=c;
        c=d;
    }
    printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
use proconio::{fastout, input};

#[fastout]
fn main() {
  input! {
    n: i32,
  }
  let mut ans: i64 = 0;
  let mut pre: i64 = 0;
  for _ in 0..n {
    input!{
      mut a: i64,
    }
    if pre <= a {
      ans = ans+pre;
      a = a-pre;
    }
    ans = ans + a/2;
    pre = a%2;
  }
  
  
  println!("{}",ans);
}


Measured memory_bytes: 3228
#include <stdio.h>
int amari(int x){
  return x % 10; 
}
 
int min(int x[5]){
  int min = x[0];
  int i, count = 0;
  for(i=1;i<5;i++){
    if(x[i] == 0){
      
      continue;
    }
    else if(min > x[i]) {
      min = x[i]; count=i;
    }
  }
  return count;
}
 
int main(void){
  int A, B, C, D, E, k, l=0;
  int a[5], i;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&D);
  scanf("%d",&E);
  a[0] = amari(A);
  a[1] = amari(B);
  a[2] = amari(C);
  a[3] = amari(D);
  a[4] = amari(E);
  k = min(a);
  for(i=0;i<5;i++){
   if(a[i] == 0) l++;
  }
  if(l == 5) l -= 1;
  if(k == 0) {
    printf("%d",A+B+C+D+E+40-l*10-a[1]-a[2]-a[3]-a[4]);
  }
  else if(k == 1) printf("%d",A+B+C+D+E+40-l*10-a[0]-a[2]-a[3]-a[4]);
  else if(k == 2) printf("%d",A+B+C+D+E+40-l*10-a[0]-a[1]-a[3]-a[4]);
  else if(k == 3) printf("%d",A+B+C+D+E+40-l*10-a[0]-a[1]-a[2]-a[4]);
  else printf("%d",A+B+C+D+E+40-l*10-a[0]-a[2]-a[3]-a[1]);
  
  printf("\n");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }

struct T
{
    ll value;
    int id;
    bool isB;

};

int main(void){
    int n;
    cin >> n;
    vector<T> t;

    rep(i,n){
        ll a,b;
        cin >> a >> b;
        t.push_back({a,i,false});
        t.push_back({b,i,true});
    }

    sort(all(t), [](T x, T y){
        return x.value != y.value ? x.value < y.value : x.id < y.id;
    });
    vector<vector<bool>> low(n, {0,0});
    rep(i,n){
        low[t[i].id][t[i].isB] = true;
    }

    int HH = 0, LL = 0, HL = 0, LH = 0;
    ll sum = 0;
    rep(i,n){
        if (low[i][0] && low[i][1]) LL++;
        if (!low[i][0] && !low[i][1]) HH++;
        if (!low[i][0] && low[i][1]) HL++;
        if (low[i][0] && !low[i][1]) LH++;
        sum += t[i].value;
    }

    if (LL > 0 || LH == n || HL == n) {
        assert(LL == HH);
        cout << sum << endl;
    } else if (t[n].id != t[n-1].id) {
        cout << sum - t[n-1].value + t[n].value << endl;
    } else if (sum - t[n-2].value + t[n].value < sum - t[n-1].value + t[n+1].value) {
        cout << sum - t[n-2].value + t[n].value << endl;
    } else {
        cout << sum - t[n-1].value + t[n+1].value << endl;
    }

    /*

    OK
    //// _ - _ \\ - _ -
    ////  \\ - _
    //// _ \\ - _ -
    ///
    \\\

    NG
    \\ ////// \\

    */
    
    return 0;
}


Measured memory_bytes: 11372
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

bool used[50];
bool G[50][50];
int N, M;
void dfs(int v) {
    used[v] = true;
    //dump(v);
    rep(i, N){
        if (G[v][i] == false) continue;
        if (used[i] == true) continue;
            dfs(i);
    }
}

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

    cin >> N >> M;
    int a[M], b[M];

    rep(i ,M) {
        int s,t;
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]][b[i]] = true;
        G[b[i]][a[i]] = true;
    }
    int ans = 0;
    rep(i, M){
        G[a[i]][b[i]] = false;
        G[b[i]][a[i]] = false;
        rep(j, N) used[j] = false;
        dfs(0);
        bool bridge = false;
        rep(j, N) {
            if(used[j] == false) bridge = true;
        }
        if(bridge) ans++;
        G[a[i]][b[i]] = true;
        G[b[i]][a[i]] = true;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
h1=[0 for i in range(h)]
w1=[0 for i in range(w)]
m=[]
for i in range(h):
  a=input()
  m+=[a]
  if not "#" in a:
    h1[i]=1
    
for i in range(w):
  k=1
  for j in range(len(m)):
    if m[j][i]=="#":
      k=0
      break
  if k==1:
    w1[i]=1
    
for i in range(h):
  if h1[i]==1:
    continue
  ans=""
  for j in range(w):
    if w1[j]==1:
      continue
    ans+=m[i][j]
  print(ans)
  

Measured memory_bytes: 3064
// Created by CAD on 2020/2/4.
#include <bits/stdc++.h>

#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x7fffffffffffffff
#define mst(name, value) memset(name,value,sizeof(name))
#define FOPEN freopen("C:\\Users\\14016\\Desktop\\cad.txt","r",stdin)
#define test(n) cout<<#n<<":"<<n<<endl
#define tst(x, y) cout<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define lson (p<<1)
#define rson (p<<1|1)
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define ll long long
using namespace std;

const int maxn=1005;
int compress(int *a,int *b,int w,int n){
    vector<int> v;
    for(int i=1;i<=n;++i){
        for(int d=-1;d<=1;++d)
        {
            int ta=a[i]+d,tb=b[i]+d;
            if(1<=ta&&ta<=w) v.push_back(ta);
            if(1<=tb&&tb<=w) v.push_back(tb);
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=1;i<=n;++i)
    {
        a[i]=find(v.begin(),v.end(),a[i])-v.begin()+1;
        b[i]=find(v.begin(),v.end(),b[i])-v.begin()+1;
    }
    return v.size();
}
bool g[maxn*6][maxn*6];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int w,h,n;
    while(cin>>w>>h&&w&&h){
        cin>>n;
        int x1[maxn],x2[maxn],y1[maxn],y2[maxn];
        for(int i=1;i<=n;++i)
            cin>>x1[i]>>y1[i]>>x2[i]>>y2[i],x1[i]++,y1[i]++;
        w=compress(x1,x2,w,n),h=compress(y1,y2,h,n);
        for(int i=1;i<=w;++i)
            for(int j=1;j<=h;++j)
                g[i][j]=0;
        for(int i=1;i<=n;++i)
            for(int x=x1[i];x<=x2[i];++x)
                for(int y=y1[i];y<=y2[i];++y)
                    g[x][y]=1;
        int ans=0;
        int dx[4]={0,0,1,-1};
        int dy[4]={1,-1,0,0};
        for(int x=1;x<=w;++x)
            for(int y=1;y<=h;++y)
                if(!g[x][y]){
                    ans++;
                    queue<pii> q;
                    q.push({x,y});
                    while(!q.empty()){
                        pii now=q.front();q.pop();
                        for(int i=0;i<4;++i){
                            int tx=now.fi+dx[i],ty=now.se+dy[i];
                            if(tx<1||tx>w||ty<1||ty>h||g[tx][ty]) continue;
                            q.push({tx,ty}),g[tx][ty]=1;
                        }
                    }
                }
        cout<<ans<<'\n';
    }
    return 0;
}



Measured memory_bytes: 9996
// D - Alter Altar
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; string C; cin>>N>>C;
	int l = 0, r = N-1, c = 0;
	while(l < r){
		if(C[l] == 'W' && C[r] == 'R'){ l++; r--; c++; }
		else if(C[l] != 'W') l++;
		else if(C[r] != 'R') r--;
	}
	cout<< c <<endl;
}


Measured memory_bytes: 3732
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0 || n == 1) return dp[n]=1;
  if(dp[n] != -1) return dp[n];
  return dp[n]=fib(n-1) + fib(n-2);
}


int main (){
  int n,i;

  for(i=0;i<50;i++){
    dp[i]=-1;
  }


  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}





Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 1000+5;

int n;
int m;
char a[N];
char b[N];
int memo[N][N];

int main(){
	scanf("%s", a + 1);
	scanf("%s", b + 1);
	n = strlen(a + 1);
	m = strlen(b + 1);
	for(int i = 0; i <= m; i++){
		memo[0][i] = i;
	}
	for(int i = 0; i <= n; i++){
		memo[i][0] = i;
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			memo[i][j] = n + m;
			if(a[i] == b[j]) memo[i][j] = min(memo[i][j], memo[i-1][j-1]);
			memo[i][j] = min({1 + memo[i-1][j], 1 + memo[i][j-1], 1 + memo[i-1][j-1], memo[i][j]});
		}
	}
	printf("%d\n", memo[n][m]);
	return 0;
}


Measured memory_bytes: 7148
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  string ans;
  if(n == 3 || n == 5 || n == 7) ans = "YES";
  else ans = "NO";

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define mo 19930726
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
char mp[50][50],ch[50][50];
int n,m,sx,sy,vis[50][50],cnt,x,y;
int dx[5]={-1,1,0,0};
int dy[5]={0,0,1,-1};
inline bool check(int x,int y)
{
	if(x<=0||x>n||y<=0||y>m) return 0;
	return 1;
}
int main()
{
	cin>>n>>m;
	for(re int i=1;i<=n;i++)
		for(re int j=1;j<=m;j++){
			cin>>mp[i][j];
			ch[i][j]=mp[i][j];
			if(mp[i][j]=='*') cnt++;
			if(mp[i][j]=='@') x=i,y=j;
		}
	int F;
	while(cnt){
		if(x==1&&!(y&2)) F=2;
		else if(x==n-2&&y!=m&&(y&2)) F=2;
		else if(x==n&&y>1) F=3;
		else F=(y>>1)&1;
		for(int d=2;d;d--){
			x+=dx[F],y+=dy[F];
			if(mp[x][y]=='.') mp[x][y]='#';
			else cnt-=mp[x][y]=='*';
		}
	}
	for(re int i=1;i<=n;i++){
		for(re int j=1;j<=m;j++)
		cout<<mp[i][j];
		cout<<endl;
	}
}


Measured memory_bytes: 3084
n, q = map(int, input().split())
s = input().strip()

c = [0 for _ in range(n)]
for i in range(1, n):
    if s[i-1:i+1] == 'AC':
        c[i] = c[i-1] + 1
    else:
        c[i] = c[i-1]

for _ in range(q):
    l, r = map(lambda x: int(x) - 1, input().split())
    if l == 0:
        print(c[r])
    else:
        print(c[r] - c[l-1] - 1 if s[l-1:l+1] == 'AC' else c[r] - c[l-1])

Measured memory_bytes: 6160
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const ll inf = 1e12 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 7;

using namespace std;

ll dp[110][N];
ll w[N], v[N];

int main()
{
	barnarnar
	int n, W;
	cin >> n >> W;
	forn1(i, n)	cin >> w[i] >> v[i];
	for(int i = 1; i <= n; i++)
	{
		for(int j = 0; j <= W; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if(j - w[i] >= 0)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
		}
	}
	ll ans = 0;
	for(int j = 0; j <= W; j++)	ans = max(ans, dp[n][j]);
	cout << ans;
	return 0;
}



Measured memory_bytes: 80128
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>

typedef struct node{
  int key;
  struct node *prev;
  struct node *next;
}Node, *NodePointer;



NodePointer nil;

void init(){
  nil = malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert(int k){
  NodePointer x = malloc(sizeof(Node));

  x->key = k;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

NodePointer listSearch(int key){
  NodePointer ser;
  ser = nil->next;
  while(ser != nil && ser->key != key){
    ser = ser->next;
  }
  return ser;
}

void deleteNode(NodePointer del){
  if(del == nil)return;

  del->prev->next = del->next;
  del->next->prev = del->prev;
  free(del);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}
void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void print(){
  NodePointer prt = nil->next;
  while(1){
    if(prt == nil)break;
    printf("%d",prt->key);
    if(prt->next != nil){printf(" ");}
    prt = prt->next;
  }
  
  printf("\n");
}

int main(){
  int n, k,m;
  char com[11];

  scanf("%d",&n);

  init();
  for(m=0;m<n;m++){
    scanf("%s%d",com,&k);

    if(com[0] == 'i'){
      insert(k);
    }else if(com[0] == 'd'){
      if(com[6] == 'F'){
        deleteFirst();
      }else if(com[6] == 'L'){
        deleteLast();
      }else{
        deleteKey(k);
      }
    }
    

  }
   print();
  return 0;
  
}



Measured memory_bytes: 32960
from collections import Counter
import sys
N, K = map(int, input().split())
a_lis = [int(_) for _ in input().split()]

counter = sorted(Counter(a_lis).items(), key=lambda x: x[1])

if len(counter) > K:
    ans_list = counter[:len(counter) - K]
    count = sum([item[1] for item in ans_list])
    print(count)
    sys.exit()

print(0)

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

int main() {
    int h, w, a[501][501];
    vector<int> v;
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        if(i%2==1){
            for(int j=1;j<=w;j++){
                if(a[i][j]%2==1){
                    v.push_back(i);
                    v.push_back(j);
                    if(j<w){
                        v.push_back(i);
                        v.push_back(j+1);
                        a[i][j+1]++;
                    }else if(i<h){
                        v.push_back(i+1);
                        v.push_back(j);
                        a[i+1][j]++;
                    }
                }
            }
        }else{
            for(int j=w;j>=0;j--){
                if(a[i][j]%2==1){
                    v.push_back(i);
                    v.push_back(j);
                    if(j>1){
                        v.push_back(i);
                        v.push_back(j-1);
                        a[i][j-1]++;
                    }else if(i<h){
                        v.push_back(i+1);
                        v.push_back(j);
                        a[i+1][j]++;
                    }
                }
            }
        }
    }
    int n=v.size()/4;
    cout<<n<<endl;
    for(int i=0;i+3<n*4;i+=4){
        cout<<v[i]<<" "<<v[i+1]<<" "<<v[i+2]<<" "<<v[i+3]<<endl;
    }
	return 0;
}

Measured memory_bytes: 5232
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	ll r[87];
	r[0] = 2, r[1] = 1;
	fori(i, 2, 87) {
		r[i] = r[i - 1] + r[i - 2];
	}
	ll N;
	cin >> N;
	cout << r[N] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int[] A = new int[5];
        
        for(int i=0; i<5; i++)
            A[i] = sc.nextInt();
        
        Arrays.sort(A);
        
        System.out.println(A[4]-A[0]<=sc.nextInt()? "Yay!":":(");
    }
}


Measured memory_bytes: 23124
#include <iostream>
#define TIME 100000
using namespace std;

int main(void){
  int X;
  cin >> X;
  //ここまで入力

  //iまでの和を格納していく
  long long sum[TIME] = {0};
  for(int i=0; i<TIME-1; i++)
    sum[i+1] = sum[i] + (i+1);

  //sum[i]が初めてXを超えた時のiが最適解
  //なぜなら， 1,2,...,i のうちのいずれかを
  //選んだときの和によってXが表せるため
  for(int i=0; i<TIME; i++)
    if(X <= sum[i]){
      cout << i << endl;
      return 0;
    }
  
  return 0;
}


Measured memory_bytes: 1024
N, Q = map(int, input().split())
tree_dic = {}
count = [0] * (N+1) #count[0]は使用しない
for n in range(N):
    tree_dic[n+1] = []
for n in range(N-1):
    a, b = map(int, input().split())
    tree_dic[a].append(b)
#print(tree_dic)
for n in range(Q):
    p, x = map(int, input().split())
    count[p] += x

#木をたどって数字を伝搬させる
for key in tree_dic:
    l = tree_dic[key]
    for i in l:
        count[i] += count[key]

s = " ".join(map(str, count[1:]))
print(s)

Measured memory_bytes: 77540
using System;
using System.Linq;
class Practice
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        long[] ar = new long[n];
        for(int i=0;i<n; ++i)
        {
            ar[i] = long.Parse(str[i]);
        }
        Console.WriteLine("{0} {1} {2}", ar.Min(), ar.Max(), ar.Sum());
    }
}


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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define all(x) x.begin(), x.end()
using pii = pair<int, int>;
map<string, vector<string>> mp;
set<string> done;
void dfs(string &s, set<string> &st) {
    // cerr << s << endl;
    if (done.count(s)) return;
    done.insert(s);
    if (!mp.count(s)) {
        // cout << s << endl;
        st.insert(s);
    } else {
        REP(i, mp[s].size()) {
            // cerr << mp[s][i] << endl;
            dfs(mp[s][i], st);
        }
    }
}

bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;
    // set<string> st1, st2;
    mp.clear();
    done.clear();
    string g1;
    REP(i, N) {
        string S;
        cin >> S;
        int idx = find(all(S), ':') - S.begin();
        string s = S.substr(0, idx);
        if (i == 0) {
            g1 = s;
        }
        // st1.insert(s);
        // st2.insert(s);
        /// cerr << "s:" << s << endl;
        string tmp = "";
        FOR(j, idx + 1, S.size()) {
            if (S[j] == ',' || S[j] == '.') {
                // cerr << "t:" << tmp << endl;
                // st2.insert(tmp);

                mp[s].push_back(tmp);
                tmp = "";
            } else {
                tmp += S[j];
            }
        }
    }
    int cnt = 0;
    set<string> st;
    dfs(g1, st);
    cout << st.size() << endl;
    return true;
}

signed main() {
    while (solve())
        ;
}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int n, m, q;
vector<int> a(50), b(50), c(50), d(50);

void dfs(vector<int> &v, int &ans) {
	if( v.size() == n ) {
		int score = 0;
		
		for(int i = 0; i < q; ++i) {
			if( v[b[i]] - v[a[i]] == c[i] ) {
				score += d[i];
			}
		}
		
		ans = max(ans, score);
		return;
	}
	
	for(int i = v.back(); i <= m; ++i) {
		v.push_back(i);
		dfs(v, ans);
		v.pop_back();
	}
}

int main(void) {
	cin >> n >> m >> q;
	
	for(int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	
	int ans = -1;
	vector<int> v = {1};
	dfs(v, ans);
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3668
// $%U%$ $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const ll mod = 1000000007;

const int MN = 2000006;

pair<ll,ll> diofante(ll a, ll b){
	if(!a)return {0,1};
	auto t = diofante(b%a,a);
	return {t.second-(b/a)*t.first,t.first};
}
ll modinv(ll x){
	return (diofante(x,mod).first+mod)%mod;
}

ll fact[MN];

ll f(ll r, ll c){
	return fact[r+c]*modinv(fact[r]*fact[c]%mod)%mod;
}

ll ss(ll r, ll c){
	ll res=0;
	for(ll x=1; x<=r+1; ++x)res=(res+f(x,c))%mod;
	return res;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	fact[0]=1;
	for(ll i=1; i<MN; ++i){
		fact[i]=fact[i-1]*i%mod;
	}
	ll r1,c1,r2,c2;
	cin>>r1>>c1>>r2>>c2;
	cout<< (ss(r2,c2)-ss(r2,c1-1)-ss(r1-1,c2)+ss(r1-1,c1-1)+mod+mod)%mod <<endl;
	return 0;
}



Measured memory_bytes: 15872
///*
#include<iostream>
using namespace std;

int main() {

	int x, a, b;
	cin >> x >> a >> b;

	if (b - a<=0) {
		cout << "delicious";
	}
	else if (x >= b - a) {
		cout << "safe";
	}
	else {
		cout << "dangerous";
	}

	return 0;
}

//*/

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
using lli = long long int;

constexpr lli inf = 1e12;
std::vector<lli> X, Y;


int main(void){
    int H, W; scanf("%d%d", &H, &W);
    X.resize(H); REP(i, H) scanf("%lld", &X[i]);
    Y.resize(W); REP(i, W) scanf("%lld", &Y[i]);

    std::sort(X.begin(), X.end());
    std::sort(Y.begin(), Y.end());
    X.push_back(inf); Y.push_back(inf);
    int x = 0, y = 0; lli res = 0;
    while(x < H or y < W){
        lli p = X[x], q = Y[y];
        if(p < q){res += p * (W + 1 - y);x++;}
        else     {res += q * (H + 1 - x);y++;}
    }
    printf("%lld\n", res);
    return 0;
}

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

string s;
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    int sum = 0;
    for (char x : s) {
        sum += x - '0';
    }
    if (sum % 9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

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

bool next(vector<ll>& v) {
    for (ll i = v.size() - 1; i >= 0; i--) {
        if (v[i] != 3) {
            v[i]++;
            for (ll j = i + 1; j < v.size(); j++) {
                v[j] = 0;
            }
            return true;
        }
    }
    return false;
}

int main() {
    ll N, A, B, C;
    cin >> N >> A >> B >> C;

    vector<ll> l(N);
    for (ll i = 0; i < N; i++) {
        cin >> l[i];
    }

    ll ans = LLONG_MAX;
    vector<ll> use(N, 0);
    do {
        vector<ll> len(4, 0);
        ll tmp = 0;
        for (ll i = 0; i < N; i++) {
            if (use[i] > 0 && len[use[i]]) {
                tmp += 10;
            }
            len[use[i]] += l[i];
        }

        bool empty = false;
        for (ll i = 1; i <= 3; i++) {
            if (len[i] == 0) {
                empty = true;
            }
        }
        if (empty) {
            continue;
        }

        tmp += abs(A - len[1]) + abs(B - len[2]) + abs(C - len[3]);
        ans = min(ans, tmp);
    } while (next(use));

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace algorithm
{
	class Program
	{
		public static void Main()
		{
			int[] q = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			int[] work = new int[q[0]];
			int[] q2 = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
			int ans = 0;
			List<int> tmp = new List<int>();
			int start = -1;
			int min = 100;
			while (true)
			{
				if (work.Sum() == q2.Sum()) break;
				//全ての配列に処理を行う
				for (int i = 0; i < work.Length; i++)
				{
					if (q2[i] == work[i])
					{
						if (start != -1)
						{
							//既定範囲に加算処理
							for (int j = start; j < i; j++)
							{
								work[j] += 1;
							}
							ans++;
							//初期化
							start = -1;
						}
						
					}
					else
					{
						//開始位置
						if (start == -1 ) start = i;
					}
				}
				//全探索
				if (start != -1)
				{
					for (int i = start; i < work.Length; i++)
					{
						work[i]++;
					}
					ans++;
					start = -1;
				}
			}

			Console.WriteLine(ans);




		}
	}

}




Measured memory_bytes: 13268
import math
import bisect

N, H = map(int, input().split())

alist = []
blist = []

for n in range(N):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)

a_max = max(alist)

b_th_list = []
for b in blist:
    if b > a_max:
        b_th_list.append(b)

num_th = len(b_th_list)
H_res = H - sum(b_th_list)

if H_res <= 0:
    b_th_list.sort(reverse=True)
    sum_d = 0
    ans = 0
    for b in b_th_list:
        ans += 1
        sum_d += b
        if sum_d >= H:
            break
    print(ans)

else:
    num_cut = math.ceil(H_res/a_max)
    print(num_cut + num_th)


Measured memory_bytes: 18052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
long long int fifth(long long int in);


int main(){
	
	long long int x;
	cin >> x;

	for(long long int i=-128;i<=128;i++){
		for(long long int j=-128;j<=128;j++){
			if(fifth(i)-fifth(j) == x){
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}



	return 0;
}

long long int fifth(long long int in){
	return in * in * in * in * in;
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

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

    if(x<=3){
        cout<<x<<endl;
    }else {
        int jd = 0;
        for (int i = x;; i++) {
            for (int j = 2; j * j < i; j++) {
                if (i % j == 0) {
                    break;
                }
                if (i % j != 0 && (j + 1) * (j + 1) >= i) {
                    jd = 1;
                    break;
                }
            }
            if (jd == 1) {
                cout << i << endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n+1];
        
        for(int i = 1; i <= n; i++) h[i] = sc.nextInt();
        
        int[] dp = new int[n+1];
        
        Arrays.fill(dp, Integer.MAX_VALUE);
        
        dp[1] = 0;
        
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= k; j++){
                if(i+j == n+1) break;
                
                dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j]));
            }
        }
        
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 51124
#include<stdio.h>
main(){
  int i,j,n,no;
  double kg,m,temp;
  while(scanf("%d,%lf,%lf",&no,&kg,&m)!=EOF){
    temp=kg/(m*m);
    if(temp>=25){
      printf("%d\n",no);
    }
  }
  return 0;
}

Measured memory_bytes: 0
a=input()
b=input()
c=input()
player='a'
while True:
    if player=='a':
        if a=="":
            print('A')
            break
        else:
            player=a[0]
            a=a[1:]
    elif player=='b':
        if b=="":
            print('B')
            break
        else:
            player=b[0]
            b=b[1:]
    else:
        if c=="":
            print('C')
            break
        else:
            player=c[0]
            c=c[1:]


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

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

	int ret = 0;
	for (int i = a; i <= b; ++i) {
		string s = to_string(i);
		string t = s;
		reverse(s.begin(), s.end());
		if (s == t) {
			++ret;
		}
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
print((lambda a:min([min([float("inf")if a[1]<=1 else(lambda b:b[2]-b[0])(sorted([i*a[0],(a[1]-i)*(a[0]//2),(a[1]-i)*(a[0]//2+(a[0]%2))]))for i in range(1, a[1])])]+[min([float("inf")if a[0]<=1 else(lambda b:b[2]-b[0])(sorted([i*a[1],(a[0]-i)*(a[1]//2),(a[0]-i)*(a[1]//2+(a[1]%2))]))for i in range(1, a[0])])]+[a[1]if a[0]%3 else 0]+[a[0]if a[1]%3 else 0]))(list(map(int,input().split()))))

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define per(i,s,n) for(int i=n-1;i>=s;i--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int n;
  cin>>n;
  Ans(n>=30);
}

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

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

#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define ferrari ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool simulate(ll n, ll k)
{
	if (k == 1) return false;
	while (n >= k) {
		if (n % k == 0) n /= k;
		else n %= k;
	}
	return n == 1;
}

ll n, ans;

int main()
{
	cin >> n;
	for (ll i =  1; i * i <= n - 1; i++)
		if ((n - 1) % i == 0) {
			ans += 2;
			if (i * i == (n - 1)) ans--;
		}
	ans--;
	for (ll i = 1; i * i <= n; i++) 
		if (n % i == 0) {
			ll p = n / i;
			if (simulate(n, i)) ans++;
			if (p != i && simulate(n, p)) ans++;
		}
	cout << ans;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut n: u64 = sc.read::<u64>();

    let mut digit = 0;
    let mut t = n;
    loop {
        digit += 1;
        let num = 26_u64.pow(digit);
        if t <= num {
            break;
        }
        t -= num;
    }
    t -= 1;
    let mut ans = vec![0; digit as usize];
    for i in (0..digit).rev() {
        ans[i as usize] = t % 26;
        t = t / 26;
    }
    let ans = ans
        .into_iter()
        .map(|u| ('a' as u8 + u as u8) as char)
        .collect::<String>();
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2280
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	int ret = 1;
	cin >> n;
	while (2 * ret <= n) ret *= 2;
	cout << ret << endl;
	return 0;
}

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

ll count(ll i){
  if(i==0) return 0;
  return count(i>>1)+(1&i?1:0);
}

void c(){
    ll n;
    cin >> n;
    auto a = vector<ll>(n,0);
    auto x = vector<v>(n,v(n,0));
  	auto y = vector<v>(n,v(n,0));
  	
    rep(i,n) {
        cin >> a[i];
        rep(j,a[i]) {
          cin >> x[i][j] >> y[i][j];
          x[i][j]--;
        }
     
    }
    
    ll ans =0;
    rep(i,1<<n){
        bool ok=true;
        rep(j,n){
          if(!(1&(i>>j))) {
			continue;
          }
          rep(k,a[j])
          	if((1&(i>>x[j][k]))^y[j][k]) ok=false; 
        }
        if(ok) ans = max(ans,count(i));
    }
    cout << ans;
}

int main(){
    c();
}

Measured memory_bytes: 256
n, m = map(int,input().split())
mod = 10**9 +7
def solve(num):
    result = 1
    for i in range(1, num+1):
        result = (result*i)%mod
    return result
if n==m:
    print((solve(n)*solve(m)*2)%mod)
elif abs(n-m) == 1:
    print((solve(n)*solve(m))%mod)
else:
    print(0)

Measured memory_bytes: 3064
#include <stdio.h>

int isprime(long int* n){
  long int i;
  for(i=2; i*i<=*n; i++)
    if(*n%i==0)
      return 0;
  return 1;
}

int main(){
  long int n;
  int i, num = 0, jum;
  scanf("%d",&jum);
  for(i=0; i<jum; i++){
    scanf("%ld",&n);
    if(isprime(&n))
      num++;
  }
  printf("%d\n",num);
  return 0;
}

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

int main(){
	int N,a1=0,a2=0,a4=0,b;
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>b;
		if(b%4==0)a4++;
		else if(b%2==0)a2++;
		else a1++;
	}
	if(a1<=a4||(a1==a4+1&&a2==0)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256