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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----


#define UQ(v) (v.erase(unique(ALL(v)), v.end()) - v.begin())

LL n, k, x[50], y[50], p[50][50], s[51][51];
vector<LL> vx, vy;
map<LL, LL> mx, my;

int main() {
	cin >> n >> k;
	inc(i, n) { cin >> x[i] >> y[i]; }
	
	inc(i, n) {
		vx.PB(x[i]);
		vy.PB(y[i]);
	}
	
	sort(ALL(vx));
	sort(ALL(vy));
	int xx = UQ(vx);
	int yy = UQ(vy);
	inc(i, xx) { mx[vx[i]] = i; }
	inc(i, yy) { my[vy[i]] = i; }
	
	inc(i, n) { p[mx[x[i]]][my[y[i]]]++; }
	
	inc(i, xx) {
	inc(j, yy) {
		s[i + 1][j + 1] = p[i][j];
	}
	}
	inc1(i, xx) {
	inc1(j, yy) {
		s[i][j] += s[i - 1][j];
	}
	}
	inc1(i, xx) {
	inc1(j, yy) {
		s[i][j] += s[i][j - 1];
	}
	}
	
	
	LL ans = 4e18;
	inc(xh, xx) {
	inc(xl, xh) {
	inc(yh, yy) {
	inc(yl, yh) {
		#define R(xl, xh, yl, yh) (s[xh][yh] - s[xh][yl] - s[xl][yh] + s[xl][yl])
		int c = R(xl, xh + 1, yl, yh + 1);
		LL v = (vx[xh] - vx[xl]) * (vy[yh] - vy[yl]);
		if(c >= k) { setmin(ans, v); }
	}
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

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

    int cnt = 0;
    int sum = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                sum += (500 * i + 100 * j + 50 * k);
                if(sum == x){
                    cnt++;
                }
                sum = 0;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int A, B, C;
   scanf("%d", &A);
   scanf("%d", &B);
   scanf("%d", &C);
  if (A==B&&A==C&&B==C){
     printf("No\n");
  }
  else if (A!=B&&A!=C&&B!=C) {
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 1656
n = int(input())
x_s = input()
x = int(x_s, 2)

pops = bin(x).count("1")
x_pop_p = x%(pops + 1)
try:
    x_pop_m = x%(pops - 1)
except:
    x_pop_m = 0
for i in range(0,n):
    if x_s[i] == '1':
        if pops > 1:
            tmp = (x_pop_m - pow(2,n-1-i,(pops - 1)))%(pops - 1)
        else:
            print(0)
            continue
    else:
        tmp = (x_pop_p + pow(2,n-1-i,(pops + 1))) % (pops + 1)
    cnt = 1
    while tmp:
        tmp %= bin(tmp).count("1")
        cnt += 1
    print(cnt)

Measured memory_bytes: 9504
"use strict"
function main(arg) {
    let data = arg.trim().split("\n")[0].split("")
    for (let i = 0; i < data.length; i++) {
        if (data[i] !== '?') continue
        if (data[i] === '?') {
            data[i] = 'D'
        }
        if (data[i] === '?') {
            data[i] = 'D'
        }
    }
    data = data.join("")
    // let pd = data.split("PD").length - 1
    // let d = data.split("D").length - 1
    // console.log(pd + d)
    console.log(data)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 41632
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	string S;
	cin >> S;
	if(S[0]=='S') {
		cout << "Cloudy" << endl;
	} else if(S[0]=='C') {
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define un unsigned
using namespace std;
int main()
{
    ll n,cnt=0,i,j,k;
    cin>>n;
    k=(n/2)+1;
    //cnt=n-1;
    for(i=1;i<=n;i++)
    {
        for(j=1;i*j<n;j++)
        {
            if(i*j<n){
            cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int main(){
    ll h,w,k;cin>>h>>w>>k;
    vector<vector<bool> >a(h,vector<bool>(w));
    ll sx,sy;
    rep(i,h){
        rep(j,w){
            char c;cin>>c;
            if(c=='#');
            else if(c=='S'){
                a[i][j]=1;
                sx=i;sy=j;
            }
            else a[i][j]=1;
        }
    }
    vector<vector<int> >depth(h,vector<int>(w,inf));
    depth[sx][sy]=0;
    vector<vector<bool> >visited(h,vector<bool>(w));
    queue<pii>q;
    q.push(mp(sx,sy));
    while(!q.empty()){
        pii n=q.front();
        q.pop();
        int x=n.first,y=n.second;
        visited[x][y]=1;
        rep(i,4){
            int nx=x+dx[i],ny=y+dy[i];
            if(nx>=0&&nx<h&&ny>=0&&ny<w){
                if(visited[nx][ny]==0&&a[nx][ny]){
                    q.push(mp(nx,ny));
                    visited[nx][ny] = 1;
                    depth[nx][ny]=depth[x][y]+1;
                }
            }
        }
    }
    ll mi=max(h,w);
    rep(i,h){
        rep(j,w){
            if(depth[i][j]<=k){
                mi=min(mi,i*1LL);
                mi=min(mi,(h-1-i)*1LL);
                mi=min(mi,j*1LL);
                mi=min(mi,(w-1-j)*1LL);
            }
        }
    }
    ll ans=1;
    if(mi==0);
    else ans+=(mi-1)/k+1;
    cout<<ans<<endl;
}


Measured memory_bytes: 3072
N, K = map(int, input().split())
a_b_list_list = []
for i in range(N):
    a_b_list_list.append(list(map(int, input().split())))
a_b_list_list.sort()

counter = 0
answer = None
for a_b_list in a_b_list_list:
    counter += a_b_list[1]
    if counter >= K:
        answer = a_b_list[0]
        break

print(answer)



Measured memory_bytes: 27872
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())
p = list(map(int, input().split()))

p_ori = p[:]

p.sort()
p_sorted = p[:]

if p_ori == p_sorted:
    print("YES")
else:
    p_ori = np.array(p_ori)
    p_sorted = np.array(p_sorted)
    p_diff = p_ori - p_sorted

    if(sum(p_diff != 0) == 2):
        if p_diff.sum() == 0:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

Measured memory_bytes: 14160
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, k;

signed main() {
	cin >> a >> b >> k;
	cout << max((int)0, a - k) << " " << max((int)0, b - (max((int)0, k - a))) << endl;
}


Measured memory_bytes: 256
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)



itn main() {
	std::ios::sync_with_stdio(false);

	int a, b, c;

	cin >> a >> b >> c;

	if (a == b && a != c ||
		a == c && a != b ||
		b == c && a != b) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define chmin(x,y) x = min(x, y)
#define chmax(x,y) x = max(x, y)
#define V vector
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    string s; cin >> s;
    int ans;
    if (s == "SSS") ans = 0;
    else if (s == "SSR" || s == "SRS" || s == "RSS" || s == "RSR") ans = 1;
    else if (s == "SRR" || s == "RRS") ans = 2;
    else if (s == "RRR") ans = 3;

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

Measured memory_bytes: 3592
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

int n,a[200005],ans[200005];
vi adj[200005];
multiset<int> st;

void dfs(int cur,int par){
    
    st.insert(a[cur]);
    auto it=st.lower_bound(a[cur]);
    int del=0;
    if(++it!=st.end()){
        del=*it;
        st.erase(st.find(del));
    }
    
    
    ans[cur]=st.size();
    
    for(int ch:adj[cur]){
        if(ch==par)continue;
        dfs(ch,cur);
    }
    
    if(del)st.insert(del);
    st.erase(st.find(a[cur]));

}

signed main(){
    FASTER;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 31976
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
vector<complex<double>> fft(vector<complex<double>> a,bool inverse = false){
  int n = a.size();
  int h = 0;
  for(int i=0;(1<<i)<n;++i) ++h;

  rep(i,n){
    int j =0;
    rep(k,h) j |= (i>>k&1) << (h-1-k);
    if(i<j) swap(a[i],a[j]);
  }

  for(int b=1;b<n;b*=2){
    rep(j,b){
      complex<double> w = polar(1.0,(inverse?-1:1)*(2*M_PI)/(2*b)*j);
      for(int k=0;k<n;k+=b*2){
	complex<double> s = a[j+k];
	complex<double> t = a[j+k+b]*w;
	a[j+k] = s+t;
	a[j+k+b] = s-t;
      }
    }
  }
  if(inverse) rep(i,n) a[i] /= n;
    
  return a;
}

vector<complex<double>> fft(vector<double> a,bool inverse = false){
  vector<complex<double>> a_complex(a.size());
  rep(i,a.size()) a_complex[i] = complex<double>(a[i],0);
  return fft(a_complex,inverse);
}

vector<double> convolve(vector<double> a,vector<double> b){
  int s = a.size() + b.size() - 1;
  int t = 1;
  while(t<s) t*=2;
  a.resize(t);
  b.resize(t);
  vector<complex<double>> A = fft(a);
  vector<complex<double>> B = fft(b);
  rep(i,t){
    A[i] *= B[i];
  }
  A = fft(A,true);
  a.resize(s);
  rep(i,s) a[i] = A[i].real();
  return a;
}


int main()
{
  int n;
  cin >> n;
  ll m;
  cin >> m;
  vector<ll> a(n);
  ll mm=0;
  rep(i,n){
    cin >> a[i];
    mm = max(mm,a[i]);
  }

  vector<double> x(mm+1,0);
  rep(i,n) x[a[i]]++;

  vector<double> y = convolve(x,x);
  vector<ll> z;
  rep(i,y.size()){
    z.push_back((ll)(y[i]+0.5));
  }


  
  ll sum=0;
  ll res=0;
  for(ll i=(ll)z.size()-1;i>=0;--i){
    sum+=z[i];
    if(sum>=m){
      res+=(z[i]-(sum-m))*i;
      break;
    }
    res+=z[i]*i;
  }

  cout << res << "\n";
    
  


  
  
  return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n ; cin >> n ;

    string s ; cin >> s ;
    for ( auto c : s )
    {
        int a = c - 'A' ;
        a += n ;

        if ( a > 25 )
            a -= 26 ;

        a += 65 ;
        char p = a ;

        cout << p ;
    }
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]

use proconio::{fastout, input};
use std::cmp::{max, min};

const INF: i32 = 1001001001;
const LNF: i64 = 1001001001001001001;
const MOD: u32 = 1000000007;

#[fastout]
fn main() {
  input! {
    n: usize,
    m: usize,
  }
  let mc = ModCalc::new(500000);
  let all = (mc.facc[m] * mc.finv[m - n]).pow(2);
  let mut acc = ModInt(0);
  for i in 1..=n {
    let a = mc.facc[m] * mc.finv[m - i];
    let b = (mc.facc[m - i] * mc.finv[m - n]).pow(2);
    if i % 2 == 1 {
      acc = acc + mc.com(n, i) * a * b;
    } else {
      acc = acc - mc.com(n, i) * a * b;
    }
  }
  let ans = all - acc;
  println!("{}", ans);
}

trait Powerable: std::ops::Mul<Output = Self> + Copy {
  fn one() -> Self;
  fn pow(self, mut n: u64) -> Self {
    let mut r = Self::one();
    let mut x = self;
    while n > 0 { if n & 1 == 1 { r = r * x; } x = x * x; n >>= 1; }
    r
  }
}

#[derive(Clone, Copy)]
struct ModInt(u32);

impl Powerable for ModInt {
  fn one() -> Self { Self(1) }
}

impl std::fmt::Display for ModInt {
  fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
    write!(f, "{}", self.0)
  }
}

impl std::ops::Add for ModInt {
  type Output = Self;
  fn add(self, rhs: Self) -> Self {
    Self((self.0 + rhs.0) % MOD)
  }
}

impl std::ops::Sub for ModInt {
  type Output = Self;
  fn sub(self, rhs: Self) -> Self {
    Self((self.0 + MOD - rhs.0) % MOD)
  }
}

impl std::ops::Mul for ModInt {
  type Output = Self;
  fn mul(self, rhs: Self) -> Self {
    let x = self.0 as u64 * rhs.0 as u64;
    Self((x % MOD as u64) as u32)
  }
}

impl std::ops::Div for ModInt {
  type Output = Self;
  fn div(self, rhs: Self) -> Self {
    self * rhs.inv()
  }
}

impl ModInt {
  fn new(x: u32) -> Self {
    Self(x % MOD)
  }
  fn inv(self) -> Self {
    self.pow((MOD - 2) as u64)
  }
}

struct ModCalc {
  facc: Vec<ModInt>,
  finv: Vec<ModInt>,
}

impl ModCalc {
  fn new(n: usize) -> Self {
    let mut facc = vec![ModInt(0); n + 1];
    let mut finv = vec![ModInt(0); n + 1];
    facc[0] = ModInt(1);
    for i in 0..n {
      facc[i + 1] = facc[i] * ModInt((i + 1) as u32);
    }
    finv[n] = ModInt(1) / facc[n];
    for i in (0..n).rev() {
      finv[i] = finv[i + 1] * ModInt((i + 1) as u32);
    }
    ModCalc { facc, finv }
  }
  fn com(&self, a: usize, b: usize) -> ModInt {
    if b > a {
      return ModInt(0);
    }
    self.facc[a] * self.finv[a - b] * self.finv[b]
  }
}

Measured memory_bytes: 5968
//Link : https://atcoder.jp/contests/arc093/tasks/arc093_c

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1005
#define EDGE 2000
#define mod 1000000007

int add(int x,int y) {
  int ret = ((x+y)%mod + mod)%mod;
  return ret;
}
int mul(int x,int y) {
  return (ll)x*y%mod;
}

vector<int> adj[N];

pair<int,pair<int,int> >edge[EDGE];

ll minSt[EDGE];
int dsu[N];
int f(int x) {
  if(dsu[x]==x) {
    return x;
  }
  return dsu[x] = f(dsu[x]);
}
bool merge(int a,int b) {
  a = f(a),b = f(b);
  if(a!=b) {
    dsu[a] = b;
    return true;
  }
  return false;
}

void solve() {
  int n,m;scanf("%d %d  ", &n,&m);
  ll x;scanf("%lld ", &x);
  for(int i=0;i<m;++i) {
    scanf("%d %d %d", &edge[i].second.first,&edge[i].second.second,
    &edge[i].first);
  }
  sort(edge,edge+m);
  ll minSum = 1e18;
  for(int i=0;i<m;++i) {
    for(int j=1;j<=n;++j) {
      dsu[j] = j;
    }
    ll r = edge[i].first;
    merge(edge[i].second.first,edge[i].second.second);
    for(int j=0;j<m;++j) {
      if(merge(edge[j].second.first,edge[j].second.second)) {
        r += edge[j].first;
      }
    }
    minSt[i] = r;
    minSum = min(minSum,r);
  }
  if(x<minSum) {
    printf("0\n");
  } else if(x==minSum) {
    int r = 1;
    for(int i=0;i<m;++i) {
      if(minSt[i]==x) {
        r = mul(r,2);
      }
    }
    r = add(r,-2);
    for(int i=0;i<m;++i) {
      if(minSt[i]!=x) {
        r = mul(r,2);
      }
    }
    printf("%d\n", r);
  } else {
    bool isThereGoodTree = false;
    for(int i=0;i<m;++i) {
      if(minSt[i]==x) {
        isThereGoodTree = true;
        break;
      }
    }
    if(isThereGoodTree) {
      int small = 0, equal = 0,big = 0;
      for(int j=0;j<m;++j) {
        if(minSt[j]<x) {
          ++small;
        } else if(minSt[j]==x) {
          ++equal;
        } else {
          ++big;
        }
      }
      int ret = 0;
      int r = 1;
      for(int i=0;i<equal;++i) {
        r = mul(r,2);
      }
      r = add(r,-2);
      ret = add(ret, mul(r,2));
      ret = add(ret, 2);
      for(int i=0;i<big;++i) {
        ret = mul(ret,2);
      }
      printf("%d\n", ret);
    } else {
      printf("0\n");
    }
  }
  //Opt sol ? O(nlgn) ?
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 256
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables)]

use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;

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

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let mut s: String = read();
    if s.contains('A') && s.contains('B') {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
n = int(input())
S = list(map(int,input().split()))
p = int(input())
T = list(map(int,input().split()))
count = 0
time = 0
import math
for i in T:
    left = 0
    right = n
    while right - left > 5:
        mid = math.floor((right + left)/2)
        #print(mid,S[mid])
        if i > S[mid-1]:
            left = mid
        else:
            right = mid
    for j in range(left,right):
        if i == S[j]:
            count += 1
            break        

        
print(count)


Measured memory_bytes: 16708
N = int(input())
data = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[2])

lx, ly, lh = data[-1]

for cy in range(101):
    for cx in range(101):
        H = lh + abs(cx - lx) + abs(cy - ly)

        if all(h == max(H - abs(cx - x) - abs(cy - y), 0) for x, y, h in data):
            print(cx, cy, H)
            exit()

Measured memory_bytes: 3064
while True:
    a, b, c = map(str, input().split())
    a = int(a)
    c = int(c)
    if b == "/":
        print(a // c)
    elif b == "+":
        print(a + c)
    elif b == "-":
        print(a - c)
    elif b == "*":
        print(a * c)
    else:
        break


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(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 main() {
    ll n, a;
    cin >> n;
    vector<P> p;
    rep1(i, n){
        cin >> a;
        P pnow;
        pnow.first = a;
        pnow.second = i;
        p.push_back(pnow);
    }
    sort(p.begin(), p.end());
    rep1(i,n){
        if (i==n-1) cout << p[i].second + 1 << endl;
        else cout << p[i].second + 1 << " ";
    }
}

Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	ll i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
		ll l, a, b, n, pc, c,r, k = 1, t, ans,cn;
		cin >> l >> a >> b >> M;
		pc = 1;
		vector<vector<ll>> x{ {1,0,0},{0,1,0},{0,0,1} };
		k = 1;
		c = a+b;
		while (pc < l) {
			n =min((k - c + b - 1) / b, l - pc);
          if(n<0)n=0;
			cn = n;
			vector<vector<ll>> cz{ {k%M,b%M,(a%M + b%M) % M},{0,1,1},{0,0,1} };
			while (cn > 0) {
				if (cn % 2 == 1)
					x = mul(cz, x,3);
				cz = mul(cz, cz, 3);
				cn /= 2;
			}
			pc += n;
			c += b * n;
			k *= 10;
		}
		ans = (a%M*x[0][0]%M + x[0][2]) % M;
		cout << ans << endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int X = GetInt() - 1;
		int Y = GetInt() - 1;
		
		var cnt = new int[N - 1];
		for(int i = 0; i < N - 1; i++)
		{
			for(int j = i + 1; j < N; j++)
			{
				int len = Min(Abs(j - i), 1 + Min(Abs(X - i) + Abs(Y - j), Abs(X - j) + Abs(Y - i)));
				cnt[len - 1]++;
			}
		}
		WriteLine(string.Join("\n", cnt));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13268
object Main extends App {
  def isHarshadNumber(x:Int) = {
    val s = x.toString
    var sum = 0
    for (c <- s) sum += c.asDigit
    x % sum == 0
  }
  
  val n = readInt
  println(if (isHarshadNumber(n)) "Yes" else "No")
}

Measured memory_bytes: 27204
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,d;
int main()
{
	scanf("%d %d",&n,&d);
	int flag=0;
	if(n%(2*d+1))
		flag=1;
	printf("%d",n/(2*d+1)+flag);
	return 0; 
}

Measured memory_bytes: 128
// abc111_d

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

typedef long long ll;
#define debug(x) cout << #x << ": " << (x) << endl
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define INF ((1 << 16)-1)
#define MOD (1000000007)
#define print(arr, n) REP(i, n) cout << arr[i] << " ";


int main() {
//    std::ifstream in("../arg.txt");
//    std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N;

    int X[1024], Y[1024];

    REP(i, N) {
        cin >> X[i] >> Y[i];
    }

    REPN(i, 1, N){
        if ( (abs(X[i]) + abs(Y[i])) % 2 != (abs(X[0]) + abs(Y[0])) % 2 ) {
            cout << -1 << endl;
            return 0;
        }
    }

    int m = 31;
    vector<ll> d;
    REP_REV(i, m) d.push_back(1ll << i);
    if ((X[0] + Y[0]) % 2 == 0) {
        d.push_back(1);
        m += 1;
    }

    cout << m << endl;
    print(d, d.size());
    puts("");

    REP(j, N) {
        ll x = X[j], y = Y[j];
        string s = "";

        REP(i, d.size()) {
            if (abs(x) > abs(y)) {
                if (x > 0) {s += "R"; x -= d[i];}
                else {s += "L"; x += d[i];}
            }
            else {
                if (y > 0){ s += "U"; y -= d[i];}
                else { s += "D";y += d[i]; }
            }
        }
        cout << s << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  bool yes = 1;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3==0||a[i]%5==0) continue;
        yes=0;
        break;
    }
  }
  if(yes) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    int s=0;
    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        s+=a;
    }
    if(n<s) cout << "-1" << "\n";
    else cout << n-s << "\n";

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

int main()
{
	unsigned long N;
	std::cin >> N;

	if ( N & 1 )
	{
		// Nが奇数なら2倍する
		std::cout << N * 2 << std::endl;
	}
	else
	{
		// Nが偶数なら、それで確定
		std::cout << N << std::endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
import sys
H,W = map(int,input().split())

table = [[0]*(W+1) for i in range(H+1)]

for row in range(H):
    a = list(map(int,input().split()))
    for col in range(W):
        table[row][col]= a[col]
        
for row in range(H):
    for col in range(0,W):
        table[row][W] += table[row][col]

for col in range(0,W+1):
    for row in range(0,H):
        table[H][col] += table[row][col]
        
for row in range(0,H+1):
    print("%d"%(table[row][0]),end="")
    for col in range(1,W+1):
        print(" %d"%(table[row][col]),end = "")
    print()


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

int main(){
    int a,b,c,n;
    cin >> a >> b >> c;
    
    if(a > b){
        n=a; a=b; b=n; 
    }if(b > c){
        n=c; c=b; b=n;
    }if(a > b){
        n=b; b=a; a=n;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}
    


Measured memory_bytes: 3080
fun main(args: Array<String>) {
    val (N, T) = readInputLine().split(" ").map { it.toInt() }
    val tList = readInputLine().split(" ").map { it.toInt() }
    
    var ans = 0
    var endTime = 0
    
    for (t in tList) {
        if (t >= endTime) {
            ans += T
        } else {
            ans += t + T - endTime
        }
        endTime = t + T
    } 

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;

vector<int> g[100100];
int dp[100100];

int dfs(int v){
    if(dp[v])return dp[v];
    dp[v] = 1;
    for(int i : g[v]){
        dfs(i);
        dp[v] = max(dp[i] + 1, dp[v]);
    }
}

void solve(){
    int n, m;
    int x, y;
    
    cin >> n >> m;
    
    for(int i = 1;i <= m;++i){
        cin >> x >> y;
        g[x].push_back(y);
    }
    
    int mn = 0;
    
    for(int i = 1;i <= n;++i){
        if(dp[i] == 0){
            dfs(i);
        }
        
        mn = max(dp[i], mn);
    }
    
    cout << mn - 1;
}

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

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define PB push_back
#define LL long long
#define M          1000000007
#define MAX 100010


vector<int> mat[MAX], go[MAX];
LL dp[MAX][2];
int u, v, n;

void dfs(int p,int pa)
{
    for(auto x : mat[p])
    {
        if(x == pa) continue;
        go[p].PB( x );
        dfs(x, p);
    }
}

LL rec(int p,int t)
{
    if(!go[p].size()) return t ? 1 : 2;

    LL &re = dp[p][t], te;
    if(re != -1) return re;

    re = 1; te = 1;
    for(auto x : go[p])
    {
        re *= rec(x, 0);
        re %= M;
    }

    if(!t)
    {
        for(auto x : go[p])
        {
            te *= rec(x, 1);
            te %= M;
        }
        re += te;
        re %= M;
    }

    return re;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> n;
    FOR(i,1,n-1)
    {
        cin >> u >> v;
        mat[u].PB( v ); mat[v].PB( u );
    }
    dfs(1, 1);
    mem(dp, -1);
    cout << rec(1, 0) << endl;
    return 0;
}




Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,poi=0,count=0;
  cin >>N>>X;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin>>L.at(i);
  }
  for(int i=0;i<N;i++){
    poi+=L.at(i);
    if(poi<=X){
      count++;
    }
    else{
      break;
    }
  }
  count++;
  cout<<count<<endl;
}

Measured memory_bytes: 256
getter = -> {
  require "stringio"
  _in = StringIO.new
  while l = gets
    _in << l
  end
  _in.string
}
_in = getter.call
a = _in.strip.split(/\R/)[1].strip.split(" ").map(&:to_i)
rtn = -> {
  break rtn = 0 if a.include?(0)
  break rtn = -1 if a.include?(1000000000000000000)
  break rtn = -1 if a.count { |e| e >= 1000000000 } > 2
  break nil
}.call

if rtn
  puts rtn
else
  puts "#{a.inject { |r, n| r *= n; if r > 1000000000000000000 then break -1; end; r }}"
end


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL (vec)(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define eb emplace_back
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (ll)(a.size())
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define cont const auto
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
#define PQ priority_queue
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,a;
  cin>>n>>a;
  VL x(n);
  rep(i,n)cin>>x[i];

  ll dp[n+5][n+5][n*55];
  rep(i,n+5)rep(j,n+5)rep(k,n*55)dp[i][j][k]=0;
  dp[0][0][0]=1;

  rep(i,n){
    rep(j,n){
      rep(k,n*51){
        if(dp[i][j][k]){
          dp[i+1][j][k]+=dp[i][j][k];
          dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        }
      }
    }
  }
  
  ll ans=0;
  reps(i,n)ans+=dp[n][i][i*a];
  out(ans);

  
  return 0;
}



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



int main() {

    int n; cin >> n;
    vector<ll> a(n);
    int ans = 1;
    rep(i,n) cin >> a[i];

    if(n == 1 || n == 2) cout << 1;
    else{
        vector<ll> b;
        rep(i,n-1){
            if(a[i+1]-a[i] > 0) b.push_back(1);
            if(a[i+1]-a[i] < 0) b.push_back(-1);
        }
        rep(i,b.size()-1){
            if(b[i]!= b[i+1]){
                ans ++;
                i ++;
            }
        }
        cout << ans;
    }



    return 0;
}











Measured memory_bytes: 5008
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;
  vll hs(n);
  rep(i, n) cin >> hs[i];

  vll dp(n, INF);
  dp[0] = 0;
  repLRE(i, 1, n - 1) {
    repLRE(j, max(0LL, i - k), i - 1) {
      dp[i] = chmin(dp[i], dp[j] + abs(hs[i] - hs[j]));
    }
  }
  cout << dp.back() << endl;

  return 0;
}


Measured memory_bytes: 4748
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, X, T;
  cin >> N >> X >> T;

  cout << (N+X-1)/X*T << "\n";

  return 0;
}


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

int main()
{
	int n;
	vector<int> A;
	int a;
	int sum=0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin>> a;
		A.push_back(a);
	}
	for (int i = 0; i < A.size(); i++) {
		a = A.at(i);
		if (a == 2)sum++;
		else if (a<2||a % 2 == 0) {}
		else {
			int j=3;
			bool flag =true;
			while (j <= sqrt(a)) {
				if (a%j == 0) {
					flag = false;
				}
				j += 2;
			}
			if (flag == true)sum++;
		}
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1320
n=int(input())
d = [[0] * 10 for i in range(10)]

ans = 0
for i in range(1,n+1):
    s=str(i)
    if s[0]=="0" or s[-1]=="0":
        continue
    else:
        d[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += d[i][j] * d[j][i]

print(ans)

Measured memory_bytes: 3064
import java.io.IOException;
import java.util.NavigableSet;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] num = new int[m];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					int a = scanner.nextInt();
					num[j] += a;
				}
			NavigableSet<Pair> set = new TreeSet<Pair>();
			for (int i = 0; i < m; i++)
				set.add(new Pair(i + 1, num[i]));
			System.out.print(set.pollFirst());
			while (!set.isEmpty())
				System.out.print(" " + set.pollFirst());
			System.out.println();
		}
	}

	class Pair implements Comparable<Pair> {
		int id, point;

		public Pair(int id, int point) {
			super();
			this.id = id;
			this.point = point;
		}

		@Override
		public int compareTo(Pair o) {
			if (o.point == this.point)
				return this.id - o.id;
			return o.point - this.point;
		}

		@Override
		public String toString() {
			return String.valueOf(this.id);
		}

	}
}

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

int main()
{
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];

  int flag = 0, ans = 1;
  for (int i = 1; i < N; ++i) {
    if (flag == 0) {
      if (A[i-1] < A[i]) flag = 1;
      else if (A[i-1] > A[i]) flag = 2;
    } else if (flag == 1) {
      if (A[i-1] > A[i]) {
        flag = 0;
        ans++;
      }
    } else if (flag == 2) {
      if (A[i-1] < A[i]) {
        flag = 0;
        ans++;
      }
    }
  }

  cout << ans << endl;
}

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

const int Maxn = 100010;
int N, M, Num[ Maxn ], Appear[ Maxn ];

int main() {
    scanf( "%d%d", &N, &M );
    for( int i = 1; i <= N; ++i ) Num[ i ] = 1;
    Appear[ 1 ] = 1;
    for( int i = 1; i <= M; ++i ) {
        int x, y;
        scanf( "%d%d", &x, &y );
        if( Appear[ x ] ) Appear[ y ] = 1;
        if( Num[ x ] == 1 ) Appear[ x ] = 0;
        --Num[ x ];
        ++Num[ y ];
    }
    int Ans = 0;
    for( int i = 1; i <= N; ++i ) if( Appear[ i ] ) ++Ans;
    printf( "%d\n", Ans );
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5;
const int maxm=2e5;
ll c[maxn*2+10];
int a[maxn+10];
int lowbit(int x)
{
    return x&(-x);
}
void add(int x,int val)
{
    for(int i=x;i<=maxm;i+=lowbit(i))
    {
        c[i]+=val;
    }
}
ll sum(int x)
{
    ll ret=0;
    for(int i=x;i>0;i-=lowbit(i))
    {
        ret+=c[i];
    }
    return ret;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        int l=0,r=1e9;
        int ans=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            int cc=0;
            ll ret=0;
            for(int i=0;i<=maxm;i++)
                c[i]=0;
            add(n+1,1);
            for(int i=1;i<=n;i++)
            {
                cc+=a[i]>=mid?1:-1;
                ret+=sum(cc+n+1);
                add(cc+n+1,1);
            }
            if(ret >= (ll)n*(n+1)/2 - ret)
            {
                l=mid+1;
                ans=mid;
            }
            else
            {
                r=mid-1;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

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

int main(){
    long long N,K;cin>>N>>K;
    vector<long long> A(N),C(N);
    for (int i = 0; i < N; i++)
    {
        C[i]=0;
        cin>>A[i];
    }
    int S=0,b=0;
    vector<long long> cnt(0),cnt2(0);
    while(true){
        C[S]++;
        if(C[S]==1){
            b++;
        }
        if(C[S]==2)cnt.push_back(S);
        if(C[S]==3)break;
        S=A[S]-1;
        cnt2.push_back(S);
    }
    if(b>=K)cout<<cnt2[K-1]+1<<endl;
    else cout<<cnt[(K-b)%cnt.size()]+1<<endl;
}

Measured memory_bytes: 12796
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using pint = pair<int, int>;

int main() {
  string w;
  cin >> w;
  map<char, int> m;
  rep(i, 0, w.size()) m[w[i]]++;
  for (auto x : m) {
    if (x.second % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long n,a[10000001],ans=0;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=3*n;i++)
   {
        scanf("%lld",&a[i]);
    }
    sort(a+1,a+1+3*n);
    for(int i=(3*n)-1;i>=n+1;i-=2)
   {
        ans+=a[i];
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;
int main(){
	int a, b;
	int ans = 1,abc=0;
	string s[50],x;
	cin >> a;
	vector<int> t(a);
	rep(i, a) {
		cin >> s[i] >> t[i];
	}
	cin >> x;
	for (int j = 0; j < a;j++ ) {
		if (s[j] == x)break;
		ans++;
	}
	for (int l = ans; l < a; l++) {
		abc += t[l];
	}
	cout << abc << endl;
	return 0;
}

Measured memory_bytes: 256