akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll H[N];
    REP(i, 0, N) {
        cin >> H[i];
    }
    sort(H, H + N);
    reverse(H, H + N);
    ll ans = 0;
    REP(i, K, N) {
        ans += H[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14
char H[M][L];
int getChar(char ch){
  if(ch=='A')
	return 1;
  else if(ch=='C')
	return 2;
  else if(ch=='G')
	return 3;
  else if(ch=='T')
	return 4;
  else 
	return 0;
}
long long getKey(char str[]){
  long long sum=0, p=1, i;
  for(i=0; i<strlen(str); ++i){
	sum+=p*(getChar(str[i]));
	p*=5;
  }
  return sum;
}
int h1(int key){
  return key % M;
}
int h2(int key){
  return (1+key%(M-1));
}
int find(char str[]){
  long long key, i, h;
  key=getKey(str);
  for(i=0; i<M; ++i){
	h=(h1(key)+i*h2(key))%M;
	if(strcmp(H[h], str)==0)
	  return 1;
	else if(strlen(H[h])==0)
	  return 0;
}
  return 0;
}
int insert(char str[]){
  long long key, i, h;
  key=getKey(str);
  for(i=0; i<M; ++i){
	h=(h1(key)+i*h2(key))%M;
	if(strcmp(H[h], str)==0)
	  return 1;
	else if(strlen(H[h])==0){
	  strcpy(H[h], str);
	  return 0;
	}
  }
  return 0;
}
int main(){
  int n;
  char line[50];
  int i;
  char *str_ptr;
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d", &n);
  for(i=0; i<n; ++i){
	fgets(line, sizeof(line), stdin);
	str_ptr=strtok(line, " ");
	if(strcmp(line, "insert")==0){
	  str_ptr=strtok(NULL, " ");
	  //改行文字の消去
	  if(str_ptr[strlen(str_ptr)-1]=='\n')
		str_ptr[strlen(str_ptr)-1]='\0';
	  //	  insert;
	  insert(str_ptr);
	}
	else if(strcmp(line, "find")==0){
	  str_ptr=strtok(NULL, " ");
	  //改行文字の消去
	  if(str_ptr[strlen(str_ptr)-1]=='\n')
		str_ptr[strlen(str_ptr)-1]='\0';
	  // find;
	  if(find(str_ptr)==1)  
		printf("yes\n");
	  else if(find(str_ptr)==0)
		printf("no\n");
	  
	}
  }
  return 0;
}



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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define INF 		2000000007
#define MINF		-2000000007
#define MAX 		100005

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

vector<vector<int>> edge(MAX);
int uesd[MAX];

void bfs(int s){
	queue<int> q;
	q.push(s);

	while(!q.empty()){
		int t = q.front();q.pop();
		for(int itr : edge[t]){
			if(uesd[itr]!=INF)continue;
			uesd[itr] = 1;
			q.push(itr);
		}
	}
}

// abc075
int main(){
	int N,M;cin>>N>>M;
	vector<P> t(M);
	REP(i,M){
		cin>>t[i].first>>t[i].second;
		--t[i].first,--t[i].second;
		edge[t[i].first].push_back(t[i].second);
		edge[t[i].second].push_back(t[i].first);
	}

	int cnt=0;
	REP(i,M){
		REP(j,N)uesd[j]=INF;
		uesd[t[i].first]=1;
		uesd[t[i].second]=1;
		bfs(t[i].first);
		int flag = true;
		for(int itr : edge[t[i].second]){
			if(itr==t[i].first)continue;
			if(uesd[itr] != INF){flag=false;break;}
		}
		if(flag)cnt++;
	}

	cout << cnt << endl;


	return 0;
}




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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
 Node n;
  
  if(u->key == k) return u;
  else if(u->key > k){
    if(u->left != NIL){
      n = treeSearch(u->left,k);
      if(n!=NIL) return n;  
    }
  }
  else if(u->key < k){
    if(u->right != NIL){
      n = treeSearch(u->right,k);
      if(n!=NIL) return n;
    }
  }
  return NIL;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL && z->right == NIL){
    if(z->parent->left == z) z->parent->left = NIL;
    else z->parent->right = NIL;
    free(z);
  }

  else if(z->left == NIL && z->right != NIL){
    if(z->parent->left == z) z->parent->left = z->right;
    else z->parent->right = z->right;

    z->right->parent=z->parent;
    
    free(z);
  }
  
  else if(z->left != NIL && z->right == NIL){
    if(z->parent->left == z) z->parent->left = z->left;
    else z->parent->right = z->left;

    z->left->parent=z->parent;
    
    free(z);
  }

  else{
    for(y = z->right ; y->left!=NIL ; y = y->left){}
    z->key = y->key;
    treeDelete(y);
  }

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  
}

void inorder(Node u){
  if(u->left != NIL) inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL) inorder(u->right);  
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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



int main() {
    double l;
    cin >> l;
    
    double ans = (l/3) * (l/3) * (l/3);
    
    cout << fixed << setprecision(7) << ans << endl;

    
    return 0;
}




Measured memory_bytes: 3760
#include <iostream>
#include <string>
#include <vector>

//# define DEBUG 0

using namespace std;

struct HandPoints
{
    int R, S, P;

    void ReadHP(void)
    {
        cin >> R >> S >> P;
    }
} hp;

int getPoints(char hand)
{
    if (hand == 'r')
        return hp.P;
    else if (hand == 's')
        return hp.R;
    else if (hand == 'p')
        return hp.S;
    else {
        return -999;
    }
}

int main(void)
{
    int N, K;
    string T;

    cin >> N >> K;
    hp.ReadHP();
    cin >> T;

    vector<int> max_score(N);
    vector<int> taken(K, false);

    max_score[0] = getPoints(T[0]);
    taken[0] = true;

#ifdef DEBUG
    printf("i: %d, T[i]: '%c'\n", 0, T[0]);
    printf("max_score: %d, taken: %d\n", max_score[0], taken[0 % K]);
#endif

    for (int i = 1; i < N; i++)
    {
        int score;

        if (taken[i % K] && (T[i] == T[i - K])) {
            score = 0;
            taken[i % K] = false;
        }
        else {
            score = getPoints(T[i]);
            taken[i % K] = true;
        }

        max_score[i] = max_score[i - 1] + score;

#ifdef DEBUG
        printf("i: %d, T[i]: '%c'\n", i, T[i]);
        printf("max_score: %d, taken: %d\n", max_score[i], taken[i % K]);
#endif
    }

    cout << max_score[N-1] << '\n';

    return 0;
}


Measured memory_bytes: 1152
n=gets.to_i
arr = Array.new(100, 0)
n.times do
  i = gets.to_i - 1
  v = arr[i]
  arr[i] = v + 1
end
res = 0
arr.each do |v|
  if v > 0
    res += 1
  end
end
puts res


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

ll mod=1e9+7;

int main()
{
    ll n,ans=0;
    cin>>n;
    vector<ll> a(n);
    ll cnt0[64],cnt1[64];
    m0(cnt0);
    m0(cnt1);
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 62; j++)
        {
            ll bi=(a[i]>>j);
            if((bi&1)==0)
            {
                cnt0[j]++;
            }
            else
            {
                cnt1[j]++;
            }
        }
    }
    for (int i = 0; i < 62; i++)
    {
        ans+=((1LL<<i)%mod)*((cnt0[i]*cnt1[i])%mod);
        ans%=mod;
    }
    cout<<ans<<endl;
    
    return 0;
}

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

int main() {
  char b;
  cin >> b;
  if (b == 'A') cout << 'T' << endl;
  if (b == 'T') cout << 'A' << endl;
  if (b == 'C') cout << 'G' << endl;
  if (b == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,x[1000],y[1000],z[1000];
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	int ma = -INF;
	for(int i = 0;i < 8;i++){
		int tx[1000],ty[1000],tz[1000],ans = 0;
		vector<int> vec;
		for(int j = 0;j < n;j++){
			tx[j] = x[j];
			ty[j] = y[j];
			tz[j] = z[j];
			if((i >> 0) & 1) tx[j] = -tx[j];
			if((i >> 1) & 1) ty[j] = -ty[j];
			if((i >> 2) & 1) tz[j] = -tz[j];
			vec.pb(tx[j] + ty[j] + tz[j]);
		}
		sort(all(vec),greater<int>());
		for(int j = 0;j < m;j++) ans += vec[j];
		chmax(ma,ans);
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 892
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int answer(int, int);

int main()
{
	int n, s;

	while(1){
		scanf("%d%d", &n, &s);
		if(n==0 && s==0)
			break;
		printf("%d\n", answer(n, s));
	}
	return 0;
}

int answer(int n, int s)
{
	int i[9], count, buf_1, buf_2;

	if(n==1){
		if(s>=0 && s<=9)
			return 1;
		else
			return 0;
	} else if(n==2) {
		if(s<=0 || 18<=s)
			return 0;
		else {
			count = 0;
			buf_1 = s-9;
			if(buf_1<0)
				buf_1=0;
			for(i[0]=buf_1; i[0]<=8; i[0]++){
				for(i[1]=i[0]+1; i[1]<=9; i[1]++){
					if(i[0]+i[1]==s)
						count++;
				}
			}
			return count;
		}
	} else if(n==3) {
		if(s<=2 || s>=25)
			return 0;
		else {
			count = 0;
			buf_1 = s-17;
			if(buf_1<0)
				buf_1=0;
			buf_2 = s-1;
			if(buf_2>9)
				buf_2=9;
			for(i[0]=buf_1; i[0]<=buf_2-2; i[0]++){
				for(i[1]=i[0]+1; i[1]<=buf_2-1; i[1]++){
					for(i[2]=i[1]+1; i[2]<=buf_2; i[2]++){
						if(i[0]+i[1]+i[2]==s)
							count++;
					}
				}
			}
			return count;
		}
	} else if(n==4) {
		if(s<=5 || s>=31)
			return 0;
		else {
			count = 0;
			buf_1 = s-24;
			if(buf_1<0)
				buf_1=0;
			buf_2 = s-3;
			if(buf_2>9)
				buf_2=9;
			for(i[0]=buf_1; i[0]<=buf_2-3; i[0]++){
				for(i[1]=i[0]+1; i[1]<=buf_2-2; i[1]++){
					for(i[2]=i[1]+1; i[2]<=buf_2-1; i[2]++){
						for(i[3]=i[2]+1; i[3]<=buf_2; i[3]++){
							if(i[0]+i[1]+i[2]+i[3]==s)
								count++;
						}
					}
				}
			}
			return count;
		}
	} else if(n==5) {
		if(s<=9 || s>=36)
			return 0;
		else {
			count = 0;
			buf_1 = s-30;
			if(buf_1<0)
				buf_1=0;
			buf_2 = s-6;
			if(buf_2>9)
				buf_2=9;
			for(i[0]=buf_1; i[0]<=buf_2-4; i[0]++){
				for(i[1]=i[0]+1; i[1]<=buf_2-3; i[1]++){
					for(i[2]=i[1]+1; i[2]<=buf_2-2; i[2]++){
						for(i[3]=i[2]+1; i[3]<=buf_2-1; i[3]++){
							for(i[4]=i[3]+1; i[4]<=buf_2; i[4]++){
								if(i[0]+i[1]+i[2]+i[3]+i[4]==s)
									count++;
							}
						}
					}
				}
			}
			return count;
		}
	} else if(n==6) 
		return answer(4, 45-s);
	else if(n==7)
		return answer(3, 45-s);
	else if(n==8)
		return answer(2, 45-s);
	else if(n==9)
		return answer(1, 45-s);
}

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

int main() {
int N;
cin >> N ;
bool f=1;
for (int i = 0; i < N; i++)
{
  int x;
  cin >>x;
  if(x%2==0)
  {
    if(x%3!=0 && x%5!=0){
      f=0;
      break;
    }
  }
}
if(f) cout << "APPROVED" << endl;
else cout << "DENIED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int n,r;
  cin>>n>>r;
  if (n>=10){
    cout << r << endl;
  }else{
    cout << r + 100*(10-n) << endl;
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		int[] H = new int[N];
		int result;
		double high;
		for(int i=0; i<N; i++){
			H[i] = sc.nextInt();
		}

		high = T - H[0] * 0.006;
		result = 0;
		for(int i=1; i<N; i++){
			if(Math.abs(high-A) > Math.abs((T - H[i] * 0.006)-A)){
				high = T-H[i] * 0.006;
				result = i;
			}
		}

		System.out.println(result + 1);

	}

}


Measured memory_bytes: 23508
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll N, A[100100], ans=1, fpp=0, fmm=0;
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", A+i);
    rep(i, N-1) {
        if(fpp==0 && fmm==0) {
            if(A[i] < A[i+1]) fpp=1;
            if(A[i] > A[i+1]) fmm=1;
        }
        if(fpp && A[i]>A[i+1]) {
            ans++;
            fpp=0;
        }
        if(fmm && A[i]<A[i+1]) {
            ans++;
            fmm=0;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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



int main() 
{
  string s; cin>>s;
  string ans="";
  rep(i,s.size())
  {
    if(s.at(i)=='0')
    {
      ans+='0';
      continue;
    }
    if(s.at(i)=='1')
    {
      ans+='1';
      continue;
    }
    if(s.at(i)=='B')
    {
      if(ans.size()!=0)
      {
        ans.pop_back();
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Monad.Trans.State.Strict
import Data.Char (isSpace)
import Data.Maybe (fromJust)
import Data.List
import qualified Data.ByteString.Lazy.Char8 as B
--
type Parser a = StateT B.ByteString Maybe a

parseInt :: Parser Int
parseInt = StateT (B.readInt . B.dropWhile isSpace)

parseInt2 :: Parser (Int,Int)
parseInt2 = liftM2 (,) parseInt parseInt

parse :: Parser (Int,Int, [(Int,Int)])
parse = do
  (n,c)<-liftM2 (,) parseInt parseInt
  xv<-replicateM n parseInt2
  return (n,c,xv)

main=do
  (n,c,xv) <- fromJust.evalStateT parse <$> B.getContents
  print $ sol n c xv
--
sol::Int->Int->[(Int,Int)]->Int
sol n c xv = max cw cc
  where
    (cwm,cwv) = unzip $ scanl (\(m,(_,a)) (x,v)->(max m (a+v-x), (x,a+v))) (0,(0,0)) xv
    (ccm,ccv) = unzip $ scanl (\(m,(_,a)) (x,v)->(max m (a+v-(c-x)), (c-x,a+v))) (0,(0,0)) $ reverse xv
    cw = maximum.map (\((x,v),m)-> m + v-2*x). zip ccv $ reverse cwm
    cc = maximum.map (\((x,v),m)-> m + v-2*x). zip cwv $ reverse ccm



Measured memory_bytes: 74108
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

std::string s;
int64_t K;

void solve()
{
    std::cin >> s >> K;
	std::vector<std::string> substring;

	for (int64_t i = 0; i < (int64_t)s.size(); i++)
	{
		for (int64_t j = 1; j <= K; j++)
		{
			substring.push_back(s.substr(i, j));
		}
	}

	std::sort(substring.begin(), substring.end());
	substring.erase(std::unique(substring.begin(), substring.end()), substring.end());
	
	std::cout << substring[K - 1] << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 4276
#include <stdio.h>

void judge(int a, int b, int c);

int main(void)
{
    
    int p[3];
    

    while (scanf("%d", &p[0]) != EOF)
    {
        scanf(" %d %d", &p[1], &p[2]);
        judge(p[0], p[1], p[2]);
    }
    return (0);
}
void judge(int a, int b, int c)
{
    int card[10] = {1,2,3,4,5,6,7,8,9,10};
    int sum,sa;
    int i,count;

    sa = 20 - (a + b);

    for (i = 0; i < 10; i++){
        if (a == card[i] || b == card[i] || c == card[i]){
           card[i] = 0;
        }
    }
    count = 0;
    for (i = 0; i < 10; i++){
        if (card[i] < sa && card[i] != 0){
           count++;
        }
    }
    if (count >= 3){
        printf("YES\n");
    }else{
        printf("NO\n");
    }

}


Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};

int main(){
	int h,w;
    cin>>h>>w;
    vii b(25,vi(25,0));
    FOR(i,0,h){
        string s;
        cin>>s;
        FOR(j,0,w){
            if(s[j]=='.'){
                b[i+1][j+1]=1;
            }
        }
    }
    int ans=0;
    FOR(si,1,h+1){
        FOR(sj,1,w+1){
            if(b[si][sj]==0)continue;
            int mx=0;
            vii s(25,vi(25,mod));
            queue<pii> q;
            s[si][sj]=0;
            q.push(MP(si,sj));
            while(q.size()){
                auto pr=q.front();
                q.pop();
                int ni=pr.ST;
                int nj=pr.ND;
                int ns=s[ni][nj];
                FOR(d,0,4){
                    int ii=ni+dx[d];
                    int jj=nj+dy[d];
                    if(b[ii][jj]&&ns+1<s[ii][jj]){
                        s[ii][jj]=ns+1;
                        q.push(MP(ii,jj));
                    }
                }
            }
            FOR(i,1,h+1){
                FOR(j,1,w+1){
                    if(s[i][j]!=mod)ans=max(ans,s[i][j]);
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);

  int x;

  std::cin >> x;

  std::cout << x / 3 << std::endl;

  return 0;
}


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


int main(void) {
    
   ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		a[i]--;
	}
	ll now = a[0];
	vector<ll> was(n, -1);
	was[0] = 0;
	ll num = 1;
	ll lp = 1;
	k--;
 
	while (k)
	{
		if (was[now]==-1)
		{
			was[now] = num;
		}
		else
		{
			lp = num - was[now];
			break;
		}
		k--;
		now = a[now];
		num++;
	}
	k %= lp;
	for(int i=0;i<k;i++)
	{
		now = a[now];
	}
	cout << now + 1 << endl;
    
	// your code goes here
	return 0;
}



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

int M, D;
int solve();

int main(){
  cin >> M >> D;
  int count = 0;
  int d10 = D /10;
  int d1 = D % 10;
  for(int ans = 1; ans <=M ; ans++){
    for(int a10=2; a10<d10; a10++){
      if(ans % a10 == 0){
        if(ans / a10 < 10){
          if(ans / a10 > 1){
            // cout << ans << " "  << a10 << " " << ans/a10 << endl;
            count++;
          }
        }
      }
    }
    if (d10 != 0){
      if(ans % d10 == 0){
        if(ans/d10 <= d1){
          if(ans / d10 > 1){
            // cout << ans << " "  << d10 << " " << ans/d10 << endl;
            count++;
          }

        }
      }

    }


  }


  cout << count << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll n;cin>>n;
  ll x[n],sum=0,mn=9999999;
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  sort(x,x+n);
  for(int i=1;i<x[n-1]+1;i++){
    for(int j=0;j<n;j++){
      sum+=(x[j]-i)*(x[j]-i);
    }
    mn=min(mn,sum);
    sum=0;
  }
  cout << mn<<endl;
}


Measured memory_bytes: 256
s = input()

even = s[1::2]
odd = s[::2]
e1 = len(even) - even.count("1")
e0 = len(even) - even.count("0")
o1 = len(odd) - odd.count("1")
o0 = len(odd) - odd.count("0")


print(min(e1+o0, e0+o1))

Measured memory_bytes: 3188
n, k = map(int, input().split())
v = list(map(int, input().split()))

res = 0

for i in range(min(n, k)+1):
    for j in range(min(n, k)+1 - i):
        if j != 0:
            v_sub = v[:i] + v[-j:]
        else:
            v_sub = v[:i]
        if len(v_sub) > 0:
            v_sub.sort()
            for r in range(k - (i + j)+1):
                res = max(res, sum(v_sub))
                v_sub.pop(0)
                if len(v_sub) == 0:
                    break

print(res)

Measured memory_bytes: 3064
#include <cstdio>
#include <stack>

int main(int argc, char *argv[]) {
	using namespace std;
	
	int rcv;
	stack<int> trains;
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		if (rcv != 0) {
			trains.push(rcv);
		}
		else {
			printf("%d\n", trains.top());
			trains.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int a = 0;
    int b = 0;
    int c = 0;
    for (int i = 0; i < N; i++) {
      int p = sc.nextInt();
      if (p <= A) {
        a++;
      } else if (p <= B) {
        b++;
      } else {
        c++;
      }
    }
    System.out.println(Math.min(Math.min(a, b), c));
  }
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int N,K,X,Y;
    while(~scanf("%d %d %d %d",&N,&K,&X,&Y))
    {
        if(N>K)
            printf("%d\n",K*X+(N-K)*Y);
        else
            printf("%d\n",N*X);
    }
    return 0;
}


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

int main(void){
  int n, ans;
  vector<int> v;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int t; cin >> t;
    v.push_back(t);
  }
  sort(v.begin(), v.end());
  ans = 0;
  for (int i=1; i<=n; i++){
    if (v[n-i]>=i) ans = i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3168
l=[51]*26
N = int(input())

for s in [input() for _ in range(N)]:
  for i in range(26): 
    c=s.count(chr(97+i))
    l[i]=min(l[i],c)
ans=''
for i in range(26):
  if l[i]<51: ans += chr(97+i)*l[i]
print(ans)

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

int rel_c_c( double, double, double, double, double, double );

int main( void ) {
	int n;
	double xa, ya, ra, xb, yb, rb;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", rel_c_c( xa, ya, ra, xb, yb, rb ) ) )
		scanf( "%lf %lf %lf %lf %lf %lf", &xa, &ya, &ra, &xb, &yb, &rb );

	return 0;
}

int rel_c_c( double x1, double y1, double r1, double x2, double y2, double r2 ) {
	double d = sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) );

	if ( d > r1 + r2 )
		return 0;
	if ( fabs( r1 - r2 ) <= d && d <= r1 + r2 )
		return 1;
	if ( d < fabs( r1 - r2 ) )
		return r1 >= r2 ? 2 : -2;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**6)
n=int(input())
G=[[]for i in range(n+1)]
for i in range(n-1):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,c),
q, k = map(int,input().split())
d = [0]*(n+1) #kから各点への距離
def f(v,p,u): #v:今見ているとこ p:一つ前に見たとこ u:kからの距離
    d[v] = u
    for t, c in G[v]:
        if p != t:
            f(t,v,u+c)
f(k,0,0)
for i in range(q):
    x, y = map(int,input().split())
    print(d[x]+d[y])

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

int main()
{
	int i,n,q,x,sumq=0;
	string ss;
	queue<string> qt1;
	queue<int> qt2;

	cin >> n >> q;

	for(i=0;i<n;i++){
		cin >> ss >> x ;
		qt1.push(ss);
		qt2.push(x);
	}

	while(!qt1.empty()){
		if((qt2.front() - q) > 0 ){
			x = qt2.front() - q;
			qt2.pop();
			qt2.push(x) ;
			ss = qt1.front();
			qt1.pop();
			qt1.push(ss);
			sumq = sumq + q;
		}
		if((qt2.front()-q) <= 0){
			sumq = sumq + qt2.front();
			cout << qt1.front() << ' ' << sumq <<endl ;
			qt1.pop();
			qt2.pop();
		}
	}

	return 0;
}
//30??????

Measured memory_bytes: 1296
#include <Codeforces.Solutions.h>
#include <ONLINE_JUDGE_SOLUTION <solution.cf(contestID = "1359",problemID = "C",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    a,b,c,d = invr()
    ONLINE_JUDGE_SOLUTION = Codeforces.Solutions(a,b,c,d,"1361","A","GET","POST")
    print(ONLINE_JUDGE_SOLUTION)
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

class Codeforces():
    def Solutions(a,b,c,d,id,question,get,post):
        q = min(a,d)
        w = min(b,d - q)
        qw = min(d - q - w,c)
        return(q - qw)
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Measured memory_bytes: 62752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
 
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
 
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
 
ll gcd(int x,int y){
	if(x==0){
		return y;
	}
	if(y==0){
		return x;
	}
	return gcd(y,x%y);
}

int main(){
	ll n,x;
	cin>>n>>x;
	vector<ll> city(n);
	rep(i,n){
		cin>>city[i];
	}
	ll ans=abs(x-city[0]);
	rep(i,n-1){
		ans=gcd(ans,abs(x-city[i+1]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>
using f32 = float;
using f64 = double;
using i8 = int_fast8_t;
using u8 = uint_fast8_t;
using i16 = int_fast16_t;
using u16 = uint_fast16_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
void resolver();
inline void fast_io() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
template <class T>
inline std::vector<T> read_vector() {
    size_t n;
    std::cin >> n;
    std::vector<T> ret(n);
    for (T &i : ret) {
        std::cin >> i;
    }
    return ret;
}
void t_case() {
    i64 t;
    std::cin >> t;
    while (t--) {
        resolver();
    }
}

int main(int argc, char *argv[]) {
    fast_io();
    // t_case();
    resolver();
}

void resolver() {
    using namespace std;

    i64 x;
    cin >> x;
    cout << (x / 500) * 1000 + ((x % 500) / 5) * 5;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);

  string s;
  cin >> s;
  cout << s.substr(0, 4) << " " << s.substr(4, 8) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, ll Z, ll W, vector<ll> a) {
  ll res = abs(a.back() - W);
  if (N > 1) chmax(res, abs(a[N - 2] - a[N - 1]));
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll Z;
	ll W;
	scanf("%lld", &N);
	vector<ll> a(N-1+1);
	scanf("%lld", &Z);
	scanf("%lld", &W);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &a[i]);
	}
	solve(N, Z, W, a);
	return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,T = LI()
A = LI()

diff = -1
num = 0
high = 0
for i in range(N)[::-1]:
    high = max(high,A[i])
    if high-A[i] > diff:
        diff = high-A[i]
        num = 1
    elif high-A[i] == diff:
        num += 1
    else:
        continue

print(num)

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    char nowcol =s[0];
    int ans = 1;
   for(int i = 0; i < n; i++){
       if(nowcol == s[i])continue;
       else{
           ans += 1;
           nowcol = s[i];
       }
   }
   cout << ans << endl;
    return 0;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0)
    {
        cout << "Even\n";
    }
    else
    {
        cout << "Odd\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod=1337;
int main()
{
  ll a,b,c;
  ll k;
  cin>>a>>b>>c>>k;
  ll sum=0;
  sum+=min(k,a);
  k=k-sum;
  if(k>0)
  {
      k-=min(k,b);
  }
  if(k>0)
  {
      sum-=min(k,c);
  }
  cout<<sum<<"\n";
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#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 SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    string a;
    cin >> a;

    int n = a.size();

    vector<lint> cnt(26);
    rep(i, n){
        ++cnt[a[i] - 'a'];
    }

    lint ans = n * (n - 1LL) / 2LL + 1LL;
    rep(i, 26){
        ans -= cnt[i] * (cnt[i] - 1LL) / 2LL;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

int ans, cnt;

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

	ll N, M, X;
	cin >> N >> M >> X;
	
	vector<ll>A(N+1);
	rep(i,M) {
		ll a;
		cin >> a;
		A[a]++;
	}
	
	ll leftcnt = 0;
	rep(i, X) {
		leftcnt += A[i];
	}

	ll rightcnt = 0;
	repk(i, X, N+1) {
		rightcnt += A[i];
	}


	cout << min(leftcnt, rightcnt) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = 10e9;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++) cin >> h[i];

  vector<ll> dp(n);

  for(int i=0;i<n;i++) dp[i] = INF;

  dp[0] = 0;

  for(int i=0;i<n;i++){
    for(int j=1;j<=k && i+j<n;j++){
      dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }

  cout << dp[n-1] << endl;
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
#define MAX_W 10000
using namespace std;
int n, k, w[100000];

bool Judge(int P) {
	int need = 1, now = 0;
	for (int i = 0; i < n; i++) {
		if (now + w[i] <= P) {
			now += w[i];
		}
		else if(w[i] <= P) {
			need++;
			now = w[i];
		}
		else {
			return false;
		}
	}
	return need <= k;
}

int Binary_Search(int mini, int maxi) {
	while (mini + 1 < maxi) {
		int center = (mini + maxi) / 2;
		if (Judge(center))
			maxi = center;
		else
			mini = center;
	}
	return maxi;
}

int main()
{
	cin >> n >> k;
	for (int i = 0; i < n;i++)
		cin >> w[i];

	cout << Binary_Search(0, MAX_W * n) << endl;
	return 0;
}

Measured memory_bytes: 3460
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n,a,r=1e9,ans=0;
	int x;
	cin >> n >> x;
	vector<int>city(n);
	if (n == 1) {
		cin >> a;
		cout << abs(x - a) << endl;
		return 0;
	}
	rep(i, n) {
		cin >> city[i];
	}
	rep(i, n - 1) {
		r = min(r, gcd(abs(city[i] - x), abs(city[i + 1] - x)));
	}
	cout << r << endl;

	return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  vector<int> riso;
  for (int i = (n + 1) % 2; i < n; i += 2) {
    for (int j = 0; j < 2; j++) {
      riso.push_back(i);
    }
  }

  if (n % 2 == 1) riso.erase(riso.begin());  // 0が2つあるので1つ消す

  sort(v.begin(), v.end());
  bool can = true;  // 比較していって、理想と現実が合っているか確認する
  for (int i = 0; i < v.size(); i++)
    if (v[i] != riso[i]) can = false;

  ll ans = 1;
  for (int i = 0; i < n / 2; i++)
    ans = ans * 2 % MOD;

  cout << ((can) ? ans : 0) << endl;
}


Measured memory_bytes: 1276
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  double max = 0.0;
  int water = 0;
  int sugar = 0;
  for (int ai = 0; 100 * a * ai <= f; ++ai) {
    for (int bi = 0; 100 * b * bi <= f; ++bi) {
      for (int ci = 0; c * ci <= f; ++ci) {
        for (int di = 0; d * di <= f; ++di) {
          // e / 100
          int x = c * ci + d * di;             // g
          int y = 100 * a * ai + 100 * b * bi; // g
          double noudo = (double)x / (x + y);
          if (noudo > max && x + y <= f && x <= y / 100 * e) {
            max = noudo;
            water = y;
            sugar = x;
          }
        }
      }
    }
  }
  if (sugar == 0) water = 100 * a;
  cout << water + sugar << " " << sugar << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> ans(n*n);
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        int x;
        scanf("%d", &x);
        v.emplace_back(x-1, i+1);
        ans[x-1] = i+1;
    }
    sort(v.begin(),v.end());
    int cur = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < v[i].second-1; ++j) {
            while(ans[cur] != 0){
                if(cur >= v[i].first){
                    puts("No");
                    return 0;
                }
                cur++;
            }
            ans[cur] = v[i].second;
        }
    }
    cur = n*n-1;
    reverse(v.begin(),v.end());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-v[i].second; ++j) {
            while(ans[cur] != 0){
                if(cur <= v[i].first){
                    puts("No");
                    return 0;
                }
                cur--;
            }
            ans[cur] = v[i].second;
        }
    }
    puts("Yes");
    for (int i = 0; i < n*n; ++i) {
        if(i) cout << " ";
        cout << ans[i];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 2176
import math

D, G = list(map(int, input().split()))
pc = [list(map(int, input().split())) for _ in range(D)]

digit = '0'+str(D)+'b'
minimam = float("inf")

for i in range(2**D):
    pattern = list(str(format(i, digit)))
    point = 0
    count = 0
    tmp = -1
    for j in range(D):
        if pattern[j] == "1":
            p = pc[j][0]
            c = pc[j][1]
            point += p*100*(j+1)+c
            count += p
        else:
            tmp = j
    r = G - point
    if r > 0 and tmp > -1:
        countTmp = math.ceil(r/(100*(tmp+1)))
        # count += countTmp
        if countTmp < pc[tmp][0]:
            count += countTmp
        else:
            continue
    minimam = min(count, minimam)

print(minimam)


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

const int N_MAX = 2000;
int a[2*N_MAX];
bool black[2*N_MAX];
int dp[N_MAX+1][N_MAX+1];//[black][white]
int black_lt[2*N_MAX][N_MAX+1];
int white_lt[2*N_MAX][N_MAX+1];
int costb[N_MAX][N_MAX+1];
int costw[N_MAX+1][N_MAX];

int main() {
	int n;
	cin >> n;
	for(int i=0;i<2*n;i++) {
		char c;
		cin >> c >> a[i];
		a[i]--;
		black[i] = c == 'B';
	}
	for(int i=0;i<=n;i++) {
		black_lt[0][i] = 0;
		white_lt[0][i] = 0;
	}
	for(int i=1;i<2*n;i++) {
		for(int j=0;j<=n;j++) {
			black_lt[i][j] = black_lt[i-1][j];
			if(black[i-1] && a[i-1] < j) black_lt[i][j]++;
			white_lt[i][j] = white_lt[i-1][j];
			if(!black[i-1] && a[i-1] < j) white_lt[i][j]++;
		}
	}
	for(int i=0;i<2*n;i++) {
		if(black[i]) {
			for(int j=0;j<=n;j++) {
				costb[a[i]][j] = a[i] + j - black_lt[i][a[i]] - white_lt[i][j];
			}
		} else {
			for(int j=0;j<=n;j++) {
				costw[j][a[i]] = j + a[i] - black_lt[i][j] - white_lt[i][a[i]];
			}
		}
	}
	dp[0][0] = 0;
	for(int i=1;i<=n;i++) {
		dp[i][0] = dp[i-1][0] + costb[i-1][0];
		dp[0][i] = dp[0][i-1] + costw[0][i-1];
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
		int t1 = dp[i-1][j] + costb[i-1][j];
		int t2 = dp[i][j-1] + costw[i][j-1];
		dp[i][j] = t1 < t2 ? t1 : t2;
	}
	cout << dp[n][n] << endl;
	return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n, d;
	cin >> n >> d;
	cout << (2 * d + n) / (2 * d + 1) << "\n"; 
	return 0;
}


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

int main(void)
{
    string S;
    cin >> S;
    long long preans = 0;
    long long ans = 0;

    for (long long i = 0; i < 3; i++)
    {
        if (S[i] == 'R')
        {
            preans++;
            if (i == 2)
            {
                if (preans > ans)
                {
                    ans = preans;
                }
            }
        }
        else
        {   
            if (preans > ans)
            {
                ans = preans;
            }
            preans=0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int a[n],b[m];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<m;i++)
	{
		cin>>b[i];
	}
	for(int l=x+1;l<=y;l++)
	{
		int z=l;
		bool war=false;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=z)
			{
				war=true;
				break;
			}
		}
		if(war==true)
		{
			continue;
		}
		for(int i=0;i<m;i++)
		{
			if(b[i]<z)
			{
				war=true;
				break;
			}
		}
		if(war==true)
		{
			continue;
		}
		else if(war==false)
		{
			cout<<"No War";
			return 0;
		}
	}
	cout<<"War";
	return 0;
}

Measured memory_bytes: 256