akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long int;
const ll MOD = 1000000007;

template <class T>
T mpow(T a, T n, T mod){
    T result = 1;
    while(n > 0){
        if(n & 1){
            result = result * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    
    return result;
}

int main(){
    ll n;
    cin >> n;
    cout << (mpow(10LL, n, MOD)-2LL*mpow(9LL, n, MOD)+mpow(8LL, n, MOD)+5LL*MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 3636
import math

n = int(input())
x = [0] * n
for i in range(n):
    x[i] = list(map(int, input().split()))
count = 0

k = [1]
for i in range(n):
    k.append(k[i] * (i + 1))
l = 0


for i in range(n - 1):
    for j in range(i + 1, n):
        count += 1
        l += (
            (math.sqrt(((x[i][0] - x[j][0]) ** 2) + ((x[i][1] - x[j][1]) ** 2)))
            * (n - 1)
            * 2
        )
print(l / (count * 2))

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

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if (n>1)&(m>1):
	print(combinations_count(n, 2)+combinations_count(m, 2))
elif n>1:
    print(combinations_count(n, 2))
elif m>1:
    print(combinations_count(m, 2))
else:
    print(0)

Measured memory_bytes: 9192
#coding:utf-8

s = str(input())

n = len(s)

s1 = s[:int((n - 1)/2)]
s2 = s[int((n + 1)/2):]

if(s[::-1] == s)and(s1[::-1] == s1)and(s2[::-1] == s2):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Measured memory_bytes: 3060
import bisect

n = int(input())
L = list(map(int,input().split()))
L.sort()
ans =0
for i in range(n-1,1,-1):
  for j in range(i-1,0,-1):
    L_ = L[:j]
    ans += j-bisect.bisect_right(L_,L[i]-L[j])
    
print(ans)




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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    double l;
    cin >> l;

    cout << setprecision(10) << (l / 3.0) * (l / 3.0) * (l / 3.0) << "\n";

    return 0;
}



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


int main(void) {
    double a, b, c, d, e, f;
    double x, y;
    
    while(cin >> a >> b >> c >> d >> e >> f) {
        x = (c*e - b*f) / (a*e - b*d);
        y = (c*d - a*f) / (b*d - a*e);
        
        if(x == 0) x = 0;
        if(y == 0) y = 0;
        printf("%.3lf %.3lf", x, y);
        cout << endl;
    }
}


Measured memory_bytes: 3204
import math

H,A = map(int,input().split())
f, i = math.modf(H/A)

if not H <= 10^4 and H >= 1:
  False
if not A <= 10^4 and H >= 1:
  False

if f == 0:
  print(int(i))
if f != 0:
  print(int(i+1))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;

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

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

// 第一引数 == 第二引数 ? true : false
template<class T, class U>
bool check(T first, U second) {
    return (first == second);
}

// 約数列挙
vector<int64_t> divisor(int64_t n) {
  vector<int64_t> ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}


// 数字和
template<class T>
T digitSum(T num) {
    T dig;
    T sum = 0;
    while (num) {
        dig = num % 10;
        sum += dig;
        num /= 10;
    }
    return sum;
}

string background_black(string s) { return "\x1b[40m" + s; }
string background_red(string s) { return "\x1b[41m" + s + "\x1b[40m"; }
string background_green(string s) { return "\x1b[42m" + s + "\x1b[40m"; }
string background_yellow(string s) { return "\x1b[43m" + s + "\x1b[40m"; }
string background_bleu(string s) { return "\x1b[44m" + s + "\x1b[40m"; }
string background_white(string s) { return "\x1b[47m" + s + "\x1b[40m"; }

string black(string s) { return "\x1b[30m" + s + "\x1b[37m"; }
string red(string s) {return "\x1b[31m" + s + "\x1b[37m"; }
string green(string s) { return "\x1b[32m" + s + "\x1b[37m"; }
string yellow(string s) { return "\x1b[33m" + s + "\x1b[37m"; }
string blue(string s) { return "\x1b[34m" + s + "\x1b[37m"; }
string white(string s) { return "\x1b[37m" + s + "\x1b[37m"; }

const int ten = 10;
const int hundred = 100;
const int thousand = 1000;

typedef long long ll;
typedef unsigned long long ull;

string tolower(string s) {
  string c;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] >= 'A') && (s[i] <= 'Z')) {
        c.push_back((s[i] + 0x20));
    } else {
        c.push_back(s[i]);
    }
  }
  return c;
}
#include <cstdlib>
string solve() {
  string str = "";
// int->string: to_string, string->int: stoi
//=============================================================================


  
  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, 0, a.size()-1) cin >> a[i];

  if (t == 1) {
    str += to_string(k-1);
  } else {
    sort(a.begin(), a.end());
    int sub = a[a.size()-1] - accumulate(a.begin(), a.end()-1, 0);
    if (sub <= 1) {
      str += to_string(0);
    } else {
    str += to_string(sub-1);
    }
  }





//=============================================================================
  str += "\n";
  return str;
}

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


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

typedef long long LL;

const int N = 1e5 + 10;
const LL mod = 1e9 + 7;

int n;
char s[N];

LL f[N];

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	bool flag = 0;
	for (int i = 1; i <= n; ++ i)
		if (s[i] == s[i - 1]) flag = 1;
	if (!flag) return printf("1\n"), 0;
	f[0] = 1;
	for (int i = 1, sum = 0, pre[3] = { 0, - 1, - 1 }; i <= n; ++ i)
	{
		(sum += 1 + (s[i] != 'a')) %= 3;
		if (!sum && i < n) f[i] = 1;
		(++ sum) %= 3;
		if (pre[sum] != - 1) (f[i] += f[pre[sum]]) %= mod;
		(++ sum) %= 3;
		if (pre[sum] != - 1) (f[i] += f[pre[sum]]) %= mod;
		(++ sum) %= 3;
		pre[sum] = i;
	}
	printf("%lld\n", f[n]);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll a, b, n; cin >> a >> b >> n;


    if(n >= b){
        ll x = (n/b) * b - 1;
        cout << (a*x)/b - a * (x/b) << endl;
        return 0;
    }

    cout << (a*n)/b - a * (n/b) << endl;
}

Measured memory_bytes: 3588
#include <stdio.h>
void print_building(int x[3][10])
{
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            printf(" %d", x[i][j]);
        }
        printf("\n");
    }
}

int main(void)
{
    int n; //情報の数
    int b, f, r, v;
    int x[4][3][10] = {0};

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        x[b - 1][f - 1][r - 1] += v; //各部屋の配列に人数を代入していく
    }
    print_building(x[0]);
    puts("####################");
    print_building(x[1]);
    puts("####################");
    print_building(x[2]);
    puts("####################");
    print_building(x[3]);

    return 0;
}


Measured memory_bytes: 2764
import java.util.*;
public class Main{
    public static void main(String []args){
        Scanner x=new Scanner(System.in);
        int a=x.nextInt();
        while(100<=a&&a<=999){
            int b=a/100;
            int c=a%100/10;
            int d=a%100%10/1;
            int bb=(b*100)+(b*10)+b;
            if(bb>=a){
                System.out.println(bb);
                break;
            }
            else{
                System.out.println((b+1)*100+(b+1)*10+(b+1));
                break;
            }
        }
     }
}

Measured memory_bytes: 23124
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;

int main(void)
{
	int n,i,p,j[65000];
	unsigned int a,b,c,x;
	while(1){
		a=0;
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&p); a+=p;
		}
		for(i=0;i<n-1;i++) scanf("%d",&j[i]);
		sort(j,j+n-1,greater<int>());
		x=n*a; b=a;
		for(i=0;i<n-1;i++){
			b+=j[i];
			c=(n-(i+1))*b;
			if(c>x) x=c;
		}
		printf("%u\n",x);
	}
	return 0;
}

Measured memory_bytes: 2820
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#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()

int main() {
  string s;
  while(cin>>s) {
    vector<int> v;
    REP(i,s.length())
      v.push_back(s[i]-'0');
    
    while(v.size()>1) {
      vector<int> vv;
      REP(i,v.size()-1) {
        int a = v[i]+v[i+1];
        if (a >= 10) a-=10;
        vv.push_back(a);
      }
      v = vv;
    }
    cout << v[0] << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

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

int main()
{
    ll n, y;
    cin >> n >> y;
    bool flag = false;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n - i; j++)
        {
            if (y - (10000 * i + 5000 * j) == 1000 * (n - i - j))
            {
                cout << i << " " << j << " " << n - i - j << endl;
                flag = true;
                break;
            }
        }
        if (flag)
        {
            break;
        }
    }
    if (flag == false)
    {
        cout << "-1 -1 -1" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define rev(x) reverse(x.begin(),x.end())
using ll = long long;

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

	ll ans = 0;
	SORT(a);
	rev(a);
	rep(i, 0, n) {
		if (!(i % 2)) ans += a[i];
		else ans -= a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

# 標準入力 <int>
N = int(input())

# 標準入力<str>
S = input()

R = S.count("R")
G = S.count("G")
B = S.count("B")

cnt = 0

for i in range(N - 2):
  for j in range(i + 1, N - 1):
    k = i + ((j - i) * 2)
    if k < N:
      if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        cnt += 1

print(R * G * B - cnt)


Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#define INF 1 << 9
#define MAX 1000001
using namespace std;

int pollock[200];
int pollock2[200] = {INF};
int dp[MAX];
int dpo[MAX];

void calcDpo() {
  for (int i = 0; i < MAX; i++)
    dpo[i] = i;
  for (int i = 0; i < 200; i++) {
    if (pollock2[i] > MAX) break;
    for (int j = pollock2[i]; j < MAX - 1; j++) {
      dpo[j] = min(dpo[j], dpo[j - pollock2[i]] + 1);
    }
  }
}

void calcDp() {
  for (int i = 0; i < MAX; i++)
    dp[i] = i;
  for (int i = 1; i < 200; i++) {
    if (pollock[i] > MAX) break;
    for (int j = pollock[i]; j < MAX - 1; j++) {
      dp[j] = min(dp[j], dp[j - pollock[i]] + 1);
    }
  }
}

void calcPollock() {
  for (int i = 0; i < 200; i++) {
    pollock[i] = i * (i + 1) * (i + 2) / 6;
  }
  pollock2[0] = 0;
  int j = 1;
  for (int i = 0; i < 200; i++) {
    if (pollock[i] % 2)
      pollock2[j++] = pollock[i];
  }
}

int main() {
  calcPollock();
  calcDp();
  calcDpo();
  

  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    cout << dp[n] << ' ' << dpo[n] << endl;
  }
}

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

using namespace std;

const int N = 500000 + 77;
int n , k , cur = 1 , a[N] , P[N] , Mx[N << 2] , A[N];
bool M[N];
vector < int > adj[N];
void Update(int x , int y , int l = 1 , int r = n + 1 , int id = 1) {
   if(r - l < 2) {
      Mx[id] = y;
      return ;
   }
   int mid = ((l + r) >> 1);
   if(x < mid)
      Update(x , y , l , mid , id << 1);
   else
      Update(x , y , mid , r , id << 1 ^ 1);
   Mx[id] = max(Mx[id << 1] , Mx[id << 1 ^ 1]);
}
int Get(int ql , int qr , int l = 1 , int r = n + 1 , int id = 1) {
   if(qr <= l || r <= ql)
      return 0;
   if(ql <= l && r <= qr)
      return Mx[id];
   int mid = ((l + r) >> 1);
   return max(Get(ql , qr , l , mid , id << 1) , Get(ql , qr , mid , r , id << 1 ^ 1));
}
void dfs(int v) {
   M[v] = 1;
   for(int u : adj[v])
      if(! M[u])
         dfs(u);
   A[cur ++] = v;
}
int main() {
   scanf("%d %d" , & n , & k);
   for(int i = 1;i <= n;++ i)
      scanf("%d" , a + i) , P[a[i]] = i;
   for(int i = 1;i <= n;++ i) {

      int le = Get(max(P[i] - k + 1 , 1) , P[i]);
      int ri = Get(P[i] , min(P[i] + k , n + 1));
      if(le)
         adj[P[i]].push_back(P[le]);
      if(ri)
         adj[P[i]].push_back(P[ri]);
      Update(P[i] , i);
   }
   for(int i = 1;i <= n;++ i)
      if(! M[i])
         dfs(i);
   for(int i = 1;i <= n;++ i)
      a[A[i]] = i;
   for(int i = 1;i <= n;++ i)
      printf("%d\n" , a[i]);
   return 0;
}


Measured memory_bytes: 58624
n,m=map(int,input().split())
h=list(map(int,input().split()))
e=[1]*n
for _ in range(m):
  a,b=map(int,input().split())
  if h[a-1]>h[b-1]:e[b-1]=0
  elif h[a-1]<h[b-1]:e[a-1]=0
  else:
    e[a-1]=0
    e[b-1]=0
print(sum(e))

Measured memory_bytes: 86412
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Test ll t;cin>>t; while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
int main() 
{
    string s;
    cin>>s;
    char x;
    x=s[0];
    ll r,c,l,i,mid,j;
    c=1;
    r=1;
    l=0;
    vector<ll> v,a,b;
    for(i=1;i<s.length();i++)
    {
        if(s[i]==x)
        {
            c++;
        }
        else
        {
            x=s[i];
            if(r)
            v.push_back(i-1);
            if(r)
            {
                a.push_back(c);
                r=0;
                l=1;
            }
            else
            if(l)
            {
                b.push_back(c);
                r=1;
                l=0;
            }
            c=1;
        }
    }
    if(r)
    {
        a.push_back(c);
        r=0;
        l=1;
    }
    else
    if(l)
    {
        b.push_back(c);
        r=1;
        l=0;
    }
    for(i=0;i<a.size();i++)
    {
        if((a[i]+b[i])%2==0)
        {
            a[i]=b[i]=(a[i]+b[i])/2;
        }
        else
        if(a[i]>b[i])
        {
            mid=(a[i]+b[i])/2;
            if(a[i]%2==0)
            {
                a[i]=mid;
                b[i]=mid+1;
            }
            else
            {
                a[i]=mid+1;
                b[i]=mid;
            }
        }
        else
        if(a[i]<b[i])
        {
            mid=(a[i]+b[i])/2;
            if(b[i]%2==0)
            {
                a[i]=mid+1;
                b[i]=mid;
            }
            else
            {
                a[i]=mid;
                b[i]=mid+1;
            }
        }
    }
    j=0;
    // for(i=0;i<v.size();i++)
    // cout<<v[i]<<" ";
    // cout<<endl;
    for(i=0;i<s.length();)
    {
        if(i==v[j])
        {
            cout<<a[j]<<" "<<b[j]<<" ";
            j++;
            i+=2;
        }
        else
        {
            cout<<"0 ";
            i++;
        }
    }
	return 0;
} 

Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
   int  a;
cin >> a;
if(a==7||a==5||a==3){
cout << "YES";
}else{
cout << "NO";  
}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    int a[100100]; 
    map<int, int> mp;
    rep(i, N) {
        cin >> a[i];
        mp[a[i]] ++;
    }
    if(mp.size() != 1 && mp.size() != 2) No();
    else if(mp.size() == 1) {
        if(a[0] == N - 1) Yes();
        else if(a[0] * 2 <= N) Yes();
        else No();
    }
    else {
        int m[2]; int i = 0;
        for(auto p : mp) {
            m[i] = p.fr; i++;
        }
        if(abs(m[0] - m[1]) > 1) No();
        else {
            int k = max(m[0], m[1]);
            if(mp[k - 1] <= k - 1 && mp[k] >= 2 * (k - mp[k - 1])) Yes();
            else No();
        }
    }
	return 0;
}

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

int main() {
  int K,A,B;
  cin >> K;
  cin >> A >> B;

  for(int i = A; i <= B; i++) {
    if(i % K == 0) { cout << "OK"; return 0;}
  }

  cout << "NG";
  return 0;
}



Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

int main() {
  string S;
  cin >> S;
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    if (S.at(i) == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long int i,n,hoge=2,tmp=1,ans=1;
  scanf("%lld",&n);
  for(i=2;i<=n;i++){
    ans=hoge+tmp;
    hoge=tmp;
    tmp=ans;
  }
  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 128
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-5-20 21:05:39
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const int infty = 1000000007;

int N;
int P[200010];
int Q[200010];

int solve()
{
  int ans = 1;
  int lb = 0;
  for (auto i = 1; i < N; i++)
  {
    if (Q[i - 1] < Q[i])
    {
      ans = max(ans, i - lb + 1);
      // cerr << "lb = " << lb << ", i = " << i << endl;
    }
    else
    {
      lb = i;
    }
  }
  return N - ans;
}

int main()
{
  cin >> N;
  for (auto i = 0; i < N; i++)
  {
    cin >> P[i];
    P[i]--;
  }
  for (auto i = 0; i < N; i++)
  {
    Q[P[i]] = i;
  }
  int ans = solve();
  cout << ans << endl;
}

Measured memory_bytes: 1920
N = int(input())
a = map(int, input().split())
a_sorted = sorted(list(a),reverse=True)

alice_count = 0
bob_count = 0

for i in range(0,N):
    #手順を調べる
    if i%2==0: # Aliceの番
        alice_count += a_sorted[i]
    else: #Bobの番
        bob_count += a_sorted[i]
        
print(alice_count-bob_count)

Measured memory_bytes: 3060
#print("please, type A and B")
ab_list = input().split()
A_cake = int(ab_list[0])
B_cake = int(ab_list[1])

if (not 1<= A_cake <=16) or (not 1<= B_cake <=16) or (A_cake + B_cake > 16):
    #print("something is wrong with your input")
    print(":(")
    #print("A:"+str(A_cake))
    #print("B:"+str(B_cake))
    exit()


Acnt = A_cake
Bcnt = B_cake

for i in range(16):
    if i % 2 == 0:
        Acnt -= 1
    else:
        Bcnt -= 1

if Acnt <= 0 and Bcnt <= 0:
    print("Yay!")
else:
    print(":(")




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using ll = long long;
const int inf = 1e8;

int dp[305][305];

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        vector<int> w(n);
        rep(i,n) cin >> w[i];
        for (int i = n-1; i >= 0; i--) {
            for (int j = 0; j < n; j++) {
                if (j < i) continue;
                else if (j == i) dp[i][j] = 0;
                else if (j == i+1) {
                    if (abs(w[i]-w[j]) <= 1) dp[i][j] = 2;
                    else dp[i][j] = 0;
                }
                else {
                    if (abs(w[i]-w[j]) <= 1 && dp[i+1][j-1] == j-i-1) dp[i][j] = j-i+1;
                    for (int k = i; k <= j-1; k++) {
                        dp[i][j] = max(dp[i][k]+dp[k+1][j],dp[i][j]);
                    }
                }
            }
        }
        cout << dp[0][n-1] << endl;
        rep(i,n)rep(j,n) dp[i][j] = 0;
    }
}


Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000005
#define NIL -1

struct Node
{
    int parent, left, right;
};

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";

    if ( T[u].parent == NIL) cout << "root, ";
    else if ( T[u].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for (i = 0, c = T[u].left; c != NIL; i++, c = T[c].right){
        if(i)cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p){
    D[u] = p;
    if( T[u].right != NIL) rec(T[u].right, p);
    if( T[u].left != NIL) rec(T[u].left, p+1);
}

int main(){
    int i, j, d, v, c, l, r;
    cin >> n;
    for (int i = 0; i < n; i++) T[i].parent = T[i].left = T[i].right = NIL;

    for(i = 0; i < n; i++){
        cin >> v >> d;
        for(int j = 0; j < d; ++j){
            cin >> c;
            if(j == 0) T[v].left = c;
            else T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].parent == NIL) r = i;
    }

    rec(r, 0);

    for(i = 0; i < n;i++) print(i);

    return 0;
}



Measured memory_bytes: 7780
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	string s,t;
	cin>>s>>t;
	int ans=INF;

	rep(i,s.size()-t.size()+1){
		int cnt=0;
		rep(j,t.size()){
			if(s[i+j]!=t[j]) cnt++;
		}
		chmin(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> data(M,vector<int>(2));
  for(int i=0;i<M;i++){
    for(int j=0;j<2;j++){
      cin >> data.at(i).at(j);
    }
  }
  int count=0;
  int a=0;
  int b=0;
  int c=0;
  for(int i=0;i<M-1;i++){
    for(int j=i+1;j<M;j++){
      if(data.at(i).at(0)==data.at(j).at(0)){
        if(data.at(i).at(1)!=data.at(j).at(1)){
          count++;
        }
      }
    } 
  }
  for(int i=0;i<M;i++){
    if(N==2 || N==3){
      if(data.at(i).at(0)==1 && data.at(i).at(1)==0){
        count++;
      }
    }
  }           
        
  if(count==0){
    for(int i=0;i<M;i++){
      if(data.at(i).at(0)==1){
        a=data.at(i).at(1);
      }
      if(data.at(i).at(0)==2){
        b=data.at(i).at(1);
      }      
      if(data.at(i).at(0)==3){
        c=data.at(i).at(1);
      }    
    }
    if(N==1){
      cout << a << endl;
    }
    if(N==2){
      if(a==0){
        a=1;
      }
      cout << a << b << endl;
    }
    if(N==3){
      if(a==0){
        a=1;
      }
      cout << a << b << c << endl;
    }
  }
  else{
    cout << -1 << endl;
  }
}
    
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100001
using namespace std;
typedef long long ll;
int n;
ll A[N];

int check(ll x){
  ll size = A[x];
  for(int i=0;i<x;i++) 
    if(size*2>=A[i]) size+=A[i];
  
  for(int i=x+1;i<n;i++)
    if(size*2>=A[i]) size+=A[i];
    else return 0;
  return 1;
}

int main(){

  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  sort(A,A+n);
  
  ll L = 0,M ,R = n;
  while(L<R){
    M = (L+R)/2;
    if(check(M)) R = M;
    else L = M+1;
  }
  cout<<n-L<<endl;


  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

int main(){
  vector<string> st;
  int N;
  string str;
  while(cin >> str && str != "-"){
    cin >> N;
    for(int i=0;i<N;i++){
      int h;
      string s1, s2;
      cin >> h;
      s1 = str.substr(0, h);
      s2 = str.substr(h, str.size()-h);
      str = s2 + s1;
    }
    st.push_back(str);
  }

  for(int i=0;i<st.size();i++){
    cout << st[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>


void print_pattern(int n, int h, int buf[], int csr) {
    int i, j;
    for (i = h<n?h:n; i; i--) {
        buf[csr] = i;
        if (n - i) {
            print_pattern(n - i, i, buf, csr + 1);
        }
        else {
            printf("%d", buf[0]);
            for (j = 1; j <= csr; j++) {
                printf(" %d", buf[j]);
            }
            puts("");
        }
    }
}

int main(void) {
    int n;
    int buf[100];

    while (scanf("%d", &n) != EOF && n) {
        print_pattern(n, n, buf, 0);
    }
    return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<int> G[200010];
stack<ll> S[200010];

ll alc = 0, N;
ll idc[200010], C[200010], ans[200010], ap[200010];

void euler(int c, int p) {
	for (int i : G[c]) {
		if (i == p)continue;
		S[C[c]].push(alc + idc[C[c]]);
		idc[C[c]] = -alc;
		alc++;
		idc[C[i]]--;
		euler(i, c);
	}
	ll g;
	if (p < 0)return;
	if (p == 0) {
		for (int i = 1;i <= N;i++) {
			g = idc[i] + alc;
			ans[i] += g * (g - 1) / 2;
		}
		return;
	}
	g = idc[C[p]] + alc;
	ans[C[p]] += g * (g - 1) / 2;
	idc[C[p]] = S[C[p]].top() - alc;
	S[C[p]].pop();
}


int main() {
	for (int i = 0;i < 200010;i++)idc[i] = C[i] = ans[i] = ap[i] = 0;
	int a, b;
	cin >> N;
	for (int i = 1;i <= N;i++) {
		cin >> C[i];
		ap[C[i]]++;
	}
	for (int i = 1;i < N;i++) {
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	G[0] = { 1 };
	S[0].push(0);
	euler(0, -1);
	for (int i = 1;i <= N;i++)
		if (ap[i] == 0)cout << 0 << endl;
		else cout << N * (N - 1) / 2 - ans[i] + ap[i] << endl;
}

Measured memory_bytes: 178712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int x = in.nextInt();
            int y = in.nextInt();
            if (n > k) {
                out.println((k * x) + ((n - k) * y));
            } else {
                out.println(n * x);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
N = int(input())
count = 0
from math import sqrt
for i in range(1,N+1)[::-1]:
    if i%2==1:
        yakusu = 0
        for j in range(1,i+1):
            if i%j==0:
                yakusu += 1
        
        if yakusu == 8:
            count += 1
print(count)

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


int main(){
	int cnt = 0;
	string sss;
	cin >> sss;

	rep(i,3){
	    if(sss[i] == '1') cnt++;
	}
	cout << cnt << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define N_MAX 1000
#define M 1000000007
using namespace std;
typedef long long ll;
 
ll func(int);
 
int N,s,t;
string n[N_MAX];
vector<int> edge[N_MAX];
 
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>n[i];
  for(int i=0;i<N-1;i++) cin>>s>>t,edge[s-1].push_back(t-1);
  cout<<func(0)%M<<endl;
  return 0;
}
 
ll func(int x){
  ll res=0,res2=1;
  if(!edge[x].size()){
    if(n[x]=="E") return 1;
    if(n[x]=="E?") return 2;
    return 0;
  }
  if(n[x]=="E"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return res2%M;
  }
  if(n[x]=="E?"){
    for(int i=0;i<edge[x].size();i++) res2*=func(edge[x][i]);
    return (res2+1)%M;
  }
  if(n[x]=="A"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    for(int i=0;i<edge[x].size();i++)
      if(n[edge[x][i]]=="E?") return (res+1)%M;
    return res%M;
  }
  if(n[x]=="A?"){
    for(int i=0;i<edge[x].size();i++) res+=func(edge[x][i]);
    return (res+1)%M;
  }
  if(n[x]=="R?"){
    for(int i=0;i<edge[x].size();i++){
      if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
      else res2*=(1+func(edge[x][i]));
    }
    return res2%M;
  }
  if(n[x]=="R"){
    for(int i=0;i<edge[x].size();i++){
      if(n[edge[x][i]]=="E?") res2*=func(edge[x][i]);
      else res2*=(1+func(edge[x][i]));
    }
    for(int i=0;i<edge[x].size();i++)
      if(n[edge[x][i]]=="E?") return res2%M;
    return (res2-1)%M;
  }
}

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

int n,a;
bool flag;

namespace WalkerV {
	void Read() {
		scanf("%d",&n);
		return;
	}

	void Solve() {
		for(int i=1;i<=n;i++) {
			scanf("%d",&a);
			if(a%2!=0) {
				continue;
			}
			if(a%3==0||a%5==0) {
				continue;
			}
			else {
				flag=false;
				return;
			}
		}
		flag=true;
		return;
	}

	void Print() {
		if(flag) {
			printf("APPROVED");
		}
		else {
			printf("DENIED");
		}
		return;
	}
}

int main()
{
	WalkerV::Read();
	WalkerV::Solve();
	WalkerV::Print();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
#include<bitset>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから

typedef long long ll;



//英字ならture、数字ならfalse
bool isalpha(char s){
    if(('A'<=s&&s<='Z')||('a'<=s&&s<='z')){
        return 1;
    }else{
        return 0;
    }
}
//全ての文字が英字ならture、数字ならfalse
bool Isalpha(string s){
    ll n;
    bool tmp = true;
    rep(i,n){
        if(isalpha(s[i])){
            tmp = false;
        }
    }
    return tmp;
}




using Graph = vector<vector<ll>>;



//cout<<fixed<<setprecision(10);

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}



int main(){
    ll n,m;
    cin>>n;
    string s = "";
    while(n>0){
        n-=1;
        m = n%26;
        n-=m;
        n/=26;
        s+='a'+m;
    }

    n = s.size();
    rep(i,n){
        cout<<s[n-1-i];
    }cout<<endl;

    return 0;
}



Measured memory_bytes: 3632
#include<stdio.h>
 int main(void)
 {
    long A[10000];
    int M,N,i,j=0,k,L=0;
    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++){
      scanf("%ld",&A[i]);
      j=j+A[i];
    }
    for(i=0;i<N;i++)
      if(4*M*A[i]>=j) L++;
 
    if(L>=M) printf("Yes\n");
       else  printf("No\n");
    return 0;
 }

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int ans;
int main() {
	int a, b;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % 10 == i / 10000 && (i / 10) % 10 == (i / 1000) % 10)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn lcm(a: i64, b: i64) -> i64 {
    a*b / gcd(a, b)
}

fn main() {
    input! { a: i32, b: i32}

    let mut r = (a-b)/2;
    r = r.abs();
    let x = if a > b {b} else {a};
    let y = if a > b {a} else {b};
    if x + r + r == y {
        println!("{}", x+r);
    } else {
        println!("IMPOSSIBLE");
    }
}

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

int main() {
	int a,b;
	cin >> a >> b;
	if ( a == b ) {
		cout << "a == b" << endl;
	} 
	else if ( a < b ) {
		cout << "a < b" << endl;
	} 
	else if ( a > b ) {
		cout << "a > b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
// remove fropen in online judge
int main()
{ 
   // #ifndef ONLINE_JUDGE 
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   // freopen("error.txt","w",stderr);
   //  #endif 

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++)
    {
      sum+=(s[i]-'0');
    }
    if(sum%9==0)
      cout<<"Yes";
    else
      cout<<"No";
    
}


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

int main() {
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int h, w;
	int c;
	cin >> h >> w >> c;
	if (h == w) {
		cout << c << endl;
	} else if (h < w) {
		for (int i = 1; ; i++) {
			if (w % (h / i) == 0 && h % i == 0) {
				int x = i * w / (h / i);
				cout << c * x << endl;
				break;
			}
		}
	} else {
		for (int i = 1; ; i++) {
			if (h % (w / i) == 0 && w % i == 0) {
				int x = i * h / (w / i);
				cout << c * x << endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 3164
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int area = a*b;
        int length = (a+b)*2;
        System.out.println(area + " " + length);
    }
}


Measured memory_bytes: 25988
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    fast_io;
    
    ll n;
    cin>>n;
    vector<ll> h(n+1);

    for(ll i=0;i<n;i++)
    cin>>h[i];
    vector<ll> dp(n+1);

    //base case
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    //BU
    for(ll i=2;i<n;i++)
    {
        ll op1 = dp[i-1] + abs(h[i]-h[i-1]);
        ll op2 = dp[i-2] + abs(h[i]-h[i-2]);
        dp[i] = min(op1,op2);
    }
    cout<< dp[n-1] <<endl;

    return 0;
}


Measured memory_bytes: 1792
// https://beta.atcoder.jp/contests/abc106

#define SUBMIT
//#define DEBUG

#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const int MAX_N = 500;
const int MAX_M = 200000;
int L[MAX_M + 1];
int R[MAX_M + 1];
// ans[i][j] 区間[i, j]に完全に含まれる電車の数
int memo[MAX_N + 1][MAX_N + 1];
//int ans[MAX_N + 1][MAX_N + 1];
int dp[MAX_N + 1][MAX_N + 1];

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    auto s = std::string(R"(10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10
)");
    stringstream stream(s);
#endif
    int N, M, Q;
    stream >> N >> M >> Q;

    memset(memo, 0, sizeof(memo));
//    memset(ans, 0, sizeof(ans));
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < M; ++i) {
        stream >> L[i] >> R[i];
        memo[L[i]][R[i]]++;
//        for (int l = L[i]; l >= 0; --l) {
//            for (int r = R[i]; r <= N; ++r) {
//                ans[l][r]++;
//            }
//        }
    }

    for (int i = N; i >= 0; --i) {
        for (int j = 1; j <= N; ++j) {
            dp[i][j] = memo[i][j];
            if (j != 1) dp[i][j] += dp[i][j - 1];
        }
    }

    for (int i = N; i >= 0; --i) {
        for (int j = 1; j <= N; ++j) {
            if (i != N) dp[i][j] += dp[i + 1][j];
        }
    }


    int p, q;
    for (int i = 0; i < Q; ++i) {
        stream >> p >> q;
        cout << dp[p][q] << endl;
    }

#ifdef DEBUG
    cout << "memo" << endl;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            cout << memo[i][j] << " ";
        }
        cout << endl;
    }

    cout << "dp" << endl;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    cout << "ans" << endl;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
#endif

    return 0;
}

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

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

  int sum = 0, mxi = 0;

  for (int i = 0; i < N; i++) {
    int L;
    cin >> L;
    sum += L, mxi = max(mxi, L);
  }

  cout << ((mxi < sum - mxi) ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
import math
mod = 10**9+7
ans = 1
n, m = map(int, input().split())
if abs(n - m) > 1:
  print(0)
  quit()
elif n == m:
  ans = 2
ans = ans * math.factorial(n) % mod
ans = ans * math.factorial(m) % mod
print(ans)

Measured memory_bytes: 9960
#include <bits/stdc++.h>
using namespace std;
struct point{
	int a,b;
	point *l,*r,*pa;
	point(){l=r=pa=NULL;}
	point(int aa,int bb):a(aa),b(bb){l=r=pa=NULL;};
};
point *root;
point *rightRotate(point *t){
	point *s=t->l;
	t->l=s->r;
	s->r=t;
	return s;
}
point *leftRotate(point *t){
	point *s=t->r;
	t->r=s->l;
	s->l=t;
	return s;
}
point* insert(point *p,int a,int b){
	if(p==NULL)return new point(a,b);
	if(a==p->a)return p;
	if(a<p->a){
		p->l=insert(p->l,a,b);
		if(p->b<p->l->b)
			p=rightRotate(p);
	}else{
		p->r=insert(p->r,a,b);
		if(p->b<p->r->b)
			p=leftRotate(p);
	}return p;
}
point *_del(point *p, int a);
point *del(point *p,int a){
	if(p==NULL)return NULL;
	if(a<p->a)p->l=del(p->l,a);
	else if(a>p->a)p->r=del(p->r,a);
	else return _del(p,a);
	return p;
}
point *_del(point *p, int a){
	if(p->l==NULL&&p->r==NULL)return NULL;
	else if(p->l==NULL)p=leftRotate(p);
	else if(p->r==NULL)p=rightRotate(p);
	else{
		if(p->l->b>p->r->b)p=rightRotate(p);
		else p=leftRotate(p);
	}return del(p,a);
}
bool find(int a){
	point *p=root;
	while(p){
		if(a==p->a)return 1;
		if(a>p->a)p=p->r;
		else p=p->l;
	}
	return 0;
}
void dfs1(point *p){
	if(!p)return;
	dfs1(p->l);
	printf(" %d",p->a);
	dfs1(p->r);
}
void dfs2(point *p){
	if(!p)return;
	printf(" %d",p->a);
	dfs2(p->l);
	dfs2(p->r);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	int ta,tb;
	string s;
	while(cin>>s){
		if(s=="insert"){
			cin>>ta>>tb;
//			if(!root)root=new point(ta,tb);
//			else 
			root=insert(root,ta,tb);
		}else if(s=="find"){
			cin>>ta;
			if(find(ta))printf("yes\n");
			else printf("no\n");
		}else if(s=="print"){
			dfs1(root);
			printf("\n");
			dfs2(root);
			printf("\n");
		}else if(s=="delete"){
			cin>>ta;
			root=del(root,ta);
		}
	}
	return 0;
}



Measured memory_bytes: 12660
s = int(input())
a = []
a.append(s)
while True:
    x = a[-1]
    y = 0
    if x % 2 == 0:
        y = x // 2
    else:
        y = x * 3 + 1
    if y in a:
        break
    else:
        a.append(y)
print(len(a)+1)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
int main()
{
	long long n,i,sum=0,x=0,j=0,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
	{
		while(j<n&&sum+a[j+1]==(x^a[j+1]))
		{
			j++;
			sum+=a[j];
			x^=a[j];
		}
		if(sum==x)
			ans+=j-i+1;
		sum-=a[i];
		x^=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N =sc.nextInt();
        int count =0;

        String s =sc.next();
        if(s.length()>N){
            return;
        }
        s.toUpperCase();
        int index = s.indexOf("ABC",0);
        if(index==-1){
            System.out.println(0);
            return;
        }
        while (index!=-1){
            count++;
            index=s.indexOf("ABC",index+2);
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21972