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

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        int k,n;
        cin>>k>>n;
        int a[n],b[n+1];
        for(int i=0;i<n;i++)
            cin>>a[i];
        b[0]=a[0];
        for(int i=1;i<n;i++)
            b[i]=a[i]-a[i-1];
        b[n]=k-a[n-1];
        b[n]+=b[0];
        int max=-1000;
        for(int i=0;i<=n;i++)
            if(b[i]>max)
                max=b[i];
        cout<<k-max;
    }
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
bool dp[1000001];
bool isprime(int& x){
  for(int i = 2 ; i * i <= x ; i++ ) if( x % i == 0) return true;
  return false;
}
int solve(int i){
  while(true){ if(dp[i] && !isprime(i)) return i; i--; }
}
int main(){
  int n,x,data[30],ans;
  while(cin >> n >> x , n){
    fill_n(dp,1000001,false); dp[0] = true;
    for(int i = 0 ; i < n ; i++ ) cin >> data[i];
    for(int i = 0 ; i <= x ; i++ ){
      if(dp[i]) for(int j = 0 ; j < n ; j++ )
        if(i + data[j] <= x) dp[i+data[j]] = true;
    }
    if(1 < (ans = solve(x))) cout << ans << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 2136
#include <iostream>

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



long long a[100001][3];

long long dp[100001][3];

using namespace std;

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

  for(int i = 0; i < N; i++) for(int j = 0; j < 3; j++) cin >> a[i][j];

  for(int i = 0; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j == k) continue;
        chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
      }
    }
  }

  long long res = 0;
  for(int j = 0; j < 3; j++) chmax(res, dp[N][j]);
  cout << res <<  endl;
  
  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

vector <ll> par; // 各元の親を表す配列
vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

void init_u(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
	for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}

ll n, a, b;
ll ans;

void solve() {
	cin >> n >> a >> b;
	ans += n / (a + b) * a;
	ans += min(a, n % (a + b));
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 256
N, K = map(int, input().split())

As_has_okashi = [False for i in range(N)]

for _ in range(K):
    d = int(input())
    As = list(map(int, input().split()))
    for i in range(d):
        As_has_okashi[As[i]-1] = True

count = 0
for i in range(N):
    if As_has_okashi[i] == False:
        count += 1

print(count)


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

int N, L;
string W[105];

int main() {
    scanf("%d%d", &N, &L);

    for(int i = 0; i < N; i++) {
        cin >> W[i];
    }

    sort(W, W + N);

    string word;
    for(int i = 0; i < N; i++) {
        word += W[i];
    }

    cout << word << "\n";
    return 0;
}


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, a[N];
ll res;

int main() {
	megaRandom();
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	for(int i = 2; i <= n; i ++) {
	  if(!a[i]) continue;
		if(a[i - 1] & 1) {
			a[i - 1] ++;
			a[i] --;			
		}
	}
	for(int i = 1; i <= n; i ++) {
		res += a[i] / 2;
		a[i] = a[i] & 1;
	}
	for(int i = 1; i < n; i ++) {
		if(a[i] > 0 && a[i + 1] > 0) {
			a[i] = a[i + 1 ] = 0, res ++;
			//cout << i << "\n";
		}
	}
	cout << res;
	return 0;  
}


Measured memory_bytes: 640
import functools
import fractions


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return functools.reduce(lcm_base, numbers, 1)

n = int(input())
l = list(map(int, input().split()))
ans = 0
lcm_l = lcm_list(l)
for i in range(n):
    ans += (lcm_l // l[i])
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 6084
#include <iostream>
#include <string>

using namespace std;

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

    int s = 0;
    for (int i = 0; i < static_cast<int>(n.size()); i++) {
        s += n[i] - '0';
    }

    cout << (s % 9 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
const int N = 666666,inf=0x3f3f3f3f;
int n,c[N];long long res;
struct ele{int v,p;}a[N],b[N];
bool cmp(ele a, ele b){return a.v<b.v;}
bool cmp1(ele a, ele b){return a.v>b.v;}
int main() {
	scanf("%d",&n);rep(i,1,n)scanf("%d%d",&a[i].v,&b[i].v),a[i].p=i,b[i].p=i;
	sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp1);
	int p=0;while(p+1<=n&&a[p+1].v<=b[p+1].v)p++;//[1,p] [p+1,n]
	rep(i,1,n)res+=min(a[i].v,b[i].v);rep(i,1,p)c[a[i].p]^=1,c[b[i].p]^=1;
	bool bo=0;rep(i,1,n)bo|=c[i];//res+=min(a[p].v,b[p+1].v)+min(a[p+1].v,b[p].v)-a[p].v-b[p+1].v;
//	printf("%d %d %d %d\n",a[1].p,b[1].p,a[1].v,b[1].v);
	a[0].v=a[n+1].v=b[0].v=b[n+1].v=inf;
	if(!bo&&min(p,n-p)>=1){//min(a[p+1].v,b[p].v)-max(a[p].v,b[p+1].v);
		int now=inf;
		rep(A,max(p-1,1),p)rep(B,p+1,min(p+2,n))rep(C,p+1,min(p+2,n))rep(D,max(p-1,1),p)
			if((p==1||a[A].p!=b[D].p)&&(p==n-1||b[B].p!=a[C].p))now=min(now,min(a[C].v,b[D].v)-max(a[A].v,b[B].v));
		res+=now;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 5120
x, y = gets.split.map(&:to_i)
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
[a,b,c].each do |g|
  if g.include?(x) && g.include?(y)
    puts 'Yes'
    exit
  end
end
puts 'No'


Measured memory_bytes: 1788
#include<stdio.h>

int main(void) {
  int n, d1, d2, count=0;
  scanf("%d", &n);
  int i;
  for(i=0; i<n; i++) {
    scanf("%d %d", &d1, &d2);
    if(d1 == d2) count++;
    else count = 0;
    if(count==3) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,p;
  	ci(n>>p);
  ll ans=1;
  FOR(i,1,sqrt(p)+1){
    ll a=pow(i,n);
    if(p%a==0){
		chmax(ans,i);
    }
  }
  if(n==1){
    co(p)
  }
  else{
    co(ans)
  }
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

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

	int A,B;
	cin>>A>>B;
	for(int i=B-A+1;i<=B+A-1;i++) cout<<i<<" ";
	return 0;
}

Measured memory_bytes: 256
import math

q = int(input())
query = [list(map(int, input().split())) for i in range(q)]

max_n = 10**5
sq = int(math.sqrt(max_n))

prime = [i for i in range(max_n+1)]
prime[1] = 0
for i in prime:
    if i > sq:
        break
    if i == 0:
        continue
    for j in range(i*2, max_n+1, i):
        prime[j] = 0

memo = [0 for i in range(max_n+1)]
for i in range(3, max_n+1, 2):
    if prime[i] != 0 and prime[(i+1)//2] != 0:
        memo[i] = 1

for i in range(max_n):
    memo[i+1] += memo[i]

for l, r in query:
    print(memo[r] - memo[l-1])

Measured memory_bytes: 32940
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  if(s[1]==s[2] && (s[0]==s[1] || s[3]==s[2])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

import Data.Int

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, k ] <- readInts
	vs <- readInts
	print $ solve k $ map fromIntegral vs

solve k vs' = runST $ do
	let
		n = length vs'
	vs <- newListArray ( 0, n - 1 ) vs' :: ST s ( STUArray s Int Int64 )
	dp <- newArray ( ( 0, 0, 0 ), ( k, n, n ) ) ( minBound `div` 2 :: Int64 ) :: ST s ( STUArray s ( Int, Int, Int ) Int64 )
	writeArray dp ( 0, 0, n ) 0
	forM_ [ 0 .. k - 1 ] $ \i -> do
		forM_ [ 0 .. n ] $ \j1 -> do
			forM_ [ j1 .. n ] $ \j2 -> do
				modifyArray dp ( i + 1, j1, j2 ) =<< max <$> readArray dp ( i, j1, j2 )
				when ( j1 < j2 ) $ do
					modifyArray dp ( i + 1, j1 + 1, j2 ) =<< max <$> ( (+)
						<$> readArray vs j1
						<*> readArray dp ( i, j1, j2 ) )
					modifyArray dp ( i + 1, j1, j2 - 1 ) =<< max <$> ( (+)
						<$> readArray vs ( j2 - 1 )
						<*> readArray dp ( i, j1, j2 ) )
					when ( i + 2 <= k ) $ do
						modifyArray dp ( i + 2, j1 + 1, j2 ) =<< max
							<$> readArray dp ( i, j1, j2 )
						modifyArray dp ( i + 2, j1, j2 - 1 ) =<< max
							<$> readArray dp ( i, j1, j2 )
	res <- newSTRef 0
	forM_ [ 0 .. n ] $ \j1 -> do
		forM_ [ j1 .. n ] $ \j2 -> do
			modifySTRef res =<< max <$> readArray dp ( k, j1, j2 )
	readSTRef res

Measured memory_bytes: 4092
N=gets.to_i
array=gets.chomp.split(" ").map(&:to_i)
money = 1000

index = 0
while index < N do
    mini = array[index]
    loop do
        if index < N-1 && array[index] > array[index+1]
            index += 1
            break if index >= N
            mini = array[index]
        else
            break
        end
    end

    index += 1
    break if index >= N
    

    maxi = array[index]
    loop do
        if index < N-1 && array[index] < array[index+1]
            index += 1
            break if index >= N
            maxi = array[index]
        else
            num = money / mini
            money += num*(maxi-mini)
            break
        end
    end
end
puts money


Measured memory_bytes: 14416
n = int(input())
slist = []
for i in range(n):
    s = input()
    slist.append(s[0])
import collections
c = collections.Counter(slist)
l = ["M","A","R","C","H"]
import itertools
citer = list(itertools.combinations(l,3))
ans = 0
for i in citer:
    ans += c[i[0]] * c[i[1]] * c[i[2]]
print(ans)

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

int main() {
  int N,K;
  int a[60];
  cin >> N>>K;
  for (int i = 0; i < N; ++i) cin >> a[i];
  int count=0;
  sort(a, a + N, greater<int>());
  for (int i = 0; i < K; ++i) {
    count+=a[i];
  }
  cout << count << endl;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define unsort(vec) sort(vec); rever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
  int n;
  cin>>n;
  vector<int>a(100010);
  rep(i,n) {
    int b;
    cin>>b;
    if(0<b) {
      a[b-1]++;
      a[b]++;
      a[b+1]++;
    }
    else {
      a[0]++;
      a[1]++;
    }
  }
  unsort(a);
  cout<<a[0]<<endl;
}

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

using namespace std;

int main()
{
	//freopen("input1.txt","r",stdin);freopen("output1.txt","w",stdout);
	int i,j,k,n,l;
	cin>>n>>l;
	char a[n][l],b[l];
    for (i=0;i<n;i++){
    	cin>>b;
    	for (j=0;j<l;j++){
    		a[i][j]=b[j];
    	}
    }
    for (i=0;i<n-1;i++){
    	for (j=0;j<n-1-i;j++){
    		k=0;
    		while (a[j][k]==a[j+1][k]){
    			k++;
    		}
    		if (a[j][k]>a[j+1][k]){
    			for (k=0;k<l;k++){
    				swap(a[j][k],a[j+1][k]);
    			}
    		}
    	}
    }
    for (i=0;i<n;i++){
    	for (j=0;j<l;j++){
    		cout<<a[i][j];
    	}
    }
    return 0;
} 

Measured memory_bytes: 256
import random
N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
a=[0 for i in range(N+1)]
b=[0 for i in range(N+1)]
for i in range(N):
    a[A[i]]+=1
    b[B[i]]+=1
if max([a[i]+b[i] for i in range(1,N+1)])<=N:
    print("Yes")
else:
    print("No")
    exit()
B=B[::-1]
point=0
for i in range(N):
    if A[i]==B[i]:
        point+=1
while(point>0):
    x=random.randrange(N)
    y=random.randrange(N)
    if x==y:
        continue
    before=0
    after=0
    if A[x]==B[x]:
        before+=1
    if A[y]==B[y]:
        before+=1
    if A[x]==B[y]:
        after+=1
    if A[y]==B[x]:
        after+=1
    if before>after:
        B[x],B[y]=B[y],B[x]
        point=point+after-before
print(*B)


Measured memory_bytes: 150940
#include <iostream>
#include <map>
using namespace std;
#define pi 3.14159265

int main()
{
	long long ans = 0, i = 0, j = 0, k = 0, n, max=1;
	cin >> n;

	i = n / 100;n %= 100;
	j = n / 10;n %= 10;
	k = n;

	if (i > j)
		max = i;
	else if (i == j) {
		if (i >= k)
			max = i;
		else
			max = i + 1;
	}
	else
		max = i+1;

	
		

	cout << max << max << max << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

class M_Solutions_B
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        int lose = 0;

        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] == 'x') lose++;
        }

        if(lose>=8) Console.WriteLine("NO");
        else Console.WriteLine("YES");
    }
}

Measured memory_bytes: 13140
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        for (int i = 0; i < 3; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = a[2] - a[0];
        System.out.println(sum);
    }

}


Measured memory_bytes: 21588
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, P> E;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll x = mod_pow(a, n / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, n - 1)) % MOD;
}
struct UnionFind {
	vector<int> par;
	vector<int> rank;
	int size;
	UnionFind(int n) :size(n) {
		par.resize(size);
		rank.resize(size);
		for (int i = 0; i < size; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
};
int N, M;
vector<E> edge;
ll MST(int index) {
	UnionFind U(N);
	U.unite(edge[index].second.first, edge[index].second.second);
	ll ans = edge[index].first;
	for (int i = 0; i < M; i++) {
		if (!U.same(edge[i].second.first, edge[i].second.second)) {
			U.unite(edge[i].second.first, edge[i].second.second);
			ans += edge[i].first;
		}
	}
	return ans;
}
int main() {
	cin >> N >> M;
	ll X;
	cin >> X;
	for (int i = 0; i < M; i++) {
		int U, V;
		ll W;
		cin >> U >> V >> W;
		U--; V--;
		edge.emplace_back(W, P(U, V));
	}
	sort(edge.begin(), edge.end());
	int cnt1 = 0, cnt2 = 0;
	ll m = INF;
	for (int i = 0; i < M; i++) {
		ll ret = MST(i);
		m = min(m, ret);
		if (ret < X) cnt1++;
		else if (ret == X) cnt2++;
	}
	if (m == X) {
		ll ans = (mod_pow(2, cnt2) + MOD - 2) % MOD;
		(ans *= mod_pow(2, M - cnt2)) %= MOD;
		cout << ans << endl;
		return 0;
	}
	if (cnt2 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = (mod_pow(2, cnt2) + MOD - 1) % MOD;
	(ans *= 2) %= MOD;
	(ans *= mod_pow(2, M - cnt1 - cnt2)) %= MOD;
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	char[] a=sc.next().toCharArray();
    int e=0;
    for(char i='a';i<='z';i++){
      int f=0;
      for(int j=0;j<a.length;j++){
        
        if(a[j]==i){
          f++;
          
          break;
        }
      }
      if(f==0){
        System.out.println(i);
        e++;
        break;
      }
    }
    if(e==0){
      System.out.println("None");
    }
  }
}


Measured memory_bytes: 25672
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e4+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    IOS;
    int n;
    cin>>n;
    ll a[n],res=0;
    map<ll,ll>mp;
    lp(i,0,n)
        cin>>a[i],mp[a[i]]++,res+=a[i];
    int q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        res-=mp[b]*b;
        res+=mp[b]*c;
        mp[c]+=mp[b];
        mp[b]=0;
        cout<<res<<endl;
    }
}

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

int main(){
	int n;
	scanf("%d", &n);
	int mon[n+1], bra[n];
	for(int i=0; i<n+1; i++){
		scanf("%d", &mon[i]);
	}
	for(int i=0; i<n; i++){
		scanf("%d", &bra[i]);
	}
	
	long int count=0;
	for(int i=0; i<n; i++){
		if(mon[i]<=bra[i]){
			count+= mon[i];
			bra[i]-= mon[i];
			mon[i] = 0;
			if(bra[i]>=mon[i+1]){
				count+= mon[i+1];
				bra[i]-= mon[i+1];
				mon[i+1] = 0;
			}
			else{
				count+= bra[i];
				mon[i+1]-= bra[i];
				bra[i] = 0;
			}
		}
		else{
			count+= bra[i];
			mon[i]-= bra[i];
			bra[i] = 0;
		}
	}
	
	printf("%ld", count);
	
	
	return 0;
}

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

#define N 100005

int n, h[N], f[N];

int main() {
#ifdef whyqx
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif
    cin >> n;
    for (int i = 1; i <= n; ++i)
        scanf("%d", h + i);
    f[1] = 0, f[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= n; ++i)
        f[i] = min(f[i - 2] + abs(h[i] - h[i - 2]), f[i - 1] + abs(h[i] - h[i - 1]));
    cout << f[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
 

void func()
{
   ll n;
   cin>>n;
   string s[n+1];
   f(i,1,n+1) cin>>s[i];
   ll cnt[4]={};
   f(i,1,n+1)
   {
	   if(s[i]=="AC") cnt[0]++;
	   else if(s[i]=="WA") cnt[1]++;
	   else if(s[i]=="TLE") cnt[2]++;
	   else cnt[3]++;
   }
   
   cout<<"AC x "<<cnt[0]<<"\n";
   cout<<"WA x "<<cnt[1]<<"\n";
   cout<<"TLE x "<<cnt[2]<<"\n";
   cout<<"RE x "<<cnt[3]<<"\n";

}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
        
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
      //cout<<"Case #"<<i<<": ";
       func();
    }
     
    return 0;
}


Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    vector<int> B(n);
    for(int i = 0; i < n; i++){
        cin >> B[i];
    }
    int counta = -1;
    int countb = -1;
    do{
        if(A == B){
            break;
        }
        counta += 1;
    }while(next_permutation(A.begin(), A.end()));
 
    do{
        if(A == B){
            break;
        }
        countb += 1;
    }while(next_permutation(B.begin(), B.end()));
    cout << abs(counta-countb) << endl;
    return 0;
}

Measured memory_bytes: 256
/*ex7_3
 Sweet_Sweet_Soul */
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int hei,wid;/*hei=height、wid＝width*/
    int *hei_ture,*wid_ture;/*各行や列に'#'があれば1を記録する配列*/
    char **grid;/*入力用の多次元配列*/
    scanf("%d%d",&hei,&wid);
    grid=(char**)calloc(hei,sizeof(char*));/*まず各配列の先頭のポインタを確保*/
    if(grid==NULL){
        exit(1);
    }
    for(int i=0;i<hei;i++){
        grid[i]=(char*)calloc(wid,sizeof(char));/*各配列の要素を確保*/
        if(grid[i]==NULL){
            exit(1);
        }
    }
    hei_ture=(int*)calloc(hei,sizeof(int));/*他二つのtrue配列も確保*/
    if(hei_ture==NULL){
        exit(1);
    }
    wid_ture=(int*)calloc(wid,sizeof(int));
    if(wid_ture==NULL){
        exit(1);
    }
    for(int i=0;i<hei;i++){
        for(int j=0;j<wid;j++){
            scanf(" %c",&grid[i][j]);/*gridに入力*/
            if(grid[i][j]=='#'){
                hei_ture[i]=1;/*ついでに真偽値も記録*/
                wid_ture[j]=1;
            }
        }
    }
    for(int i=0;i<hei;i++){
        if(hei_ture[i]==1){
            for(int j=0;j<wid;j++){
                if(wid_ture[j]==1){
                    printf("%c",grid[i][j]);/*行、列ともに真偽値1なら出力*/
                }
            }
        printf("\n");/*行ごとに改行*/
        }
    }
    /*先に各要素の配列のメモリを解放*/
    for(int i=0;i<hei;i++){
        free(grid[i]);
    }
    /*次に先頭のポインタを解放*/
    free(grid);
    free(hei_ture);
    free(wid_ture);
    return 0;
}

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

int main ()
{
	int n; int sum=0; 
scanf("%d",&n);
	
	int temp=n;
	
	while(temp>0){
		sum+=temp%10;
		temp/=10;
	
	}
	if(n%sum==0){
		puts("Yes\n");
}
else 
puts("No\n");
 return 0;

}



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

string srep(string x, int y){
    string s = "";
    rep(i, y) s += x;
    return s;
}


int main(){
    int h, w;
    cin >> h >> w;
    vector<string> v = vector<string>(h);
    rep(i, h){
        cin >> v[i];
    }

    cout << srep("#", w+2) << endl;
    rep(i, h) cout << "#" << v[i] << "#" << endl;
    cout << srep("#", w+2) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        char c = s.charAt(0);
        int ret = 0;
        for (int i = 1;i < s.length();i++) {
            char tmp = s.charAt(i);
            if (c!=tmp) ret++;
            c = tmp;
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 13852
#include <iostream>

using namespace std;

int main()
{
    int n, m, p;

    while (cin >> n >> m >> p, n || m || p) {
        int sum, w_num, x;

        sum = 0;
        for (int i = 1; i <= n; i++) {
            cin >> x;
            
            sum += x * 100;
            if (i == m) {
                w_num = x;
                if (w_num == 0)
                    cout << "0\n";
            }
        }
        if (w_num != 0)
            cout << (sum - (sum * p / 100)) / w_num << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
#define ll long long
#define MAX 55
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n;
struct Node{int x,y;}p[MAX];
bool operator<(Node a,Node b){if(a.x!=b.x)return a.x<b.x;return a.y<b.y;}
bool cmp(Node a,Node b){if(a.x!=b.x)return a.x<b.x;return a.y<b.y;}
set<Node> M;
int ans=1e9;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)p[i].x=read(),p[i].y=read();
	if(n==1){puts("1");return 0;}
	sort(&p[1],&p[n+1]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i^j)
			{
				int P=p[j].x-p[i].x,Q=p[j].y-p[i].y;
				//if(P==0&&Q==0)continue;
				if(P<0)P=-P,Q=-Q;
				M.clear();int ret=0;
				for(int k=1;k<=n;++k)
				{
					if(!M.count((Node){p[k].x-P,p[k].y-Q}))++ret;
					M.insert(p[k]);
				}
				ans=min(ans,ret);
			}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int p=2019;
  int n = sz(s);
  reverse(s.begin(),s.end());
  vl S(n+1,0);
  map<ll,ll> nums;
  ll ten = 1;
  rep(i,n){
    S[i+1] = (S[i] +(s[i]-'0')*ten)%p;
    ten = (ten*10)%p; 
  }
  ll ans = 0;
  if(p == 2 || p == 5){
    rep(i,n){
      if((s[i]-'0')%p==0)ans+=n-i;
    }
    cout<<ans<<endl;
    return 0;
  }
  rep(i,n+1){
    ll q = S[i]%p;
    nums[q]++;
  }
  for(auto it: nums){
    ll a = it.se;
    ans+=a*(a-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long res = 0;
  for (int start = -1; start <= 1; start += 2) {
    vector<int> coef(n);
    for (int i = 0, sign = start; i < n; ++i, sign = -sign) {
      if (i == 0 || i == n - 1) {
        coef[i] = sign;
      } else {
        coef[i] = 2 * sign;
      }
    }
    sort(coef.begin(), coef.end());
    long long diff = 0;
    for (int i = 0; i < n; ++i) {
      diff += a[i] * coef[i];
    }
    res = max(res, diff);
  }
  cout << res << '\n';
}


Measured memory_bytes: 1024
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 51
#define mod 1000000007
#define inf 100000000000000000
#define ll long long
#define endl '\n'

ll a[MAX][MAX],ans[MAX][MAX];
void mul(ll M[MAX][MAX]){
	ll temp[MAX][MAX];
	memset(temp,0,sizeof temp);
	for(int i =0 ; i< MAX ; i++){
		for(int j =0 ; j < MAX; j++){
			for(int k = 0; k <MAX ;k++){
				temp[i][j] += (ans[i][k] * M[k][j]) % mod;
				temp[i][j] %= mod;
			}
		}
	}
	for(int i =0 ; i < MAX ;i++)
		for(int j =0 ; j < MAX ; j++)
			ans[i][j] = temp[i][j];
}

void mpow(ll k){
	if(k == 0 || k == 1)return;
	mpow(k / 2);
	mul(ans);
	if(k&1)
		mul(a);
}


int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n,k;
	cin>>n>>k;
	for(int i =0 ; i < n; i++)
		for(int j =0 ;j < n ; j++){
			cin>>a[i][j];
			ans[i][j] = a[i][j];
		}

	mpow(k);

	ll sum = 0;
	for(int i =0 ; i < MAX ;i++)
		for(int j = 0; j < MAX ;j++)
			sum += ans[i][j], sum %= mod;
	cout<<sum;
	return 0; 
} 

Measured memory_bytes: 384
a, b, c = map(int, input().split())
if a == 5:
  if b == 5 and c == 7:
    print('YES')
  elif b == 7 and c == 5:
    print('YES')
  else:
    print('NO')
else:
  if b == 5 and c == 5:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 8988
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 lng long
#define P pair<int,int>
#define PP pair<P,int>

int a,b;

int main(){
  cin>>a>>b;
  cout<<6-a-b<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W, D;
    while(cin >> N >> W >> D, N or W or D)
    {
        vector<PP> cakes;
        cakes.push_back(PP(W * D, P(W, D)));
        for(int i = 0; i < N; i++)
        {
            int p, s; cin >> p >> s;
            p--;
            int w = cakes[p].second.first;
            int d = cakes[p].second.second;
            cakes.erase(cakes.begin() + p);
            int l = 2 * (w + d);
            s %= l;
            PP cake1, cake2;
            if((s <= w) or (s >= w + d and s <= 2 * w + d))
            {
                if(s >= w + d) s -= w + d;
                cake1 = PP(s * d, P(s, d));
                cake2 = PP((w - s) * d, P(w - s, d));
            }
            else
            {
                if(s >= 2 * w + d) s -=  2 * w + d;
                else s -= w;
                cake1 = PP(w * s, P(w, s));
                cake2 = PP(w * (d - s), P(w, d - s));
            }
            if(cake1.first > cake2.first) swap(cake1, cake2);
            cakes.push_back(cake1);
            cakes.push_back(cake2);
        }
        sort(cakes.begin(), cakes.end());
        for(int i = 0; i < cakes.size(); i++)
        {
            if(i) cout << " ";
            cout << cakes[i].first;
        }
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3124
#include <cstdio>

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        char c;
        scanf("%c", &c);
        if (c == 'Y') {
            printf("Four\n");
            return 0;
        }
    }
    printf("Three\n");
    return 0;
}


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


int main() {
	int N;
	cin >> N;
	vector<vector<int>> A(2, vector<int>(N));
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < N; j++){
			cin >> A.at(i).at(j);
		}
	}
	int ans = 0;
	for(int i = 0; i < N; i++){
		int sum = 0;
		for(int j = 0; j <= i; j++){
			sum += A.at(0).at(j);
		}
		for(int k = i; k < N; k++){
			sum += A.at(1).at(k);
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

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

for i in range(1, n + 1):
    a[i-1] -= i

a.sort()
if n % 2 == 0:
    center = (a[n//2] + a[n//2-1]) // 2
else:
    center = a[(n-1)//2]
sub = lambda x: abs(x - center)
print(sum(list(map(sub, a))))


Measured memory_bytes: 90064
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    REP(i,n) cin>>h[i];
    vector<int> dp(n+1,INF);
    dp[0]=0;
    REP(i,n){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}


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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

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

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)


void Main() {
  ll n, k;
  cin >> n >> k;
  ll a = n / k;
  cout << min(abs(n - k*a), abs(n - k *(a+1))) << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  string l;
  cin >> n >> l;
  
  vector<string> s(n);

  for (int i = 0; i < n; i++){
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  
  for (int i = 0; i < n; i++){
    cout << s[i];
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N, K; cin >> N >> K;
  ll p[K][2*K] = {};
  rep(i,N) {
    int x, y; cin >> x >> y;
    string tmp; cin >> tmp;
    bool black = (tmp=="B"); 
    x %= 2*K; if (x>=K) { y+=K; x-=K; }
    y += (!black)*K; y %= 2*K;
    // cout << x << " " << y << endl;
    p[x][y]++;
  }
  int sum[3*K+1][3*K+1] = {};
  rep(i,9) {
    if (i%2==0) {
      rep(x,K) rep(y,K) sum[i/3*K+x+1][i%3*K+y+1] = p[x][y];
    }
    else {
      rep(x,K) rep(y,K) sum[i/3*K+x+1][i%3*K+y+1] = p[x][K+y];      
    }
  }
  // rep(i,3*K+1) { rep(j,3*K+1) cout << sum[i][j] << " "; cout << endl;} cout << endl;
  rep(i,3*K) rep(j,3*K) sum[i+1][j+1] += sum[i+1][j]+sum[i][j+1]-sum[i][j];
  // rep(i,3*K+1) { rep(j,3*K+1) cout << sum[i][j] << " "; cout << endl;}
  int result = 0;
  rep(i,2*K) rep(j,2*K) {
    result = max(result, sum[i+K][j+K]-(sum[i][j+K]+sum[i+K][j])+sum[i][j]);
  }
  cout << result << endl;
  return 0;
}

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

 
int main()
{
 int a,b,c,k;
 cin>>a>>b>>c>>k;
 int sum=0;

     if(k>=a){
         sum=a;
         k=k-a;
     }
     else{
         sum=k;
        ;
     }
     
     if(k>0){
         k=k-b;
     }
     
     if(k>0){
        sum=sum-k;
     }
     cout<<sum<<endl;

 
   return 0;
}



Measured memory_bytes: 3632
n, m = map(int, input().split())

ac_set = set()
penalty = 0
wa_count = [0] * (n+1)

for i in range(m):
    p, s = input().split()
    p = int(p)

    if s == "AC":
        if not p in ac_set:
            penalty += wa_count[p]
            ac_set.add(p)
    elif s == "WA":
        wa_count[p] += 1


print(len(ac_set), penalty)

Measured memory_bytes: 12780
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1LL; i<n; i++) ans += i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var n = input[0];
	var num = input[1].split(" ");
	
	var count = 0;
	while(check(num)) {
	    for(var i = 0; i < num.length; i++) {
            num[i] = parseInt(num[i], 10) / 2;
        }
        count++;
	}
	console.log(count);
	
}

function check(num) {
    for(var i = 0; i < num.length; i++) {
        if(parseInt(num[i], 10) % 2 === 1) return false;
    }
    return true;
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  double ldx,ldy,rux,ruy;
  while(cin>>ldx>>ldy>>rux>>ruy){
    double x[2],y[2];
    int ans = 0;
    bool eq = false;
    //ldx -= EPS; ldy -= EPS;
    //rux += EPS; ruy += EPS;
    cin>>x[0]>>y[0]>>x[1]>>y[1];
    REP(i,2) REP(j,2){
      double xx = x[i];
      double yy = y[j];
      if(xx >= ldx && xx <= rux &&
	 yy >= ldy && yy <= ruy)
	  ans++;
    }
    double xx = (ldx + rux)/2.0;
    double yy = (ldy + ruy)/2.0;
    if(xx >= x[0] && xx <= x[1] &&
       yy >= y[0] && yy <= y[1])
      ans++;
    if(ans != 0 && !(eq && ans == 1))
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
using namespace std;
int p[1000010],qian[2000010],hou[1000010],pos[1000010];

int ans[1000010];
int main()
{
	int n,flag=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&p[i]),pos[p[i]]=i;
	int Max=0;
	for(int i=1;i<=n;i++)
	{
//		if(pos[i]>pos[i-1]) ans++;
//		else ans=1;
//		Max=max(Max,ans);
		ans[p[i]]=ans[p[i]-1]+1;
		Max=max(Max,ans[p[i]]);
	}
	cout<<n-Max;
	return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,t;
    cin>>n>>t;
    int a=1e9;
    for(int i=0;i<n;i++){
        int k,v;
        cin>>k>>v;
        if(v<=t) a=min(a,k);

    }

    a==1e9?cout<<"TLE":cout<<a;
}

Measured memory_bytes: 256
from collections import Counter, deque, defaultdict
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

N = int(input())
SP = [list(map(str, input().split())) for _ in range(N)]

d = defaultdict(lambda: [])
for s, p in SP:
    d[s].append(int(p))

for s in sorted(d.keys()):
    d[s].sort(reverse=True)
    for p in d[s]:
        print(SP.index([s, str(p)]) + 1)


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, K;
vector<l_l> v;
vector<ll> Q;

int main() {
    //cout.precision(10);
    cin >> N >> K;
    for(ll i = 1; i <= N; i++) {
        ll in;
        cin >> in;
        v.push_back({in, i});
    }
    sort(v.begin(), v.end());
    for(int i = N - 1; i >= 0; i--) {
        Q.push_back(v[i].second);
        v[i].first--;
    }
    K--;
    ll last_opened = v[0].second;
    while(K >= 0) {
        sort(v.begin(), v.end());
        ll next_last_opened;
        for(int i = N - 1; i >= 0; i--) {
            if(v[i].second == last_opened) continue;
            Q.push_back(v[i].second);
            next_last_opened = v[i].second;
            v[i].first--;
            if(v[i].first < 0) {
                cout << -1 << endl;
                return 0;
            }
        }
        last_opened = next_last_opened;
        K--;
    }
    //if(K >= 0) {
    //cout << SIZE << " " << N << " " << K << endl;
    cout << Q.size() << endl;
    for(int i = 0; i < Q.size(); i++) {
        cout << Q[i];
        if(i + 1 < Q.size()) cout << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256