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

#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define PH push
#define ll long long
#define ull unsigned long long
#define debug(x) cerr<<#x<<"="<<x<<'\n'
//#define DEBUG
//#pragma GCC optimize(2)

const int MOD=1e9+7;

int f[1<<19][2];
int id[1<<19][2];
int n;
int a[1<<19];
int v[10];

bool tmp(int x,int y)
{
	if(x==-1) return 0;
	if(y==-1) return 1;
	return a[x]>a[y]; 
}

int main()
{
	#ifdef DEBUG
	clock_t tStart = clock();
	#endif
	scanf("%d",&n);
	for(int i=0;i<(1<<n);i++) scanf("%d",&a[i]);
	for(int i=0;i<(1<<n);i++) f[i][0]=i,f[i][1]=-1;
	for(int i=0;i<(1<<n);i++)
	{
//		printf("f[%d]=%d %d\n",i,f[i][0],f[i][1]);
		for(int j=0;j<n;j++)
		{
			if((i>>j)&1) continue;
			int msk=i+(1<<j);
			v[0]=f[msk][0],v[1]=f[msk][1],v[2]=f[i][0],v[3]=f[i][1];
			sort(v,v+4,tmp);
//			printf("msk=%d %d v=%d %d %d %d\n",i,msk,v[0],v[1],v[2],v[3]);
			f[msk][0]=v[0];
			if(v[0]==v[1]) f[msk][1]=v[2];
			else f[msk][1]=v[1];
		}
	}
	int res=0;
	for(int i=1;i<(1<<n);i++)
	{
		res=max(res,a[f[i][0]]+a[f[i][1]]);
		printf("%d\n",res);
	}
	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
	return 0;
}



Measured memory_bytes: 10240
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int d,t,s;
	bool ans=true;
	cin >>d>>t>>s;
	cout<<solve(t*s >=d)<<endl;
}

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

int main() {
  int H,W,i;
  cin >> H >> W;
  vector<string> moji(H);
  for(i=0;i<H;++i)
    cin >> moji.at(i);
  for(i=0;i<(W+2);++i)
    cout << '#';
  cout << endl;
  for(i=0;i<H;++i)
    cout << '#' << moji.at(i) << '#' << endl;
  for(i=0;i<(W+2);++i)
    cout << '#';
  
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
 if(abs(c-a)<=d) {
cout<<"Yes"<<endl;
 }
  else if(abs(b-a)<=d&&abs(c-b)<=d) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    set<ll> s;
    ll cnt = 0;
    rep(i, N) {
        ll a;
        cin >> a;

        if (a <= 399) {
            s.insert(0);
        } else if (a <= 799) {
            s.insert(1);
        } else if (a <= 1199) {
            s.insert(2);
        } else if (a <= 1599) {
            s.insert(3);
        } else if (a <= 1999) {
            s.insert(4);
        } else if (a <= 2399) {
            s.insert(5);
        } else if (a <= 2799) {
            s.insert(6);
        } else if (a <= 3199) {
            s.insert(7);
        } else {
            cnt++;
        }
    }
    if (s.size() == 0) {
        print(1 << " " << cnt);
    } else {
        print(s.size() << " " << s.size() + cnt );
    }
    return 0;
}


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

int main() {

 int N;
  cin >> N;
  int x;
  for (int i= 1;i<=N;i*=10){
   x += N%(10*i)/i;
  }
  if (N%x==0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int sd(int n){
	int sum=0;
	while(n>0){
		sum+=n%10;
		n/=10;
	}
	return sum;
}
int main(){
	int n,a,b;cin>>n>>a>>b;
	int ans=0;
	for(int i=1;i<=n;i++){
		int sum=sd(i);
		if(sum>=a&&sum<=b){
			ans+=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
/////////////////////////   _LeMur_
#include <iostream>
#include <algorithm>
#include <time.h>
#include <stack>
#include <string>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int M = 2005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n , k;
int a[N] , b[N];
char c[N];
int bl[M][M] , w[M][M] , pref[M][M][3];

int cnt(int x,int y,int col){
    int xx = x + k - 1;
    int yy = y + k - 1;
    x = max(x , 0);
    y = max(y , 0);
    xx = min(xx , 2 * k);
    yy = min(yy , 2 * k);
    if(x > xx || y > yy)return 0;
    int answ = pref[xx][yy][col];
    if(x != 0) answ -= pref[x - 1][yy][col];
    if(y != 0) answ -= pref[xx][y - 1][col];
    if(x != 0 && y != 0) answ += pref[x - 1][y - 1][col];
    return answ;
}

int calc(int x,int y){
    int answ = 0;
    answ += cnt(x , y , 0);
    answ += cnt(x + k , y + k , 0);
    answ += cnt(x + k , y - k , 0);
    answ += cnt(x - k , y + k , 0);
    answ += cnt(x - k , y - k , 0);
    answ += cnt(x , y + k , 1);
    answ += cnt(x , y - k , 1);
    answ += cnt(x + k , y , 1);
    answ += cnt(x - k , y , 1);
    answ += cnt(x , y - 2 * k , 0);
    answ += cnt(x , y + 2 * k , 0);
    answ += cnt(x + 2 * k , y , 0);
    answ += cnt(x - 2 * k , y , 0);

    answ += cnt(x + 2 * k , y + k , 1);
    answ += cnt(x + 2 * k , y - k , 1);
    answ += cnt(x - 2 * k , y + k , 1);
    answ += cnt(x - 2 * k , y - k , 1);

    answ += cnt(x + k , y + 2 * k , 1);
    answ += cnt(x + k , y - 2 * k , 1);
    answ += cnt(x - k , y + 2 * k , 1);
    answ += cnt(x - k , y - 2 * k , 1);
    return answ;
}

int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i],&b[i]);
        scanf(" %c",&c[i]);
        int x = min(a[i] / k , b[i] / k);
        a[i] -= x * k;
        b[i] -= x * k;
        x = a[i] / (2 * k);
        a[i] -= x * 2 * k;
        x = b[i] / (2 * k);
        b[i] -= x * 2 * k;
        if(c[i] == 'W') w[a[i]][b[i]]++;
        if(c[i] == 'B') bl[a[i]][b[i]]++;
    }
    for(int i=0;i<=2*k;i++){
        for(int j=0;j<=2*k;j++){
            for(int h=0;h<2;h++){
                pref[i][j][h] = (h == 0) ? w[i][j] : bl[i][j];
                if(i != 0) pref[i][j][h] += pref[i-1][j][h];
                if(j != 0) pref[i][j][h] += pref[i][j-1][h];
                if(i != 0 && j != 0) pref[i][j][h] -= pref[i-1][j-1][h];
            }
        }
    }
    int answ = 0;
    for(int i=0;i<2*k;i++){
        for(int j=0;j<2*k;j++){
            answ = max(answ , calc(i , j));
        }
    }
    cout<<answ<<endl;
    return 0;
}


Measured memory_bytes: 79616
N, X = gets.split.map(&:to_i)
L = gets.split.map(&:to_i)

d = 0
x = 0
i = 0
while x <= X && d <= N+1 do
    d += 1
    if d == N+1 then
        break
    end
    x += L[i]
    i+=1
end

puts(d)

Measured memory_bytes: 1788
N = int(input())
h = [int(h_i) for h_i in input().split()]

dp = [0] * N
dp[1] = abs(h[0] - h[1])
for i in range(2, N):
	dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2])
print(dp[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n;
    cin >> n;
    vector<pair<int,int> > k;
    rep(i,n){
        int s;
        cin >> s;
        k.push_back(MP(-s,i));
    }
    sort(k.begin(),k.end());
    int id = k[0].second;
    rep(i,n){
        if(id==i){
            cout << -k[1].first << endl;
        }else{
            cout << -k[0].first << endl;
            
        }
    }
    return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int N, M;
string A[55], B[55];

bool ok(int y, int x) {
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < M; j++) {
			if (A[y+i][x+j] != B[i][j]) {
				return false;
			}
		}
	}
	return true;
}

void solve() {
	for (int i = 0; i <= N - M; i++) {
		for (int j = 0; j <= N - M; j++) {
			if (ok(i, j)) {
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}
	solve();
	return 0;
}




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

int main() {
  int n,cal=0;
  cin >> n;
  vector<int> d(n);
  
  for(int i=0; i<n; i++) cin >> d.at(i);
  
  for(int i=0; i<n-1; i++){
    for(int j=n-1; j>i; j--){
  		if(d.at(j)<d.at(j-1)){
          cal=d.at(j);
          d.at(j)=d.at(j-1);
          d.at(j-1)=cal;
        }
    }
  }
  
  cal=d.at(0);
  int count=1;
  for(int i=1; i<n; i++){
    if(cal<d.at(i)){
      cal=d.at(i);
      count++;
    }
  }
  
  cout << count << endl;
  
}

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

const int maxn = 1e6 + 10;

string s;
int n;
int ans;
int a[maxn];

void in();
void solve();
bool resid(int);
void out();

int main(){
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	in();
	solve();
	out();
}

void in(){
	cin >> s;
	n = s.size();
}

void solve(){
	for(int i = 0; i < n; i++)
		a[i] = s[i] - '0';
	int l = 0;
	int r = n + 1;
	while(r - l != 1){
		int mid = (l + r) >> 1;
		if(resid(mid))
			r = mid;
		else
			l = mid;
	}
	ans = r;
}

bool resid(int x){
	x = 9 * x;
	int res = 0;
	for(int i = n - 1; i >= 0; i--){
		while(((x + res) % 10 + 10) % 10 != a[i])
			x--;
		res = (res + x) / 10;
		if(x < 0)
			return 0;
	}
	return 1;
}

void out(){
	cout << ans;
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

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

    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= 1250; i++) {
        if (i * 2 / 25 == a && i / 10 == b) return cout << i, 0;
    }
    cout << -1;
}


Measured memory_bytes: 3664
//  Copyright © 2019 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 300005
#define INF 1e18
using namespace std;
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
typedef long long i64;

i64 N;
i64 a[MAX];
i64 memo[MAX][2];
bool vis[MAX][2];

i64 dp( i64 x , bool f )
{
    if( x == N )
    {
        if( f ) return a[x] * -1;
        return a[x];
    }
    if( vis[x][f] )
        return memo[x][f];
    
    i64 ans = -INF;
    i64 m = 1;
    if( f ) m *= -1;
    // Cambiame
    ans = max( ans , dp( x + 1 , 1 ) + ( m * a[x] ) * -1 );
    ans = max( ans , dp( x + 1 , 0 ) + ( m * a[x] ) );
    vis[x][f] = 1;
    return memo[x][f] = ans;
    
}

int main()
{
    optimiza_io 
    cin >> N;
    for( i64 i = 1; i <= N; i ++ )
        cin >> a[i];
        
    cout << dp( 1 , 0 );
    return 0;
}


/*



-4 4 


-10 5 -4


*/

Measured memory_bytes: 13824
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main()
{
	int n, i, j, c;
	char s[101] = "", r[101] = "", t;
	while (cin >> s, !cin.eof())
	{
		c = 0;
		for (i = 0; i < strlen(s); i++)
		{
			if (s[i] == '@')
			{
				t = s[i+1];
				n = atoi(&t);
				for (j = 0; j < n; j++)
				{
					r[c] = s[i+2];
					c++;
				}
				i += 2;
			}
			else
			{
				r[c] = s[i];
				c++;
			}
		}
		r[c] = '\0';
		cout << r << endl;
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];

    ll ans = LINF;
    for (int i = 1; i<=100; ++i) {
        ll tmp = 0;
        rep(j,n) {
            tmp += (x[j]-i) * (x[j]-i);
        }
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}






























Measured memory_bytes: 256
#include <stdio.h>
int max2(int a, int b)
{
    return a>b ? a : b;
}
int max3(int a, int b, int c)
{
    return max2(a, max2(b, c));
}
int main()
{
    int a, b;   scanf("%d %d", &a, &b);
    printf("%d\n", max3(a-b, a+b, a*b));
    return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
cnt = 0
cnt2 = 0
for i in range(1,n+1):
    if k%2 == 0:
        if i%k == 0:
            cnt += 1
        if i%k == k//2:
            cnt2 += 1 
    else:
        if i%k == 0:
            cnt += 1
print(cnt**3+cnt2**3)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    int a,b,c;
    cin >> a>> b>> c;
    cout << c << " " << a << " " << b << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
	int rcv; char type[3]; map<string, int> nums;
	string blood_name[4] = {"A", "B", "AB", "O"};
	for (int i=0;i<4;i++) nums.insert(make_pair(blood_name[i],0));
	while (EOF != fscanf(stdin, "%d,%s", &rcv, type)) {
		nums[type]++;
	}
	for (int i=0;i<4;i++) printf("%d\n",nums[blood_name[i]]);
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
using namespace std;

int main(){
  int m,f,r,sum;
  while( true ){
    scanf("%d %d %d", &m, &f, &r);
    sum = m + f;
    if(m == -1 && f == -1 && r == -1) break;
    if(m == -1 || f == -1 || sum < 30){
      printf("F\n");
    }
    else if(sum >= 80){
      printf("A\n");
    }
    else if(sum >= 65){
      printf("B\n");
    }
    else if(sum >= 50 || r >= 50){
      printf("C\n");
    }
    else{
      printf("D\n");
    }
  }
}

Measured memory_bytes: 1012
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 998244353;

ll mod_pow(ll x,int e){
  return e?e&1? x*mod_pow(x,e-1)%MOD:mod_pow(x*x%MOD,e/2):1;
}

ll dp[310][310*310];
ll a[310];
ll sum[310];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  repeat(i,N){
    cin>>a[i];
    sum[i+1] =sum[i]+ a[i];
  }
  dp[0][0]=1;
  repeat(i,N){
    repeat(j,sum[N]-a[i]+1){
      dp[i+1][j+a[i]] = (dp[i+1][j+a[i]]+dp[i][j])%MOD;
      dp[i+1][j] = (dp[i+1][j]+2*dp[i][j])%MOD;
    }
    //debugArray(dp[i],sum[N]+1);
  }
  ll ans=0;
  for(int j=(sum[N]+1)/2;j<=sum[N];j++){
    ans = (ans+3*dp[N][j])%MOD;
  }
  if(!(sum[N]&1)){
    repeat(i,N){
      repeat(j,sum[N]+1){
        dp[i+1][j]=0;
      }
    }
    repeat(i,N){
      repeat(j,sum[N]-a[i]+1){
        dp[i+1][j+a[i]] = (dp[i+1][j+a[i]]+dp[i][j])%MOD;
        dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
      }
    }
    ans = (ans-3*dp[N][sum[N]/2]+MOD)%MOD;
  }
  //debug(ans);
  ans = (mod_pow(3,N)-ans+MOD)%MOD;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 226816
while 1:
    n,p = map(int,input().split())
    if n==0:break
    man =  [0]*n
    ball,a = p,0
    while 1:
        a%=n
        if ball >0:
            ball-=1
            man[a]+=1
        elif ball == 0:ball,man[a] = man[a],ball
        if man[a]==p:break
        a+=1
    print(man.index(max(man)))        

Measured memory_bytes: 7544
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    int i, x;

    n = sc.nextInt();

    for(i = 0;i < n;i++){
      x = i + 1;
      if(x % 3 == 0){
        System.out.print(" " + x);
      }else{
        for(;;){
          if(x % 10 == 3){
            System.out.print(" " + (i + 1));
            break;
          }else{
            x /= 10;
            if(x == 0)break;
          }
        }
      }
    }
    System.out.println();

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 24268
/*  ex3_4
    kosaq       */

#include <stdio.h>

int main(void){
    int number;    // the number of N
    int i;    //count how many times it looped
    scanf("%d", &number);    //input N

    for(i = 1; i < 10; i++){
        if(number % i == 0 && number / i < 10){    //N can devide into two numbers(1 ~ 9)
            printf("Yes\n");    //output Yes
            break;
        }
    }
    if(i == 10){    //if N can't devide 
        printf("No\n");    //output No
    }
    return 0;
}



Measured memory_bytes: 256
// A - Security

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int main(){
	string S;
	cin >> S;

	string ans = "Good";
	for (int i=0; i<S.size()-1; i++) {
		if (S[i] == S[i+1]) ans = "Bad";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ff first
#define ss second
#define int long long
#define all(x) (x).begin(), (x).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define eb emplace_back
#define inf INT64_MAX;
#define pii pair<int, int>

using namespace std;

const int mxn = 1e5 + 5;
int n, dp[mxn][3] = {};
vector<vector<int>> h(mxn, vector<int>(3));

void solve()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> h[i][0] >> h[i][1] >> h[i][2];
    for (int i = 0; i < 3; i++)
        dp[0][i] = h[0][i];
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + h[i][0];
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + h[i][1];
            dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + h[i][2];
        }
    }
    cout << *max_element(dp[n - 1], dp[n - 1] + 3);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // int t;
    // cin >> t;
    // while (t--)
    solve();
    return 0;
}

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

typedef long long int ll;
typedef long double ld;

#define Pb push_back
#define Mp make_pair

#define ff first
#define ss second

#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))

#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;


void solve()
{
  string s,t;
  cin >> s >> t;
  int n = t.size() - 1;
  t = t.substr(0,n);
  if(s == t)  cout << "Yes";
  else cout << "No";
}

signed main()
{
  IOS;
  //freopen("input.txt", "rt", stdin);
  //freopen("output.txt", "wt", stdout);
  int t=1;
  //cin >> t;
  while(t--)
  {
    solve();
  }
  return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 3652
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n;
bool market[365][16];
bool V[366][2401][9];

bool check(int day,int y,int x)
{
	rep(i,2)rep(j,2)if(market[day][(y+i)*4+x+j])return 0;
	return 1;
}
bool visit(int day,int y,int x,int r0,int r1,int r2,int r3)
{
	bool &v=V[day][343*r0+49*r1+7*r2+r3][y*3+x];
	if(v)return 1;
	
	v=1;
	return 0;
}
bool dfs(int day,int cy,int cx,int r0,int r1,int r2,int r3)
{
	if(day>=n)return 1;
	
	for(int ny=cy-2;ny<=cy+2;ny++)for(int nx=cx-2;nx<=cx+2;nx++)
	if(ny==cy||nx==cx)
	if(0<=ny&&ny<3&&0<=nx&&nx<3)
	{
		if(!check(day,ny,nx))continue;
		int nr0=r0,nr1=r1,nr2=r2,nr3=r3;
		if(ny==0&&nx==0)nr0=0; else nr0++;
		if(ny==0&&nx==2)nr1=0; else nr1++;
		if(ny==2&&nx==0)nr2=0; else nr2++;
		if(ny==2&&nx==2)nr3=0; else nr3++;
		
		if(nr0>=7||nr1>=7||nr2>=7||nr3>=7)continue;
		if(visit(day+1,ny,nx,nr0,nr1,nr2,nr3))continue;
		if(dfs(day+1,ny,nx,nr0,nr1,nr2,nr3))return 1;
	}
	return 0;
}
int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,n)rep(j,16)scanf("%d",market[i]+j);
		rep(i,n+1)rep(j,2401)fill_n(V[i][j],9,0);
		
		if(!check(0,1,1))
		{
			cout<<0<<endl; continue;
		}
		cout<<dfs(1,1,1,1,1,1,1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 8652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
class SCC{//cmp(0 - kk-1) is scc's return. Same number is group. The number is no relatoin.
	public:
	int n;
	vvi G;
	vvi rG;
	vector<bool>used;
	vi vs;
	vi cmp;
	SCC(int size){
		n=size;
		G=rG=vvi(n);
		used=vector<bool>(n);
		cmp=vi(n);
		vs=vi(0);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
		rG[t].pb(s);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		rep(i,rG[v].size())if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	void dfs(int v){
		used[v]=true;
		rep(i,G[v].size())if(!used[G[v][i]])dfs(G[v][i]);
		vs.pb(v);
	}
	int scc(){
		rep(i,n)used[i]=false;
		rep(v,n)if(!used[v])dfs(v);
		rep(i,n)used[i]=false;
		int kk=0;
		for(int i=vs.size()-1;i>=0;i--)if(!used[vs[i]])rdfs(vs[i],kk++);
		return kk;  
	}
};
struct edge{
	int to,cost;
};
class MCA{
	public:
	int n,r;
	vector<vector<edge> >G,rG,tG,trG;
	vector<bool>used;
	MCA(int size,int R){
		r=R;
		n=size;
		rG=G=vector<vector<edge> >(n);
	}
	void add_edge(int s,int t,int cost){
		edge e={t,cost},ee={s,cost};
		G[s].pb(e);rG[t].pb(ee);
	}
	void dfs(int s){
		used[s]=true;
		rep(i,tG[s].size())if(!used[tG[s][i].to])dfs(tG[s][i].to);
	}
	int mca(){
		tG=trG=vector<vector<edge> >(n);
		rep(i,n)if(i!=r){
			int mi=inf;
			rep(j,rG[i].size())mi=min(mi,rG[i][j].cost);
			rep(j,rG[i].size())if(mi==rG[i][j].cost){
				edge e={i,rG[i][j].cost};
				tG[rG[i][j].to].pb(e);
				trG[i].pb(rG[i][j]);
				break;
			}
		}
//		rep(i,n)rep(j,trG[i].size())cout<<i<<" "<<trG[i][j].to<<" "<<trG[i][j].cost<<endl;
		used=vector<bool>(n);
		dfs(r);
		bool h=true;
		rep(i,n)if(!used[i])h=false;
		if(h){//connect
			int sum=0;
			rep(i,n)rep(j,tG[i].size())sum+=tG[i][j].cost;
			return sum;		
		}else{// not connect
			SCC scc(n);
			rep(i,n)rep(j,tG[i].size())scc.add_edge(i,tG[i][j].to);
			int N=scc.scc();
			MCA mca(N,scc.cmp[r]);
			int sum=0;
			rep(i,n)rep(j,tG[i].size())if(scc.cmp[i]==scc.cmp[tG[i][j].to])sum+=tG[i][j].cost;
			rep(i,n)rep(j,G[i].size())if(scc.cmp[i]!=scc.cmp[G[i][j].to]){
				bool h=false;
				int To=G[i][j].to;//i -> To
				rep(k,n)if(To!=k&&scc.cmp[To]==scc.cmp[k])h=true;
				if(h){
					mca.add_edge(scc.cmp[i],scc.cmp[To],G[i][j].cost-trG[To][0].cost);
				}else{
					mca.add_edge(scc.cmp[i],scc.cmp[To],G[i][j].cost);
				}
			}
//			rep(i,N)rep(j,mca.G[i].size())cout<<i<<" "<<mca.G[i][j].to<<" "<<mca.G[i][j].cost<<endl;
			return sum+mca.mca();
		}
		return false;
	}
};
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	MCA mca(n,k);
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		mca.add_edge(a,b,c);
	}
	cout<<mca.mca()<<endl;
}
 


 
 

Measured memory_bytes: 2300
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> b(n);
  for(int i=0;i<n;i++){
    b.at(i)=0;
  }
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      b.at(a-1)++;
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(b.at(i)==0) ans++;
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
arr = list(map(int, input().split()))

if n == 1:
    if k % 2:
        print(*arr)
    else:
        print(*[])
    exit()

table = {}
original_table = {}
move = {}

for i, a in enumerate(arr):
    if a not in table:
        table[a] = i
        original_table[a] = i
    else:
        move[table[a]], move[i] = i + 1, original_table[a] + 1
        table[a] = i

res = {}
idx = 0

for i in range(1, k + 1):
    while idx in move and move[idx] > idx:
        idx = move[idx]

    res[i] = idx
    if idx == len(arr):
        k %= len(res)
        if not k:
            k = len(res)
        break

    if idx in move:
        idx = move[idx]
    else:
        idx += 1

idx = res[k]
response = []

while idx < len(arr):
    while idx in move and move[idx] > idx:
        idx = move[idx]
    if idx < len(arr):
        response.append(arr[idx])
    idx += 1

print(*response)


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

int main()
{
    int t = 5;
    int ans;
    for (int i = 0; i < t; i++)
    {
        cin >> ans;
        if (ans == 0)
        {
            cout << i+1 << endl;
            break;
        }
    }
    

    return 0;
}

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

using namespace std;

int conv(char x){
	if (x == '+'){
		return 1;
	} else {
		return -1;
	}
}

int main() {
	string S;
	cin >> S;

	cout << conv(S[0]) + conv(S[1]) + conv(S[2]) + conv(S[3]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b != c) {
        cout << "Yes" << endl;
        return 0;
    }
    if (b == c && c != a) {
        cout << "Yes" << endl;
        return 0;
    }
    if (a == c && c != b) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  long N, T;
  cin >> N >> T;
  vector<long> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  V.push_back(1e10);

  long ans = 0;
  for (int i = 0; i < N; i++) ans += min(T, V.at(i + 1) - V.at(i));
  cout << ans << "\n";
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if((a-b)>=c){
        cout << 0 << endl;
    } else {
        cout << c-(a-b) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <map>

template <typename T>
void read(T& x)
{
    x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar());
    for (; isdigit(c); x = x * 10 + (c ^ 48), c = getchar());
}

int n, k;
double a[200010], s[200010];

int main()
{
    std::ios::sync_with_stdio(0);
    read(n); read(k);
    for (int i = 1; i <= n; ++i)
        read(a[i]);
    for (int i = 1; i <= n; ++i)
    {
        s[i] = s[i - 1];
        s[i] += (1.0 + a[i]) / 2.0;
    }
    double ans = 0;
    for (int i = k; i <= n; ++i)
    {
        ans = std::max(ans, s[i] - s[i - k]);
    }
    printf("%.7f\n", ans);
    return 0;
}

Measured memory_bytes: 3456
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep4(i, a, b, c) for (int i = int(a), i##__b = int(b), i##__c = int(c); i < i##__b; i += i##__c)
#define rep1(n) rep4(i, 0, n, 1)
#define rep2(i, n) rep4(i, 0, n, 1)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define REP(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep3(i, a, b) for (int i = int(b) - 1, i##__a = int(a); i >= i##__a; i--)
#define rrep1(n) rrep3(i, 0, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep4(i, a, b, c) for (int i = int(a + (b - a - 1) / c * c), i##__a = int(a), i##__c = int(c); i >= i##__a; i -= i##__c)
#define RREP(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define FOREACH(i, x) for (auto &i : x)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define mt make_tuple
#define print(x) cout << x << endl;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 9;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using vstring = vector<string>;
template <class T> using vv = vector<vector<T>>;
template <class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return 1;}return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return 1;}return 0;}

struct Point {int x, y; Point(int x, int y):x(x), y(y){}};
int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1};
pii dvs[] = {mp(1, 0), mp(0, 1), mp(-1, 0), mp(0, -1)};
// clang-format on


int main() {
    int N;
    cin >> N;
    int ans = 0;
    REP(k, 1, N + 1, 2) {
        int yakusu = 0;
        REP(i, 1, k + 1) {
            if (k % i == 0) {
                yakusu++;
            }
        }
        if (yakusu == 8) {
            ans++;
        }
    }
    print(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int N,M,T;cin>>N>>M>>T;
        //if(N+M==0) break;
        
        vector<int> A(N);
        
        for(int i=0;i<N;i++) cin>>A[i];
        
        int ans=max(0,A[0]-M);
        
        for(int i=1;i<N;i++){
            ans+=max(0,A[i]-A[i-1]-2*M);
        }
        ans+=max(0,T-A[N-1]-M);
        cout<<ans<<endl;
        
        return 0;
        
    }
}



Measured memory_bytes: 3220
#include <stdio.h>
#include <stdlib.h>

int h[1000000];
int main(void)
{
   int n;
    int answer,i,j,max;
    max=0;
    int num=0;
answer=0;
    scanf("%d",&n);

    for(i=0; i<n; i++)
    {
         scanf("%d",&h[i]);
    }


for(i=n-2; i>=0; i--)
{
    if(h[i]>=h[i+1])
    {
        num+=1;
    }else 
    {
        if(num>max)
        {
            max=num;
        }
        num=0;
    }
}

if(num>max)
        {
            max=num;
        }

printf("%d",max);

   
    
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include<math.h>
int main(void) {
double a,b,c,d;
double e;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
e=(a-c)*(a-c)+(b-d)*(b-d);
e=sqrt(e);
printf("%f",e);
  return 0;
}


Measured memory_bytes: 2108
import math
import queue
from collections import defaultdict
 
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def printQueue(q):
	r=q
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)

N = readInt()

s = list(str(N))

if "7" in s:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 9644
#!/usr/bin/env python
# coding: utf-8

# In[11]:


import itertools


# In[20]:


N = int(input())
S = {}
S["M"] = 0
S["A"] = 0
S["R"] = 0
S["C"] = 0
S["H"] = 0
for _ in range(N):
    tmp = input()
    if tmp[0] == "M":
        S["M"] += 1
    elif tmp[0] == "A":
        S["A"] += 1
    elif tmp[0] == "R":
        S["R"] += 1
    elif tmp[0] == "C":
        S["C"] += 1
    elif tmp[0] == "H":
        S["H"] += 1


# In[21]:


ans = 0
for myset in list(itertools.combinations("MARCH",3)):
    ans += S[myset[0]]*S[myset[1]]*S[myset[2]]
print(ans)


# In[ ]:






Measured memory_bytes: 9240
a, b, c, d = map(int, input().split())

if a % d == 0:
    n_a = a // d
else:
    n_a = a // d + 1

if c % b == 0:
    n_c = c // b
else:
    n_c = c // b + 1

if n_a >= n_c:
    print("Yes")
else:
    print("No")

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

int main() { 
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0;i < N;i++){
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(N / 2) - d.at(N / 2 - 1) <<endl;
}

Measured memory_bytes: 640
import sys
X = int(input())

def isPrime(n):
  if n < 2:
    return False
  if n == 2:
    return True
  for p in range(2, n):
      if n % p == 0:
        return False
  return True

while True:
    if isPrime(X):
        print(X)
        sys.exit()
    else:
        X += 1

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

#define ff              first
#define ss              second
#define endl 			"\n"
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerbefone(x)    __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define Pi 				acos(-1.0)
#define precise(x,y)    fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	FIO;
	int tt = 1;
	// cin >> tt;
	while (tt--)
	{
		int n, k;
		cin >> n >> k;
		vector<int> v(n + 1);
		int ans[n + 1];
		for (int i = 1; i <= n; i++)
		{
			cin >> v[i];
			ans[i] = 1e9;
		}
		ans[1] = 0;
		for (int i = 2; i <= n; i++)
		{
			for (int j = 1; j <= k; j++)
			{
				if (j >= i) break;
				else
				{
					ans[i] = min(ans[i], abs(v[i] - v[i - j]) + ans[i - j]);
				}
			}
		}
		cout << ans[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 4812
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int n = s.length();

    int len = 3;
    int tar = 753;
    int res = 1 << 28;
    for (int i = 0; i + len <= n; ++i) {
        string ss = s.substr(i, len);
        int x = stoi(ss);
        res = min(res, abs(x - tar));
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
/*input
4 3
-1 -2 -3 -4
*/

#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll k,m;
	cin>>m>>k;
	vll a;
	ll cz=0;
	rep(i,0,m){cin>>j;if(j)a.pb(j);else cz=1;}
	sort(a.rbegin(),a.rend(),[](ll &b,ll &c){
		return abs(c)>abs(b);
	});
	if((ll)a.size()<k){
		cout<<0<<endl;
		return;
	}
	vll n,p;
	rep(i,0,k){
		if(a[i]<0)n.pb(a[i]);
		else p.pb(a[i]);
	}
	if((((ll)n.size())%2)==0){
		ll ans=1;
		for(auto i : p)ans*=i,ans%=M;
		for(auto i : n)ans*=(-i),ans%=M;
		cout<<ans<<endl;
		return;
	}
	ll ap=0,an=0;
	rep(i,k,(ll)a.size()){
		if(a[i]>0){
			ap=a[i];
			break;
		}
	}
	rep(i,k,(ll)a.size()){
		if(a[i]<0){
			an=a[i];
			break;
		}
	}
	if((!ap&&!an) || (!ap&&(ll)p.size()==0)){
		if(cz){
			cout<<0<<endl;
			return;
		}
		ll ans=1;
		reverse(a.begin(),a.end());
		rep(i,0,k){ans*=abs(a[i]),ans%=M;}
		cout<<M-ans<<endl;
		return;
	}
	if(p.size()==0 || abs(an)*abs(n[(ll)n.size()-1]) < ap*p[(ll)p.size()-1]){
		ll ans=1;
		rep(i,0,(ll)n.size()-1)ans*=abs(n[i]),ans%=M;
		for(auto i : p)ans*=i,ans%=M;
		ans*=ap;
		ans%=M;
		cout<<ans<<endl;
	}else{
		ll ans=1;
		rep(i,0,(ll)p.size()-1)ans*=p[i],ans%=M;
		for(auto i : n)ans*=abs(i),ans%=M;
		ans*=abs(an);
		ans%=M;
		cout<<ans<<endl;
	}
	

}

int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 8084
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 998244353;
const ll inf = 0x3f3f3f3f;
const ll maxn = 1e5 + 5;
const ll N=1e3+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;

int main(){
    string s;
    cin>>s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R') cout<<"3"<<endl;
    else if((s[0]=='R'&&s[1]=='R')||(s[1]=='R'&&s[2]=='R')) cout<<'2'<<endl;
    else if(s=="SSS")cout<<'0'<<endl;
    else cout<<"1"<<endl;
}

Measured memory_bytes: 3620
hotel=int(input())
hotel2=int(input())
hotel3=int(input())
hotel4=int(input())

if hotel > hotel2:
	sum1=int(hotel2)*int(hotel3)
	hotel5=int(hotel)-int(hotel2)
	sum2=int(hotel5)*int(hotel4)
	fee=int(sum1)+int(sum2)
else:
  fee=int(hotel)*int(hotel3)
 
print(str(fee))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

double getLength(double const& x1, double const& x2, double const& y1,double const& y2){
    double len = std::sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    return len; 
}

int main(){
    double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	printf("%.8lf\n",getLength(x1, x2, y1, y2));
}


Measured memory_bytes: 3192
a,b,m = map(int,input().split())
la = list(map(int,input().split()))
lb = list(map(int,input().split()))
l = [list(map(int,input().split())) for i in range(m)]
ans = min(la)+min(lb)

for i,j,k in l:
    check = la[i-1]+lb[j-1]-k
    ans = min(ans,check)
print(ans)

Measured memory_bytes: 38560
#include <iostream>

using namespace std;

const int MAX=100;
const int INFTY=(1<<21);
const int WHITE=0;
const int GRAY=1;
const int BLACK=2;

int M[MAX][MAX];
int n;

void dijkstra(){
    int u,minv;
    int color[MAX],d[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }

    d[0]=0;

    while(true){
        minv=INFTY;
        u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i] and color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK and M[u][v]!=INFTY){
                if (d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }

    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==INFTY ? -1:d[i])<<endl;
    }

    return;
}

int main()
{
    cin>>n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]= INFTY;
        }
    }

    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }



    dijkstra();
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>

using namespace std;

void solve() {
    int a,b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    int sb, wb;
    sb = c; wb = f - sb + 1;
    for (int i = 0; i <= f; i += a * 100) {
        for (int j = 0; i + j <= f; j += b * 100) {
            int wat = i + j;
            int maxsug = min(e * (wat / 100), f - wat);
            for (int k = 0; k <= maxsug; k+=d) {
                for (int q =0; k + q <= maxsug; q += c) {
                    int sug = q + k;
                    if (sug * (sb + wb) > sb * (sug + wat)) {
                        sb = sug;
                        wb = wat;
                    }
                }
            }
        }
    }
    if (sb == c && wb == f-sb+1) {
        sb = 0;
        wb = a*100;
    }
    cout << wb + sb << " " << sb;


}

int main() {

	solve();
    return 0;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) {
        cin >> e;
    }
    int ans = 0;
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i-1]) {
            //cout << i << "\n";
            ++ans;
            if (i + 1 < n)
                a[i] = a[i+1] + 1;
        }
    }
    cout << ans;
    return 0;
}

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

#define int long long

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

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int a;
	cin >> a;

	cout << a + (a * a) + (a * a * a);	

	return 0;
}

Measured memory_bytes: 3628