akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

int C[51][51];

void comb(int N) {
	eREP(i, N) {
		eREP(j, i) {
			if (j == 0 || j == i) {
				C[i][j] = 1LL;
			}
			else {
				C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
			}
		}
	}
}

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

	int N, A,B;
	cin >> N >> A >> B;
	VI V(N);
	REP(i, N) {
		cin >> V[i];
	}
	comb(N);
	rSORT(V);
	double ans;
	REP(i, A) {
		ans += V[i];
	}
	ans /= A;
	int num = 0, pos = 0;
	REP(i, N) {
		if (V[i] == V[A - 1]) {
			num++;
			if (i < A) {
				pos++;
			}
		}
	}
	int cnt = 0;
	if (pos == A) {
		for (pos = A; pos <= B; pos++) {
			cnt += C[num][pos];
		}
	}
	else {
		cnt += C[num][pos];
	}
	cout.precision(20);
	cout << fixed << ans << endl;
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

string s;
int dp[111111][2];

int main()
{
	while (cin >> s)
	{
		if (s == "#") break;
		REP(i, s.size())REP(j, 2) dp[i][j] = (i == 0 ? 0 : INF);
		FOR(i, 1, s.size())
		{
			int t = (s[i] - '1') % 3;
			int p = (s[i - 1] - '1') % 3;
			dp[i][0] = dp[i - 1][0] + 1;
			dp[i][1] = dp[i - 1][1] + 1;
			if (t <= p) dp[i][0] = min(dp[i][0], dp[i - 1][1]);
			if (t >= p) dp[i][1] = min(dp[i][1], dp[i - 1][0]);
		}
		cout << min(dp[s.size()-1][0], dp[s.size()-1][1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 2104
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')


#import numpy as np

def main():
	x,y,z=MI()
	print(z,x,y)





if __name__ == "__main__":
	main()

Measured memory_bytes: 9164
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct City {
    int index;
    int prefecture;
    int year;
};

bool sort_by_year(City& a, City& b) { return a.year < b.year; }

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

    vector<City> cities(m);
    for (int i = 0; i < m; ++i) {
        cin >> cities[i].prefecture >> cities[i].year;
        cities[i].index = i;
    }

    sort(cities.begin(), cities.end(), sort_by_year);
    vector<int> city_count(n + 1);
    vector<string> id(m);
    for (int i = 0; i < m; ++i) {
        int index = cities[i].index;
        ++city_count[cities[i].prefecture];

        char buffer[13];
        sprintf(buffer, "%06d%06d", cities[i].prefecture,
                city_count[cities[i].prefecture]);
        id[index] = buffer;
    }

    for (int i = 0; i < m; ++i)
        cout << id[i] << '\n';
}


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

mincount=s[1:].count('E')
ans=mincount

# それぞれをリーダーとして試算する
for i in range(1,n):
    # リーダーより左のWの数を累積していく
    if s[i]=="E":
        mincount-=1
    if s[i-1]=="W":
        mincount+=1
    ans=min(ans,mincount)
print(ans)

Measured memory_bytes: 3784
k = int(input())
import numpy as np
ans = np.array([i for i in range(50)],dtype=np.int64)

a = k//50
b = k%50

ans += a
for i in range(b):
    ans[i] += 50
    ans[:i] -= 1
    ans[i+1:] -= 1
print(50)
print(' '.join(map(str, ans)))

Measured memory_bytes: 13352
#include<stdio.h>

int dp[50];

int fib(int num);

int main(void)
{
  int num,i;

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

  scanf("%d",&num);

  printf("%d\n",fib(num));

  return 0;
}

int fib(int num)
{
  if(num==0||num==1)
    {
      return dp[num]=1;
    }

  if(dp[num]!=-1)
    {
      return dp[num];
    }

  return dp[num]=fib(num-1)+fib(num-2);
}



Measured memory_bytes: 2108
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}

//}}}

// -------------------- Spliters ------------------------
const int maxn = 100100;

#define R 0
#define C 1

struct E {
	bool rc;
	int len;
	bool operator<(const E& b) const {
		return len < b.len;
	}
} a[maxn * 2];

int main() {
	ios::sync_with_stdio(0);
	ll W, H;
	cin>>W>>H;
	rep(i, 0, W) {
		cin>>a[i].len;
		a[i].rc = R;
	}
	rep(i, 0, H) {
		cin>>a[W + i].len;
		a[W + i].rc = C;
	}
	sort(a, a + W + H);
	int rr = 0, cc = 0;
	ll ans = 0;
	rep(i, 0, W + H) {
		if(a[i].rc == R) {
			rr++;
			ans += (H + 1 - cc) * a[i].len;
		} else if(a[i].rc == C) {
			cc++;
			ans += (W + 1 - rr) * a[i].len;
		}
	}
	cout<<ans<<endl;
	return 0;
}
// --USE C++11
// *-USE O2


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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int n, k, a[ N ];
 int check( int v )
 {
  int P = 0;
  For( i, 1, n )
  {
   int b = a[ i ] / v;
   if( b * v < a[ i ] )
    P += b;
   else
    P += b - 1;
  }
  return P;
 }
 void Fakemain( )
 {
  IOS;
  cin >> n >> k;
  For( i, 1, n )
   cin >> a[ i ];
  int L = 1, R = 1e9, ans = -1;
  while( L <= R )
  {
   int mid = L + R >> 1;
   if( check( mid ) <= k )
    ans = mid, R = mid - 1;
   else
    L = mid + 1; 
  }
  cout << ans;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
int ans[102][102];
int main()
{
	int a,b;
	char x[102][102];
	cin>>a>>b;
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			cin>>x[i][j];
			if(x[i][j]=='#')
			{
				ans[i-1][j+1]++;
				ans[i-1][j]++;
				ans[i-1][j-1]++;
				ans[i][j-1]++;
				ans[i][j+1]++;
				ans[i+1][j-1]++;
				ans[i+1][j]++;
				ans[i+1][j+1]++; 
			}	
		} 
	}
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			if(x[i][j]=='#')cout<<"#";
			else cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
 }


Measured memory_bytes: 256
class Main{
	public static void QQspecify(){
		for(int i=1;i<=9;i++){
			for(int j=1;j<=9;j++){
				System.out.println(i+"x"+j+"="+i*j);
			}
		}
	}
    public static void main(String[] a){
	QQspecify();

    }
}

Measured memory_bytes: 24180
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> goods;
    for (int i = 0; i < N; i++) {
        int temp;
        cin >> temp;
        goods.push(temp);
    }
    for (int i = 0; i < M; i++) {
        int value = goods.top();
        goods.pop();
        value /= 2;
        goods.push(value);
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += goods.top();
        goods.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>

using namespace std;

int main()
{
    unsigned long n, t, a;
    cin >> n;


    vector<unsigned long> vmax = vector<unsigned long>(n, 0);
    vector<bool> vt = vector<bool>(n, false);
    vector<unsigned long> abuf = vector<unsigned long>(n, 0);
    vector<bool> va = vector<bool>(n, false);

    unsigned long bef = 0;
    for (unsigned long i = 0; i < n; i++) {
        unsigned int x;
        cin >> x;
        vmax.at(i) = x;

        if (bef < x) vt.at(i) = true;
        bef = x;
    }

    for (unsigned long i = 0; i < n; i++) {
        cin >> abuf.at(i);
    }

    bef = 0;
    for (unsigned long j = 0; j < n; j++) {
        unsigned long i = n - j - 1;
        unsigned int x = abuf.at(i);

        if (bef < x) {
            va.at(i) = true;

            // tの結果に矛盾しないか？
            if (vmax.at(i) < x) {
                cout << 0 << endl;
                return 0;
            }
            if (vt.at(i)) {
                if (vmax.at(i) != x) {
                    cout << 0 << endl;
                    return 0;
                }
            }
            vmax.at(i) = x;
        } else {
            if (vmax.at(i) > x) {
                // cout << "write:" << j << i << endl;
                vmax.at(i) = x;
            }
        }
        bef = x;
    }

    unsigned long possibilities = 1;
    for (unsigned long i = 0; i < n; i++) {
        // cout << vmax.at(i) << " " << vt.at(i) << " " << va.at(i) << endl;
        if (vt.at(i) || va.at(i)) {
            // do nothing
        } else {
            possibilities *= vmax.at(i);
            possibilities %= 1000000007;
        }
    }
    cout << possibilities << endl;


    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<cmath>
//#include<windows.h>
#include<algorithm>
#include<set>
const double eps = 1e-1;
using namespace std;
typedef long long ll;

int n,e[] = {3,5,7},len,ans,dig[12];
bool t[10];
char a[13];

void dfs(int d){
    if(d>len+1)return;
    if(d>3){
        int sum=0;
        int cnt=0;
        set<int>s;
        for(int i=1;i<d;i++){
            sum = sum*10+dig[i];
            s.insert(dig[i]);
        }
        if(s.size()==3&&sum<=n){
            ans++;
//            cout<<sum<<endl;
        }
        s.clear();
    }

    for(int i=0;i<3;i++){
            dig[d] = e[i];
            dfs(d+1);
    }
}
int main(){
    scanf("%d",&n);
    sprintf(a,"%d",n);

    len = strlen(a);
//    cout<<len<<endl;
    dfs(1);
    printf("%d\n",ans);
    return 0;
}
//Hello World Here I Come
//          0                 10
//        0 1 1                8
//      0 1 1 2 3              6
//    0 1 1 2 3 5 8            4
//  0 1 1 2 3 5 8 13 21        2
//0 1 1 2 3 5 8 13 21 34 55    0


Measured memory_bytes: 256
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]

def check(x,y,S):
    cnt = 0
    for dx in range(-1,2):
        for dy in range(-1,2):
            sx = x + dx
            sy = y + dy
            if sx < 0 or sx >= H or sy < 0 or sy >= W:
                continue
            if S[sx][sy] == "#":
                cnt += 1
    S[x][y] = str(cnt)
    return S

for y in range(W):
    for x in range(H):
        if S[x][y] == "#":
            continue
        S = check(x,y,S)
for i in S:
    print("".join(i))

Measured memory_bytes: 3188
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
BC = []

for _ in range(M):
    b, c = list(map(int, input().split()))
    BC.append((c, b))

BC.sort(reverse=True)

ans = 0
count = 0


for bc in BC:
    C, B = bc

    while True:
        if count == N:
            break
        if len(A) > 0 and A[-1] >= C:
            ans += A[-1]
            del A[-1]
            count += 1
        else:
            break

    if count == N:
        break
    if B <= N - count:
        ans += B*C
        count += B
    else:
        ans += (N-count) * C
        count += (N-count)

while True:
    if count == N:
        break
    if len(A) > 0:
        ans += A[-1]
        del A[-1]
        count += 1


print(ans)


Measured memory_bytes: 21416
#include<cstdio>
using namespace std;
int n,m;
char p[505][505],r[505][505],b[505][505],ch;
int main(){
	scanf("%d%d\n",&n,&m);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) scanf("%c",&p[i][j]);
		scanf("%c",&ch);
	}
	for (int i=1;i<=n;i++) r[i][1]='#';
	for (int i=1;i<=n;i++) b[i][m]='#';
	for (int i=1;i<=n;i+=2)
		for (int j=2;j<m;j++) r[i][j]='#';
	for (int i=2;i<=n;i+=2)
		for (int j=2;j<m;j++) b[i][j]='#';
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) 
			if ((p[i][j]=='#') || (r[i][j]=='#')) r[i][j]='#';
			else r[i][j]='.';
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) 
			if ((p[i][j]=='#') || (b[i][j]=='#')) b[i][j]='#';
			else b[i][j]='.';
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) printf("%c",r[i][j]);
		printf("\n");
	}
	printf("\n");
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++) printf("%c",b[i][j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,x,y;
  cin>>a>>b>>x>>y;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
}


Measured memory_bytes: 3788
//In the name of God

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

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

const int N = 21 , mod = 1e9+7;

int dp[N][1 << N] , a[N][N] , bt[1 << N][N] , cnt[1 << N] , good[N];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(9);
   int n;
   scanf("%d" , &n);
   for(int i = 0 ; i < n ; i++)
      for(int j = 0 ; j < n ; j++){
         scanf("%d" , &a[i][j]);
         good[i] += a[i][j] * (1 << j);
      }
   for(int i = 0 ; i < n ; i++)
      if(a[0][i])
         dp[0][1 << i] = 1;
   for(int i = 0 ; i < (1 << n) ; i++)
      for(int j = 0 ; j < n ; j++)
         if((1 << j) & i)
            bt[i][cnt[i]++] = (1 << j);
   for(int i = 1 ; i < n ; i++)
      for(int j = 0 ; j < (1 << n) ; j++){
         int x = j & good[i];
         for(int k = 0 ; k < cnt[x] ; k++){
            dp[i][j] += dp[i - 1][j ^ bt[x][k]];
            if(dp[i][j] > mod)
               dp[i][j] -= mod;
         }
      }
   printf("%d" , dp[n - 1][(1 << n) - 1]);
   return 0;
}


Measured memory_bytes: 350464
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <bitset>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

#define N 10

using namespace std;
int main(int argc, const char *argv[]){
    int n,m;
    cin >> n >> m;
    vector<int> s[m];
    vector<int> p(m);
    int k;
    rep(i,m) {
        cin >> k;
        rep(j,k){
            int _s; cin>>_s;
            s[i].push_back(_s-1);
        }
    }
    int ans=0;
    rep(i,m) cin >> p[i];
    rep(i,int(pow(2,n))){
        bitset<N> l;
        bitset<N> b(i);
        rep(j,m){
            bool t = false;
            rep(k,s[j].size()){
                if(b[s[j][k]]){t = t ^ true;/*cout<<"a"<<t<<"b";*/}
            }
            if(t!=bool(p[j])) break;
        if(j==(m-1)) ans++;
        }
    }
    co(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int k,n,a,ma=0;
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		ma=max(a,ma);
	}
	printf("%d",max(ma*2-k-1,0));
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let m: usize = read();
    
    let mut s: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..m {
        let k: usize = read();
        for _ in 0..k {
            let sij: usize = read();
            s[sij-1].push(i);
        }
    }

    let mut p: Vec<usize> = vec![0; m];
    for i in 0..m {
        p[i] = read();
    }

    let mut ans = 0;
    for i in 0..(1<<(n-1)+1) {
        let mut cnt: Vec<usize> = vec![0; m];
        for j in 0..n {
            if (i >> j) & 1 == 1 {
                for k in 0..s[j].len() {
                    cnt[s[j][k]] += 1;
                }
            }
        }
        let mut ok = true;
        for j in 0..m {
            if cnt[j] % 2 != p[j] {
                ok = false;
                break;
            }
        }
        if ok {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

using namespace std;

int main(void)
{
    int K, N, i;
    long S;
    cin >> K >> N;
    int A[N], D[N];
    for(i = 0; i < N; i++)
    {
        cin >> A[i];
    }

    for(i = 0; i < N; i++)
    {
        D[i] = (K + A[(i + 1)%N] - A[i])%K;
    }
    sort(D, D+N);
    S = 0;
    for(i = 0; i < N-1; i++)
    {
        S += D[i];
    }
    cout << S << endl;
    /*
    cerr << K <<" "<< N <<endl;
    for(i = 0; i < N; i++)
    {
        cerr << A[i] << " ";
    }
    cerr << endl;
    for(i = 0; i < N; i++)
    {
        cerr << D[i] << " ";
    }
    cerr << endl;
    */
    return 0;
}


Measured memory_bytes: 1792
a=65280; b=61680; c=52428; d=43690; e=65535
from heapq import heappush, heappop
base = [a, b, c, d, e, 0]
Q = [(1, el) for el in base]
L = {el: 1 for el in base}
H = []
get = L.get
push = H.append
while Q:
    l, p = heappop(Q)
    if L[p] < l: continue
    if l+1 < get(p ^ e, 17):
        L[p ^ e] = l+1
        if l+1 < 16: heappush(Q, (l+1, p ^ e))
    if l+3 < 16:
        for q, r in H:
            if l+r+3 <= 16:
                if l+r+3 < get(p & q, 17):
                    L[p & q] = l+r+3
                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))
                if l+r+3 < get(p ^ q, 17):
                    L[p ^ q] = l+r+3
                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))
            else: break
    if l < 7: push((p, l))
print(*map(L.__getitem__, eval("e&%s"%",e&".join(open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]))),sep='\n')

Measured memory_bytes: 8604
#include<stdio.h>

int main(void){
  int K,A,B;
  int wid;
  int rem;
  
  scanf("%d\n %d %d",&K,&A,&B);
  
  rem = A%K;
  K = K-rem;
  wid = B-A;
  
  if(K<=wid || rem == 0){
    printf("OK");
  }
  else{
    printf("NG");
  }
  
  return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

int main(){
    int ans=0;
    string S,T;
    cin >> S; 
    cin >> T;
    for(int i=0; i< S.size(); i++){
        if(S[i] != T[i]) ans++;
    }
    cout << ans << endl;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  int h[n];
  for(int i=0;i<n;i++){
    h[i]=0;
  }
  int num, v;
  for(int i=0; i<k; i++){
    cin >> num;
    for(int j=0; j<num; j++){
      cin >> v;
      h[v-1]++;
    }
  }
  int ans = 0;
  for(int i=0; i<n; i++){
    if(h[i]==0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
using namespace std;
#define abs(a) ((a)<0?-(a):(a))

void Strrev(char *p){
	char *q = p,c;
	while(*q)q++;
	q--;
	for(;p<q;p++,q--){
		c=*p;
		*p=*q;
		*q=c;
	}
}

int main(void){
	char s1[20], s2[20], str[20], *p, *q;
	int s,i,j,k,l,l1,l2,mmax=0;

	cin >> str;
	p = strstr(str, "iwi");
	*p = 0;
	strcpy(s1, str);
	strcpy(s2, p+3);
	Strrev(s2);
	l1 = strlen(s1);
	l2 = strlen(s2);
	
	for(i=0; i < (1 << l1); i++){
		for(j=0; j < (1 << l2); j++){
		if(l1 - __builtin_popcount(i) != l2-__builtin_popcount(j)) continue;
		for(k = 0, l = 0;; k++,l++){
			while(i >> k & 1 && s1[k]) k++;
			while(j >> l & 1 && s2[l]) l++;
			if(!s1[k]||!s2[l]) break;
			if(abs(s1[k] - s2[l]) == 1 || abs(s1[k] - s2[l]) == 2){}
			else break;
	   	}
		if(!s1[k]&&!s2[l]){
			mmax = max(mmax,(l1+l2+3-__builtin_popcount(i)-__builtin_popcount(j)));
			continue;
		}
}
	}
	cout << mmax<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

//?????§???
struct MaxFlow {
    struct Edge {
        int to, cap, rev;
        Edge() {};
        Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {};
    };
    int V;
    vector<vector<Edge>> G;
    vector<int> used;

    MaxFlow(int V) : V(V), G(V, vector<Edge>()), used(V){}

    void add_edge(int from, int to, int cap) {
        G[from].push_back({to, cap, (int)G[to].size()});
        G[to].push_back({from, 0, (int)G[from].size() - 1});
    }

    int dfs(int v, int t, int f) {
        if (v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s, int t) {
        int flow = 0;
        while (1) {
            // memset(used, 0, sizeof(used));
            used = vector<int>(V, 0);
            int f = dfs(s, t, INF);
            if (f == 0) return flow;
            flow += f;
        }
    }
};


int main(){
    int x, y, e;
    cin >> x >> y >> e;
    MaxFlow flow(x + y + 2);
    int source = x + y, sink = x + y + 1;
    rep(i, e) {
        int a, b;
        cin >> a >> b;
        b += x;
        flow.add_edge(a, b, 1);
    }
    rep(i, x) flow.add_edge(source, i, 1);
    rep(i, y) flow.add_edge(x+i, sink, 1);
    cout << flow.max_flow(source, sink) << endl;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1'000'000'007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


vvec<ll> CombTable(int N){
    vvec<ll> res(N+1, vec<ll>(N+1,0));
    rep(i,N+1)rep(j,i+1){
        if(j == 0 or j == i){
            res[i][j] = 1;
            continue;
        }
        res[i][j] = res[i-1][j-1] + res[i-1][j];
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> v(N);
    rep(i,N)cin >> v[i];
    sort(all(v), greater<>());
    long double ans = 0;
    rep(i,A)ans += v[i];
    ans /= A;
    auto C = CombTable(N);

    ll cnt = 0;
    // 全部同じ
    if(v[0] == v[A-1]){
        ll tmp = 0;
        rep(i,N)tmp += v[i] == v[0];
        for(int k = A; k <= min(B, tmp); k++){
            cnt += C[tmp][k];
        }
    }
    else{
        ll X = 0, Y = 0;
        rep(i,A){
            Y += v[i] == v[A-1]; //[0,A)にv[A-1]がいくつあるか
        }
        rep(i,N){
            X += v[i] == v[A-1];
        }
        cnt += C[X][Y];
    }

    cout << ans << endl;
    cout << cnt << endl;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main(){

	char S[100];

	cin >> S;

	if(S[0] == 65){
		printf("%c\n", 84);
	}
    if(S[0] == 84){
    	printf("%c\n", 65);
    }
    if(S[0] == 71){
    	printf("%c\n", 67);
    }
    if(S[0] == 67){
    	printf("%c\n", 71);
    }

  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
struct Elem {
	long long a, b;
};

Elem elems[200010];

bool compareA(const Elem &a, const Elem &b) {
	return a.a < b.a;
}

bool compareB(const Elem &a, const Elem &b) {
	return a.b < b.b;
}

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

	int mid = n / 2;
	
	sort(elems, elems + n, compareA);
	long long bottom;

	if (n % 2 == 1) {
		bottom = elems[mid].a;
	} else {
		bottom = elems[mid].a + elems[mid - 1].a;
	}
	
	sort(elems, elems + n, compareB);
	
	long long top;
	if (n % 2 == 1) {
		top = elems[mid].b;
	} else {
		top = elems[mid].b + elems[mid - 1].b;
	}
	
	long long ans = top - bottom + 1;
	printf("%lld\n", ans);
	
	return 0;
}


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

int main(void) {
	char S[4];
	scanf("%s", S);
	if(strcmp(S, "abc") == 0||strcmp(S,"acb")==0||strcmp(S,"bac")==0||strcmp(S,"bca")==0||strcmp(S,"cab")==0||strcmp(S,"cba")==0)
	printf("%s", "Yes");
		
	else
	printf("%s","No");	
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class A {
public:
  static void solve(istream &cin, ostream &cout) {
    char c;
    cin >> c;
    string temp = "aiueo";
    FOR(i, temp) {
      if (i == c) {
        cout << "vowel" << endl;
        return;
      }
    }
    cout << "consonant" << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  A solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

int main(){
    string s,t;
    cin >> s >> t;
    string rot=s;
    for(int i=0;i<s.size();i++){
        rotate_copy(s.begin(),s.begin()+i,s.end(),rot.begin());
        //cout << rot << endl;
        if(rot==t){
            cout << "Yes" <<endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k; cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int ans = 0;
  for(int i = 0; i < k; i++) ans += a[i];
  cout << ans << endl;
  return 0;
}

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




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

    vector<vector<double> > dp(n+1, vector<double>(n+1));
    dp[0][0] = 1.0;
    rep(i, n) {
        rep(j, i+1) {
            dp[i+1][j] += dp[i][j]*(1.0-p[i]);
            dp[i+1][j+1] += dp[i][j]*p[i];
        }
    }

    double ans=0;
    rep(i, n+1) {
        if(i > n/2) {
            ans += dp[n][i];
        }
    }

    cout << fixed << setprecision(10);
    cout << ans << '\n';
}

Measured memory_bytes: 70656
N, T = map(int, input().split())

cts = []
for n in range(N):
  c, t = map(int, input().split())

  cts.append( (c,t)) 

cts = [(c,t) for c,t in cts if t <= T]

cts = sorted(cts, key=lambda x:x[0])

if len(cts) >= 1:
  print(cts[0][0])
else:
  print('TLE')

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
ant = [a, b, c, d, e]
f = False

for i in range(0, 5):
    for ii in range(i + 1, 5):
        sa = ant[i] - ant[ii]
        if -sa <= k:
            continue
        else:
            print(":(")
            f = True
            break
    break

if f is False:
    print("Yay!")


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    string s, t; cin >> s >> t;
    int sn = s.size(), tn = t.size();
    vvi v(26);
    rep(i,sn){
        int c = s[i] - 'a';
        v[c].push_back(i);
    }
    rep(i,26){
        int lim = v[i].size();
        rep(j,lim) v[i].push_back(v[i][j]+sn);
    }
    ll ans = 0;
    int cur = -1;
    rep(i,tn){
        int c = t[i] - 'a';
        if(v[c].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        cur = *lower_bound(all(v[c]), cur);
        cur++;
        if(cur >= sn){
            ans += sn;
            cur -= sn;
        }
    }
    cout << ans + cur << endl;
    return 0;
}

Measured memory_bytes: 4584
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

typedef long double lld;

using namespace std;

lld _abs(lld x) {
    if (x < 0) return -x;
	return x;
}

lld sqr(lld x) {
   return x * x;
}

lld det(const vector<vector<lld>> a) {
	
	return a[0][0] * (a[1][1] * a[2][2] - a[1][2] * a[2][1]) -
	       a[1][0] * (a[0][1] * a[2][2] - a[2][1] * a[0][2]) +
		   a[2][0] * (a[0][1] * a[1][2] - a[0][2] * a[1][1]);
}

pair<lld, lld> find(lld x1, lld y1, lld x2, lld y2, lld x3, lld y3) {
	lld len1 = sqr(x1) + sqr(y1);
	lld len2 = sqr(x2) + sqr(y2);
	lld len3 = sqr(x3) + sqr(y3);	
	vector<vector<lld>> a = { {len1, y1, 1} ,  {len2, y2, 1}, {len3, y3, 1} };
	vector<vector<lld>> b = { {x1, len1, 1} ,  {x2, len2, 1}, {x3, len3, 1} };
	vector<vector<lld>> c = { {x1, y1, 1} ,  {x2, y2, 1}, {x3, y3, 1} };
	lld sx = 0.5 * det(a);
    lld sy = 0.5 * det(b);
	lld A = det(c);
	if (_abs(A) < 1e-9) return {0, 0};
	sx /= A;
	sy /= A;
	return {sx, sy};
	
	
}	

int main() {
	ios_base::sync_with_stdio(0);

    int n;
	cin >> n;
	vector<lld> x(n);
    vector<lld> y(n);
	
	for (int i = 0; i < n; ++i) {
	    cin >> x[i] >> y[i];
	}
	
	lld ans = -1;
	for (int i = 0; i < n; ++i) {
	    for (int j = i + 1; j < n;  ++j) {
		    lld xr = (x[i] + x[j]) / 2;
			lld yr = (y[i] + y[j]) / 2;
			lld res = 0;
			for (int l = 0; l < n; ++l) {
			    res = max(res, sqr(xr - x[l]) + sqr(yr - y[l]));
			}
			if (ans < 0 || ans >= res) {
			    ans = res;
			}
			
			
			for (int k = j + 1; k < n; ++k) {
				auto p = find(x[i], y[i], x[j], y[j], x[k], y[k]);
				lld xr = p.first;
				lld yr = p.second;
				lld res = 0;
			
				for (int l = 0; l < n; ++l) {
					res = max(res, sqr(xr - x[l]) + sqr(yr - y[l]));
				}
				if (ans < 0 || ans >= res) {
					ans = res;
				}
				
				
			}
			
		}
	}

    cout.precision(15);
	cout << sqrt(ans) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(c >= a && c <= b)
		printf("Yes\n");
		else
			printf("No\n");
}

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

int main()
{
    int a,b; cin >> a >> b;
    if (a > b) {
        rep(i,a) {
            cout << b;
        }
    } else if (b > a) {
        rep(i,b) {
            cout << a;
        }
    } else {
        rep(i,a) {
            cout << a;
        }
    }
    

    return 0;
}

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

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

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

    int l = s/100, r = s%100;

    bool is_yymm = 1<=r && r<=12;
    bool is_mmyy = 1<=l && l<=12;

    if(is_yymm && is_mmyy) cout << "AMBIGUOUS" << endl;
    else if(is_yymm) cout << "YYMM" << endl;
    else if(is_mmyy) cout << "MMYY" << endl;
    else cout << "NA" << endl;
    return 0;
}


Measured memory_bytes: 256
// STRIVER_79 
// Lets goto the next level 
// AIM 6* at CC and CM at CF *__* 

#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)(1e9 + 21)
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int long long
#define ll long long 
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define in(x) scanf("%intd", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define fi first
#define se second
#define kitna se
#define endl "\n"
#define pi pair<int, int>
#define LL long long 
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int nax =  (int)(1*1e5+10);

// int SPF[N+5];

// void SOF()
// {
//     SPF[1] = 1;
//     for (int i=2; i<N; i++)
//         SPF[i] = i;
//     for (int i=4; i<N; i+=2)
//         SPF[i] = 2;
 
//     for (int i=3; i*i<N; i++)
//         {
//         if (SPF[i] == i)
//             {
//             for (int kon=i*i; kon<N; kon+=i)
//                 if (SPF[kon]==kon)
//                    SPF[kon] = i;
//             }
//         }
// }
int a[nax];
int n; 
int dp[nax]; 
int k;
int func(int ind)
{
	if(ind==(n-1))
		return 0;
	else if(dp[ind]!=-1) return dp[ind];
	else
	{
		int ans = 1e9+5; 
		for(int i = 1;i<=k;i++)
		{
			if(ind+i<n)
				ans = min(ans,abs(a[ind+i]-a[ind]) + func(ind+i));

		}
		return dp[ind] = ans; 
	}

}





signed main(){

int t=1; 
//cin >> t;
// string s; 
// getline(cin,s);

while(t--)
{
    cin >> n >> k;
    for0(i,n) cin >> a[i]; 	
    ini(dp,-1); 
    cout << func(0); 

}

rr;
}

Measured memory_bytes: 6528
#n=int(input())
n,k=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

mod=10**9+7
ans=0
for kval in range(k,n+2):
    mx=kval*(2*n-kval+1)//2
    mn=kval*(kval-1)//2
    add=mx-mn+1
    ans=(ans+add) % mod

print(ans)



Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	if (S == "abc")cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
h,w,k = gets.chomp.split.map(&:to_i)
g = []
for i in 0...w
  g[i] = []
  for j in 0...w
    g[i][j] = 0
  end
end
for i in 0...w
  for j in 0...w
    next if j < i-1
    next if j > i+1
    for msk in 0...(1<<(w-1))
      next if (msk & (msk>>1)) > 0
      next if (j==i) && ((msk&(1<<i))>0 || (i>0 && (msk&(1<<(i-1)))>0))
      next if (j==i+1) && (msk&(1<<i))==0
      next if (j==i-1) && (msk&(1<<(i-1)))==0
      g[i][j] += 1
    end
  end
end
dp = []
for i in 0..h
  dp[i] = []
  for j in 0...w
    dp[i][j] = 0
  end
end
MOD = 1000000007
dp[0][0] = 1
for i in 0...h
  for j in 0...w
    for to in 0...w
      dp[i+1][to] += dp[i][j] * g[j][to] % MOD
      dp[i+1][to] %= MOD
    end
  end
end
puts dp[h][k-1]


Measured memory_bytes: 1788
N = int(input())
a = [0] + list(map(int, input().split()))
b = [0] * (N+1)

for i in range(N, 0, -1):
    mod = sum(b[i::i]) % 2
    if mod == a[i]:
        pass
    else:
        b[i] = 1
    
print(b.count(1))
for idx, n in enumerate(b):
    if n:
        print(idx, '', end='')

Measured memory_bytes: 8756
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<int> to[1005];
vector<int> bfs(int s) {
    int inf = TEN(8);
    vector<int> dist(N,inf),pre(N,-1);
    queue<int> q;
    dist[s] = 0;
    q.push(s);
    while(!q.empty()) {
        int v = q.front();q.pop();
        for(auto u: to[v]) {
            if(dist[u] != inf)
                continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    pair<int,int> best(inf, -1);
    for(int i = 0;i < N;i++) {
        if(i == s)
            continue;
        for(auto u: to[i]) {
            if(u == s) {
                best = min(best, make_pair(dist[i], i));
            }
        }
    }

    if(best.first == inf)
        return vector<int>(N+1);

    int v = best.second;
    vector<int> res;
    while(v != -1) {
        res.push_back(v);
        v = pre[v];
    }

    return res;
}

int main(void) {
    int M;
    cin>>N>>M;
    for(int i = 0;i < M;i++) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        to[a].push_back(b);
    }

    vector<int> ans(N+1);
    for(int i = 0;i < N;i++) {
        vector<int> now = bfs(i);
        if(now.size() < ans.size())
            ans = now;
    }

    if(ans.size() == N+1)
    {
        cout<<-1<<endl;
    } else {
        cout<<ans.size()<<endl;
        for(auto v: ans) {
            cout<<v+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){
	int i,j,k,m,n=10,ara[10];
	for(i=0;i<10;i++){
		scanf("%d",&ara[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=0;j<(n-i)-1;j++){
			if(ara[j]>ara[j+1]){
				k=ara[j];
				ara[j]=ara[j+1];
				ara[j+1]=k;
			}
		}
	}
	for(i=0,j=9;i<3;i++,j--){
		printf("%d\n",ara[j]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>

int solve(int n){
  for(int i=2; i<=sqrt(n); i++)
    if(n%i == 0){
      int ncopy = n;
      while(ncopy%i == 0)  ncopy /= i;
      if(ncopy == 1)  return 1;
    }
  return 0;
}

int main(){
  int n;  scanf("%d", &n);
  int ans = 1;
  for(int i=n; i>=1; i--)
    if(solve(i)){
      ans = i;
      break;
    }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNextInt()){
			long x=in.nextLong(), y = in.nextLong();
			System.out.println(gcd(x,y) + " " + lcm(x,y));
		}
	}

	private static long gcd(long a, long b){
		return (a==0)?b:gcd(b%a, a);
	}

	private static long lcm(long a, long b){
		return a*b/gcd(a,b);
	}

}

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
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;}
// head
const int N = 5e2+7;
const int M = 1e4 + 7;

int T,n,m,cnt;

bool vis[M];
int prime[M];

void getPrime()
{
    cnt = 0;
    rep(i,2,M-5){
        if(!vis[i])
            prime[++cnt] = i;
        for (int j = 1; i * prime[j] < M - 5;j++){
            vis[i * prime[j]] = 1;
            if(i%prime[j]==0) break;
        }
    }
}

ll ans[M][M];

int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    getPrime();
    scanf("%d", &n);
    if(n==2){
        printf("4 7\n23 10\n");
        return 0;
    }
    rep(i, 0, n + 2) rep(j, 0, n + 2) ans[i][j] = 1;
    rep(i,1,n+1){
        rep(j,1,n+1){
            if((i&1)==(j&1)){
                ans[i][j] = prime[(i + j) / 2] * prime[(i + n + 1 - j) / 2 + n];
                ans[i + 1][j] = lcm(ans[i + 1][j], ans[i][j]);
                ans[i - 1][j] = lcm(ans[i - 1][j], ans[i][j]);
                ans[i][j + 1] = lcm(ans[i][j + 1], ans[i][j]);
                ans[i][j - 1] = lcm(ans[i][j - 1], ans[i][j]);
            }
        }
    }
    rep(i,1,n+1)rep(j,1,n+1){
        if((i&1)!=(j&1)){
            printf("%lld", ans[i][j] + 1);
        }
        else{
            printf("%lld", ans[i][j]);
        }
        printf(j == n ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 42240
#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)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

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

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);
//const int INF=(1<<29);

int main(){
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  cout << max(0, h2*60+m2-h1*60-m1-k) << endl;
}



Measured memory_bytes: 3564