akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}
vector<ll> st;
ll MM,NN;
vector<ll> A,B,C,D;
ll QQ;
ll rec(ll prev){
  ll ret=0;
  if(st.size()==NN){
    REP(QQ){
      if(st[B[i]]-st[A[i]]==C[i]){
        ret+=D[i];
      }
    }
    return ret;
  }
  for (ll i = 0; i+prev <= MM; i++)
  {
    st.push_back(prev+i);
    ret=max(ret,rec(prev+i));
    st.pop_back();
  }
  return ret;
}

void solve(long long N, long long M, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c, std::vector<long long> d){
  A=move(a);
  B=move(b);
  C=move(c);
  D=move(d);
  MM=M;
  NN=N;
  QQ=Q;
  cout<<rec(1)<<endl;;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> a(Q);
    std::vector<long long> b(Q);
    std::vector<long long> c(Q);
    std::vector<long long> d(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        --a[i];--b[i];
        scanf("%lld",&c[i]);
        scanf("%lld",&d[i]);
    }
    solve(N, M, Q, std::move(a), std::move(b), std::move(c), std::move(d));
    return 0;
}


Measured memory_bytes: 3696
// finish date: 2018/12/21

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


//素因数分解
map<ll, ll> p_fact(ll n) {
    map<ll, ll> mp;
    ll i = 2;
    while (n >= i * i) {
        while (n % i == 0) mp[i]++, n /= i;
        i++;
    }
    if (n != 1) mp[n]++;
    return mp;
}


int main() {
    //入力と変数宣言
    ll N, P;
    cin >> N >> P;

    ll ans = 1;
    map<ll, ll> mp = p_fact(P);
    for (auto e:mp) {
        while (e.second >= N) {
            ans *= e.first;
            e.second -= N;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int w,h;
  string a[102];
  while(cin>>w>>h,w){
    for(int i=0;i<102;i++){
      a[i]="";
    }
    for(int i=0;i<w;i++){
      cin>>a[i];
    }
    int x=0,y=0;
    while(true){
      if(a[x][y]=='.'){cout<<y<<' '<<x<<endl;break;}
      else  if(a[x][y]=='o'){cout<<"LOOP"<<endl; break;}
      else if(a[x][y]=='>'){a[x][y]='o'; y++;}
      else if(a[x][y]=='<'){a[x][y]='o'; y--;}
      else if(a[x][y]=='^'){a[x][y]='o'; x--;}
    else if(a[x][y]=='v'){a[x][y]='o'; x++;}
    }
  }
}
    

Measured memory_bytes: 1232
/*
 * 3027_OOLLOLL.c
 *
 *  Created on: 2019/05/19
 *      Author: nagashima
 */

#include <stdio.h>
#include <math.h>

int main(){
	int N;
	int i=0;

	scanf("%d",&N);

	for(;N>=pow(2,i)-1;i++);


	printf("%d\n",i-1);
	return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  string s;

  cin >> n >> k;
  cin >> s;

  s[k - 1] += 'a' - 'A';
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(ll i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;
    while(T--)
    {
        ll k,n; cin>>k>>n;
        ll a[n]; f(i,n) cin>>a[i];
        ll dis = a[0] + k - a[n-1];
        f1(i,n-1)
        {
            dis = max(dis, a[i]-a[i-1]);
        }
        cout<<k-dis<<"\n";
    }
    return 0;
}


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

int main(){
    long N;
    cin >> N;
    long tmp;
    long trans[5];
    
    for(int i = 0; i < 5; i++){
        cin >> tmp;
        trans[i] = tmp;        
    }

    long mini = trans[0];

    for(int i = 1; i < 5; i++){
        if(mini > trans[i]) mini = trans[i];
    }

    if(mini >= N) cout << 5 << '\n';
    else if (N%mini == 0) cout << 4 + N/mini << '\n';
    else cout << 5 + N/mini << '\n';;

    return 0;
}

Measured memory_bytes: 256
list1=[]
list2=[]
s=0
for i in range(28):
    n=int(input())
    list1.append(n)
for x in range(30):
    s=s+1
    list2.append(s)
list3=list(set(list1)^set(list2))
print(list3[0])
print(list3[1])


Measured memory_bytes: 5596
#include <stdio.h>
#include <string.h>

int main(){
    char s[1001], order[8], ch[1001];
    int i, j, n, a, b;
    
    scanf("%s\n%d", s, &n);  //命令,回数
    
    for(i=0; i<n; i++) {
        scanf("%s %d %d", order, &a, &b);
        
        if(!strcmp(order, "reverse")) {
            for(j=a; j<=b; j++)
                ch[b-j] = s[j];
            for(j=a; j<=b; j++)
                s[j] = ch[j-a];
        }
        
        if (!strcmp(order, "replace")) {
            scanf("%s", ch);
            for (j=0; ch[j]!='\0'; j++)
                s[a+j] = ch[j];
        }
        
        if (!strcmp(order, "print")) {
            for (j=a; j<=b; j++)
                printf("%c", s[j]);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2100
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
a = MAP()

flag = False
cnt=0
for i in a:
    if i==0:
        flag = True
        break
    if i<0:
        cnt+=1
if cnt%2==0:
    flag = True

if flag:
    l = [abs(i) for i in a]
    print(sum(l))
else:
    l = [abs(i) for i in a]
    print(sum(l)-(2*min(l)))

Measured memory_bytes: 14468
n = int(input())
s = input()

W_csum = [0] * n
E_csum = [0] * n
if s[0] == 'W':
    W_csum[0] = 1
else:
    E_csum[0] = 1
for i in range(1,n):
    if s[i] == 'W':
        W_csum[i] = W_csum[i-1] + 1
        E_csum[i] = E_csum[i-1]
    else:
        W_csum[i] = W_csum[i-1]
        E_csum[i] = E_csum[i-1] + 1

W_csum_r = [0] * n
E_csum_r = [0] * n
if s[-1] == 'W':
    W_csum_r[0] = 1
else:
    E_csum_r[0] = 1
for i,j in enumerate(range(n-2,-1,-1),1):
    if s[j] == 'W':
        W_csum_r[i] = W_csum_r[i-1] + 1
        E_csum_r[i] = E_csum_r[i-1]
    else:
        W_csum_r[i] = W_csum_r[i-1]
        E_csum_r[i] = E_csum_r[i-1] + 1

W_csum_r.reverse()
E_csum_r.reverse()

ans = float('inf')
for i in range(1,n-1):
    num = 0
    if s[i] == 'W':
        num += E_csum_r[i+1]
        num += W_csum[i-1]
    else:
        num += E_csum_r[i+1]
        num += W_csum[i-1]
    if num < ans:
        ans = num

if ans > E_csum_r[1]:
    ans = E_csum_r[1]
if ans > W_csum[-2]:
    ans = W_csum[-2]

print(ans)
    



Measured memory_bytes: 33976
def stringWithTheSameLength(n, s, t):

    ans = ""

    for i in range(n):
        ans += s[i] + t[i]

    return ans

def main():
    n = int(input())
    s, t = map(str, input().split())
    print(stringWithTheSameLength(n, s, t))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9100
#include <iostream>
using namespace std;
int main(void){
    int K,i;
    int k=7;
    cin>>K;
    for(i=1;i<=K;i++){
        if(k%K==0){
            cout<<i;
            break;
        }
        k=(k*10+7)%K;
    }
    if(K<i){
        cout<<-1;
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define VJ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair()
#define vi(x) vector<int>x
#define vl vector<long long int>
#define vc vector<char> 
#define Memset(a,num,l,r) for(int iii=l;iii<=r;iii++) a[iii]=num;
#define Printwithspace(a,l,r)for(int iii=l;iii<=r;iii++) cout<<a[iii]<<" ";
#define PrintwithNewline(a,l,r) for(int iii=l;iii<=r;iii++) cout<<a[iii]<<endl;
#define Max 1000001
using namespace std;

bool visited[Max];
vector<int>v[Max];

int nodes=0;

void dfs(int n){
	nodes++;
	visited[n]=true;
	for(auto it:v[n]){
		if(!visited[it])
			dfs(it);
	}
}


void solve(){
	int n,m;cin>>n>>m;
	int connected=0;
	// vi(z);
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int ans=-1;
	for(int i=1;i<=n;i++){
		if(!visited[i])
		{
			dfs(i);
			ans=max(ans,nodes);
			nodes=0;
			connected++;
		}
	}
	cout<<ans;
}



int main(){
	 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	 #endif
	VJ
	solve();
	return 0;
}



Measured memory_bytes: 39708
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n, m;
    cin >> n >> m;
    
    const int INF = 1 << 30;
    vector<vector<int>> dp(1 << n, vector<int>(n, -INF));
    vector<int> costs(1 << n, 0);
    vector<vector<int>> g(n, vector<int>(n, 0));
    
    int all_costs = 0;
    repeat(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a-1][b-1] = c;
        g[b-1][a-1] = c;
        all_costs += c;
    }
    
    repeat(s, (1 << n)) {
        repeat(x, n) {
            repeat_from(y, x+1, n) {
                if (!(s & (1 << x))) continue;
                if (!(s & (1 << y))) continue;
                costs[s] += g[x][y];
            }
        }
    }
    
    repeat(s, (1 << n)) {
        // 頂点0を含む集合に対してdpを初期化する
        if (s & 1) {
            dp[s][0] = costs[s];
        }
    }
    
    int mask = ((1 << n) - 1);
    
    repeat(s, (1 << n)) {
        repeat(x, n) {
            // Sの中の頂点xから伸ばすので, x in S か調べる
            if (dp[s][x] == -INF) continue;
            // Sの補集合がsup
            int sup = (~s) & mask;
            // supの部分集合subを降順に列挙
            for(int sub = sup; sub > 0; sub = ((sub - 1) & sup)) {
                // subから伸ばす頂点yを選ぶ
                repeat(y, n) {
                    //dump(s); dump(x); dump(y); el;
                    if (!(sub & (1 << y))) continue;
                    if (g[x][y] == 0) continue;
                    
                    //cout << "s=" << bitset<4>(s) << " sup=" << bitset<4>(sup) << " sub=" << bitset<4>(sub) << " "; dump(x); dump(y); el;
                    //cout << "before dp[" << bitset<4>(s|sub) << "][" << y << "]=" << dp[s|sub][y] << endl;
                    dp[s|sub][y] = max(dp[s|sub][y], dp[s][x] + g[x][y] + costs[sub]);
                    //cout << "after  dp[" << bitset<4>(s|sub) << "][" << y << "]=" << dp[s|sub][y] << " dp[" << bitset<4>(s) << "][" << x << "]=" << dp[s][x] << " g[" << x << "][" << y << "]=" << g[x][y] << " costs[" << bitset<4>(sub) << "]=" << costs[sub] << endl << endl;
                }
            }
        }
    }
    
   cout << all_costs - dp[mask][n-1] << endl; 
    
}
                

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int a[60], b[60], c[60], d[60], x[20];
int n, m, q, ans;

void dfs(int now, int last) {
    if (now > n) {
        int s = 0;
        for (int i = 1; i <= q; ++i) {
            if (x[b[i]] - x[a[i]] == c[i]) {
                s += d[i];
            }
        }
        ans = std::max(ans, s);
        return ;
    }
    for (int i = last; i <= m; ++i) {
        x[now] = i;
        dfs(now + 1, i);
    }
}

int main() {
    read(n), read(m), read(q);
    for (int i = 1; i <= q; ++i)    read(a[i]), read(b[i]), read(c[i]), read(d[i]);
    dfs(1, 1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3748
main :: IO ()                                                                                                              
main = do                                                                                                                  
  getLine                                                                                                                  
  k <- read <$> getLine                                                                                                    
  xs <- map read . words <$> getLine                                                                                       
  print $ (*2) . sum . map (\x -> if x < k - x then x else k - x) $ xs  

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N);
  for(int i=0;i<N;i++) std::cin >> A[i];
  vvl right = vv(N+1, 2, -1, ll);
  vvl left = vv(N+1, 2, -1, ll);
  vector<int> idx(N+1, 0);
  set<ll> r, l;
  for(int i=0;i<N;i++){
    idx[A[i]] = i;
    r.insert(A[i]);
    auto itr = r.begin();
    while(*itr!=A[i]){
      if(right[*itr][0]!=-1) right[*itr][1] = i;
      else right[*itr][0] = i;
      itr++;
    }
    auto it = r.begin();
    while(true){
      if(*it == A[i]) break;
      if(right[*it][1]!=-1) {
        it++;
        int next = *it;
        it--;
        r.erase(*it);
        it = r.find(next);
      }else it++;
    }
  }

  for(int i=N-1;i>=0;i--){
    l.insert(A[i]);
    auto itr = l.begin();
    while(*itr!=A[i]){
      if(left[*itr][0]!=-1) left[*itr][1] = i;
      else left[*itr][0] = i;
      itr++;
    }
    auto it = l.begin();
    while(true){
      if(*it == A[i]) break;
      if(left[*it][1]!=-1) {
        it++;
        int next = *it;
        it--;
        l.erase(*it);
        it = l.find(next);
      }else it++;
    }
  }
  ll ans = 0;
  for(int i=1;i<N;i++){
    ll reg = 0;
    if(right[i][0]!=-1) reg+=(i*((right[i][1]==-1?N:right[i][1])-right[i][0])*(left[i][0]==-1?idx[i]+1:idx[i]-left[i][0]));
    if(left[i][0]!=-1) reg+=(i*(left[i][1]==-1?left[i][0]+1:left[i][0]-left[i][1]) * (right[i][0]==-1?N-idx[i]:right[i][0]-idx[i]));
    ans += reg;
  }
  std::cout << ans  << '\n';
  return 0;
}


Measured memory_bytes: 16640
l,r=map(int, input().split())
mo=2019
ans=2018
r=min(r, l+mo-1)
#max in k~k+2019 line seg. i<k+2019 and k<j
for i in range(l,r):
    for j in range(i+1,r+1):
        tmp=i*j
        ans=min(ans,tmp%mo)
print(ans)

Measured memory_bytes: 65224
#include<bits/stdc++.h>
using namespace std;
#define tezi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(c) c.begin(),c.end()
#define ll long long
#define ull unsigned long long
#define traverse(c,it) for(auto it=c.begin();it!=c.end();it++)
#define lowerb(v,a) lower_bound(v.begin(),v.end(),a)
#define lowerbarr(v,n,a) lower_bound(v,v+n,a)
#define upperb(v,a) upper_bound(v.begin(),v.end(),a)
#define upperbarr(v,n,a) upper_bound(v,v+n,a)
#define maxval(v) max_element(v.begin(),v.end())
#define maxarr(v,n) max_element(v,v+n)
#define minval(v) min_element(v.begin(),v.end())
#define minarr(v,n) min_element(v,v+n)
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define mem0(v) memset(v,0,sizeof(v))
#define memf(v) memset(v,false,sizeof(v))
#define memt(v) memset(v,true,sizeof(v))
#define mem(v,a) memset(v,a,sizeof(v))
#define npos string::npos
#define MAX 10000000
#define MOD 1000000009
                    /**************SIEVE****************/

/*bool prime[MAX+1];
vector<int> v;
void sieve(){ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true.
   
    memset(prime, true, sizeof(prime)); 
  
    for (long p=2; p*p<=MAX; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (long i=p*p; i<=MAX; i += p) 
                prime[i] = false; 
        } 
    } 
  for(int i=0;i<=MAX;i++)if(prime[i])v.pb(i);
  
   
    
   
} 
 
                                        /**************gcd****************/

ll gcd(ll a,ll b) 
{ if(a>b)swap(a,b);
    if (a == 0) 
        return b; 
   return gcd(b%a, a); 
}
 
 
 
                                         /**************POWER****************/
 ll binpow(ll a, ll b) {
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2)%MOD;
    if (b % 2)
        return ((ull)res * (ull)res * (ull)a)%MOD;
    else
        return ((ull)res * (ull)res)%MOD;
}
   

 
 
 
 
                                     /**************MAIn****************/





int main()
{   tezi
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("put.txt","w",stdout);
  #endif

  int T=1;
  //cin>>T;
  
  
  while(T--)
  {ll n,k;
    cin>>n>>k;
    ll a[n];
    loop(i,0,n)cin>>a[i];
    ll dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
      ll mn=(ll)1e20;
      for(int j=i-1;j>=max(0LL,i-k);j--)
      {
        mn=min(mn,dp[j]+abs(a[j]-a[i]));
      }
      dp[i]=mn;
    }
    cout<<dp[n-1];

      



    

  }
  
  
   
    
    
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";

    

}
  
   




   
   

    
 
   
  

 
   
 
 
 
 
 
  
 
 

Measured memory_bytes: 5368
#include<iostream>
#include<iomanip>
#include<iterator>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
*/
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3f3fffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll MOD=1000000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<"DEBUG:("<<#x<<","<<#y<<") are: "<<x<<" "<<y<<'\n';
/////////////////// GLOBAL VARIABLES ////////////////////////////
vector<vector<pii>> adj; vector<bool> vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
/////////////////// FUNCTIONS ////////////////////////////////////
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
ll gcd(ll x, ll y){ if(x==0 || y==0) return x+y; else return gcd(y%x,x);}

/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<fixed;   cerr<<fixed;
  cout<<setprecision(8); cerr<<setprecision(3);
#ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
#endif

  int n; string s; cin>>n>>s; vi v(n);
  v[0]=s[0]=='W';for(int i=1;i<n;++i) v[i]=v[i-1]+(s[i]=='W'?1:0);
  ll ans=INFLL;
  for(int i=0;i<n;++i){
    ans=min<ll>(ans,v[i]-(ll)(s[i]=='W')+n-1-i-v[n-1]+v[i]);
  }
  cout<<ans<<'\n';

#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
#endif
  return 0;
}


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

#define INF (int)(1e9)
#define MOD (int)((int)1e9+7)

pair<int,int> st[110000];
int main(){
  int n, t = -1, count = 0;

  cin>>n;

  for(int i = 0; i < n; i++){
    cin>>st[i].second>>st[i].first;
  }
  sort(st,st+n);

  for(int i = 0; i < n; i++){
    if(st[i].second > t){//cout<<st[i].first<<" "<<st[i].second<<endl;
      count++;
      t =st[i].first;
    }
  }

  cout<<count<<endl;

  return 0;
}



Measured memory_bytes: 3884
import sys
n=int(input())
List=list(map(int,input().split()))
List.sort(reverse=True)
if List[-1]==0:
    print(0)
    sys.exit()
ans=1
for i in List:
    if ans<=10**18:
        ans*=i
    else:
        print(-1)
        sys.exit()
if ans<=10**18:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 84812
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;;
ll asc_cmp(const void* X,const void* Y){ll x=*(ll*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
ll desc_cmp(const void* X,const void* Y){ll x=*(ll*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

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

    int flg=0;
    for(int i=0;i<n;i++){
        if(a[i]%2==0){
            if(a[i]%3==0||a[i]%5==0);
            else{
                flg=1;
                break;
            }
        }
    }

    if(flg)printf("DENIED\n");
    else printf("APPROVED\n");
}

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

const int MOD = 1e9 + 7;

void add(int &a, int b) {
    a = a + b < MOD ? a + b : a + b - MOD;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> dp(M + 1, 1);

    for (int i = 0; i < N; i++)
        for (int m = 0, sum = 0; m <= M; m++) {
            int extra = (sum + int64_t(m) * dp[m]) % MOD;
            add(dp[m], extra);
            add(sum, extra);
        }

    cout << dp[M] << '\n';
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
int isprime(int);

int main(){
  int x[10000],count = 0;
  int n,i;
  scanf("%d",&n);
  for(i = 0;i < n;i++){
  scanf("%d",&x[i]);
  if(isprime(x[i]) == 1)
  count+=1;
}


  printf("%d\n",count);
  return 0;
}

int isprime(int x){
    int i = 3;
  if(x == 2)
  return 1;
  else if(x < 2 || x % 2 ==0)
  return 0;
  while(i <= sqrt(x)){
    if(x % i ==0)
    return 0;
    i = i+2;
  }
  return 1;
}



Measured memory_bytes: 2024
# C
a, b, c, x, y = map(int, input().split())

# A and B
AandB = a*x + b*y
# AB and A or B
if x > y:
    ABandAorB = 2*c*y + a * (x-y)
else:
    ABandAorB = 2*c*x + b * (y-x)
# only AB
if x > y:
    AB = 2*c*x
else:
    AB = 2*c*y
print(min(AandB,ABandAorB,AB))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << ((n % 2 == 0) ? n : n * 2) << endl;
    return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	ll int n,m,T,res;

	ll int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	ll int A,B,C;

	cin>>A>>B>>C;




	f(i,1,100)
	{
	    res=(A*i)+A;
	    if(res%B == C%B){
            cout<<"YES"<<endl;
            return 0;
	    }
	}

	cout<<"NO"<<endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInts();
            var a = n.Sum();
            if (a == 17) WriteLine("YES");
            else WriteLine("NO");
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 13268
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007



int main()
{
	int n;
	cin >> n;
	vector<pair<int, int> > v;
	for(int i = 1; i <= n; i++){
		int p;
		cin >> p;
		v.push_back(make_pair(p, i));
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	long long int ans = 0;

	set<int> s;

	s.insert(v[0].second);
	for(int i = 1; i < v.size(); i++){
		int nowv = v[i].first;
		int p = v[i].second;
		auto r1 = s.upper_bound(p);
		// nowvより大きい値が左側に1つ入っている またはnowvより大きい値が右側に1つ入っている
		// (L \in (*l1, *l2] かつ　R \in [p, *r1)) または ( L \in (*l2, p] かつ [*r1, *r2) ) となればよい
		long long int combnum = 0;

		// L \in (*l1, *l2] かつ　R \in [p, *r1)となる組み合わせの数
		// r1 == s.begin()のとき、l1およびl2は存在しない
		// つまりnowvの左側にnowvより大きい値は存在しない
		// この場合は何もしない
		if(r1 != s.begin()){
			int l_range, r_range;
			auto l2 = r1;
			l2--;
			if(l2 == s.begin()){
				// l1は存在しない
				// よってLの範囲は[1, *l2]
				l_range = *l2;
			} else {
				auto l1 = l2;
				l1--;
				l_range = *l2 - *l1;
			}
			if(r1 == s.end()){
				// r1は存在しない
				// つまりnowvの右側にnowvより大きな値は存在しない
				// よってRの範囲は[p, n]
				r_range = n - p + 1;
			} else {
				r_range = *r1 - p;
			}
			combnum += l_range * r_range;
		}

		// L \in (*l2, p] かつ [*r1, *r2) となる組み合わせの数
		//  r1 == s.end()のとき、r1、r2は存在しない
		// つまりnowvより大きい値はnowvより右側に存在しない
		// この場合は何もしない
		if(r1 != s.end()){
			int l_range, r_range;
			if(r1 == s.begin()){
				// l2は存在しない
				// よってLの範囲は[1, p]
				l_range = p;
			} else {
				auto l2 = r1;
				l2--;
				l_range = p - *l2;
			}
			auto r2 = r1;
			r2++;
			if(r2 == s.end()){
				// r2は存在しない
				// よってRの範囲は[*r1, n]
				r_range = n - *r1 + 1;
			} else {
				r_range = *r2 - *r1;
			}
			combnum += l_range * r_range;
		}
		ans += combnum * nowv;
		s.insert(p);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5748
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(a,b) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;

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

	if (a+b==15) cout << "+\n";
	else if (a*b==15) cout <<"*\n";
	else cout <<"x\n";

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;
    vector<vector<int>> a(2);

    rep(i, 2){
        rep(j, n){
            int x; cin >> x;
            a[i].push_back(x);
        }
    }

    int ans = 0;
    rep(i, n){
        int res = 0;
        rep(j, i+1){
            res += a[0][j];
        }

        for (int j = i; j < n; ++j) {
            res += a[1][j];
        }

        ans = max(ans, res);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int arr[2050][2050];
void fill(int s,int e,int n,int m)
{
    if(n==0) {arr[s][e+(1<<m)-1]=1;return;}
    if(m==0) {arr[s+(1<<n)-1][e]=1;return;}
    arr[s+(1<<n)-1][e+(1<<m)-1]=1;
    fill(s,e,n-1,m-1);
    fill(s+(1<<n),e,n-1,m-1);
    fill(s,e+(1<<m),n-1,m-1);
    fill(s+(1<<n),e+(1<<m),n-1,m-1);
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    fill(1,1,n-1,m-1);
    for(int i=1;i<1<<n;cout<<'\n',i++)for(int j=1;j<1<<m;j++)cout<<arr[i][j];
    cout.flush();
    return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll x,n;
  cin>>x>>n;
  ll a[n];
  map <ll,ll> mp;
  fo(i,n)
  {
    cin>>a[i];
    mp[a[i]]=1;
  }
  ll ans=0;
  for(ll i=x;;i++)
  {
    if(mp[i]==0)
    {
      ans=i;
      break;
    }
  }
  for(ll i=x;;i--)
  {
    if(mp[i]==0)
    {
      if(abs(x-i)<=abs(x-ans))
        ans=i;
      break;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
template <class ForwardIterator, class T>
  void iota (ForwardIterator first, ForwardIterator last, T val)
{
  while (first!=last) {
    *first = val;
    ++first;
    ++val;
  }
}
int g[11][11]={0};
int main()
{
    int n,m,x,y,res=0;
    cin>>n>>m;
    vector<int> p(n);
    iota(p.begin(),p.end(),0);
    
    for(int i=0;i<m;i++){
        cin>>x>>y;
        g[x-1][y-1] = g[y-1][x-1] = 1;
    }
    do{
        bool flag = true;
        if(p[0])break;//視点が1の時はbreak
        for(int i=1;i<n;i++){
            if(!g[p[i-1]][p[i]])flag=false;//つながってない
        }
        if(flag)res++;
    }while(next_permutation(p.begin(),p.end()));
    cout<<res<<endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  string s;
  map<string, int> a;
  for(int i=0; i<n; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    a[s]++;
  }
  
  int64_t ans = 0;
  for(pair<string, int64_t> p : a) {
    if(p.second>1) ans += p.second*(p.second-1)/2;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11344
#include <stdio.h>
#define MAX 100000
int A[MAX];
int n;

int partition(int p, int r){
  int x, i, j, temp;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++){
    if(A[j] <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
      temp = A[i+1];
      A[i+1] = A[r];
      A[r] = temp;

      return i+1;
}

int main(){
  int i, q;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
    q = partition(0, n-1);
  
    for(i=0; i<n-1; i++){
      if(i == q) printf("[");
      printf("%d", A[i]);
      if(i ==q)printf("]");
      printf(" " );
  }

    printf("%d\n",A[n-1]);

  return 0;

}

Measured memory_bytes: 992
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU
 
-- 解説読後
-- http://arc060.contest.atcoder.jp/data/arc/060/editorial.pdf
-- s > n のときは -1 を入れないと TLEすることも 
 
import qualified Data.List as L
 
main = print . solve . map read . lines =<< getContents
 
f b n
    | n < b     = n
    | otherwise = let (dv, md) = divMod n b in md + f b dv
 
solve [n, s]
    | n == s    = n + 1
    | s >  n    = -1
    | otherwise = ans where
        en = maximum . takeWhile (\i -> i * i <= n) $ [1 .. ]
        ans = case L.find ((==) s . snd) . map (\i -> (i, f i n)) $ [2 .. en] of
            Just (i, _) -> i
            Nothing -> if en > 0 then ans' else -1 where
                ans' = case L.find ((==) s . snd) . map (\i -> (i, f i n)) $ bs of
                    Just (j, _) -> j
                    Nothing -> -1
                bs = map ((+) 1 . fst) . filter ((==) 0 . snd) . map (divMod (n - s)) $ [ en - k | k <- [0 .. en - 1]]
 

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i <= (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

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

int main()
{
    int k,s;
    cin >> k >> s;
    int cnt = 0;
    rep(x,k)rep(y,k){
        if(x+y<=s && x+y+k>=s) cnt++;
    }    
    cout << cnt << endl;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
//typedef vector<vector<ll>> Graph;

const ll mod = 1e9 + 7;
//const ll mod = 998244353;

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

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

    ll L;
    cin >> L;
    double l = (double)L/3.0;
    double res = l*l*l;
    printf("%.10f\n", res);

    return 0;
}

Measured memory_bytes: 3720
# -*- coding: utf-8 -*-
S = list(input())
a1 = list('dreamer')
a2 = list('dream')
b1 = list('eraser')
b2 = list('erase')

#a1
loop_list = [b1, b2, a1, a2]
for word in loop_list:
    for i in range(len(S)-len(word)+1):
        all_match = True
        for j in range(len(word)):
            if S[i+j] == word[j]:
                pass
            else:
                all_match = False

        if all_match == False:
            continue

        for j in range(len(word)):
            S[i+j] = ''

# print(S)
if  sum( list(map(len,S))   ) == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 4652
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = (1e9) + 1;
const int mod = 1e9 + 7;
const int maxn = 4e5 + 111;
     
using namespace std;

ll n, q, k, a[maxn], ans = inf;
pii b[30];

void solve(){     
	string s;

	cin >> s;

	for (int i = 0; i < s.size() - 1; i++){
		if (s[i] == s[i + 1]){
			cout << i + 1 << " " << i + 2;
			return;
		}
	}
	for (int i = 0; i < s.size() - 2; i++){
		if (s[i] == s[i + 2]){
			cout << i + 1 << " " << i + 3;
			return;
		}
	}
	cout << -1 << " " << -1;
}

main(){
    boost;
	                 	
	q = 1;

	while (q--){
		solve();
	}
}


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

using namespace std;

void print_ans(int s, int n) {
  for (int i = 0; i < n; i++) {
    cout << s;
  }
  cout << '\n';
  return;
}

int main(void) {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a > b) {
    print_ans(b, a);    
  } else if (a < b) {
    print_ans(a, b);
  } else if (min(a, b) == a) {
    print_ans(b, a);
  } else {
    print_ans(a, b);
  }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const char Op[] = "+-*";
int calc(int a, int b, int c) {
  switch (c) {
  case 0:
    return a + b;
    break;
  case 1:
    return a - b;
    break;
  case 2:
    return a * b;
    break;
  }
  return 0;
}
int main() {
  int a[4];
  while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
    if (a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0) break;
    sort(a, a + 4);
    do {
      for (int op = 0; op < 27; op++) {
        int sum = a[0];
        for (int i = 1, j = 1; i < 4; i++, j *= 3)
          sum = calc(sum, a[i], op / j % 3);
        if (sum == 10) {
          printf("(((%d %c %d) %c %d) %c %d)\n", a[0], Op[op % 3], a[1],
            Op[op / 3 % 3], a[2], Op[op / 9 % 3], a[3]);
          goto NEXT;
        }
        sum = calc(calc(a[0], a[1], op % 3), calc(a[2], a[3], op / 9 % 3),
          op / 3 % 3);
        if (sum == 10) {
          printf("((%d %c %d) %c (%d %c %d))\n", a[0], Op[op % 3], a[1],
            Op[op / 3 % 3], a[2], Op[op / 9 % 3], a[3]);
          goto NEXT;
        }
      }
    }
    while (next_permutation(a, a + 4));
    cout << 0 << endl;
    NEXT:
    ;
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int A, B; cin >> A >> B;
	if (1 <= A && A <= 9 && 1 <= B && B <= 9) cout << A * B << endl;
	else cout << -1 << endl;

	return 0;
}

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

using namespace std;

int main(){

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

    int N;
    scanf("%d", &N);

    int P[N];

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

    int currMin = INT_MAX;
    int count = 0;
    for(int i=1; i <= N; i++){

        currMin = min(currMin, P[i-1]);

        if(P[i-1] <= currMin){
            count++;
        }

    }

    printf("%d\n", count);


}

Measured memory_bytes: 1024
import bisect
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a, b[i])
    y = bisect.bisect_right(c, b[i])
    ans += x * (n - y)
print(ans)

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

int main() {
  int N;
  cin >> N;
  int G = 0;
  int A = 0;  
  int B = 0;  
  G++;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < N; i++){
    G++;
    if (G % 2 == 1){
      A += vec.at(i);
     }else{
       B += vec.at(i);
    }
  }
  cout << B - A << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int outlet = 1;
    int ans = 0;
    while(outlet<b){
        outlet--;
        outlet += a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int H,W;
  int h,w;
  cin >> H >>W >>h >>w;
  print((H-h)*(W-w));

 return 0;
}


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


ll rec(ll L, ll x){
  //レベルLハンバーガを下からx層だけ食べた時のパティの枚
  if( L == 0){ return 1;}
  
   else{
  
  ll hight = (1LL << (L+1)) -3; ll p = ( 1LL << L )-1;
  
  if( x == 1|| x == 0){ return 0;}
  else if( x <= 1+hight){ return rec(L-1,x-1);}
  else if( x == 2+hight){ return p+1;}
  else if( x <= 2+2*hight){ return 1 + p + rec( L-1,x-2-hight);}
  else if( x >= 3+2*hight){ return 2*p+1;} }
}

int main(){
 ll N,X; cin >> N >> X;
  cout << rec(N,X) << endl; return 0;}
 

Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
	int H[100],W[100];
	int dataset = 0;
	
	while (H != 0 && W !=0){
		
		scanf("%d %d", &H[dataset], &W[dataset]);
		if (H[dataset] == 0 && W[dataset] == 0) break;
		dataset++;
	}
	
//	printf("%d", dataset);

	for (int data = 0; data < dataset; data++){
				
		for (int i = 0; i < H[data]; i++){
			if (i == 0 || i == H[data] - 1){
				for (int j = 0; j < W[data]; j++){
					printf ("#");
				}
			}
			else{
				printf("#");
				for (int middle = 0; middle < W[data] - 2; middle++){
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
	
}


Measured memory_bytes: 2044