akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
h = list(map(int, input().split()))

#dp[i]:i番目に到達するまでにはらうコストの最小値
INF = float('inf')
dp = [INF for i in range(N)]
dp[0] = 0

for i in range(0,N):
    for k in range(1, K+1):
        if i+k > N-1:
            break
        dp[i+k] = min(dp[i+k], dp[i]+abs(h[i+k]-h[i]))


print(dp[N-1])

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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int r,d,x;

signed main()
{
    cin>>r>>d>>x;

    rep(i,10){

        x = r*x-d;
        cout <<x<<endl;


    }

    return 0;
}


Measured memory_bytes: 256
from math import sqrt


def main():
    x = int(input())
    res = 1
    for i in range(2, int(sqrt(x)) + 1):
        b = i ** 2
        while b <= x:
            res = max(res, b)
            b *= i
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    ll h, w;
    cin >> h >> w;
    cout << (H - h) * (W - w) << endl;
}


Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc159/tasks/abc159_d
// math
use std::io;
use std::collections::HashMap;

fn main() {
    let mut n = String::new();

    io::stdin()
        .read_line(&mut n)
        .unwrap();

    let n: i64 = n.trim().parse().unwrap();

    let mut line = String::new();

    io::stdin()
        .read_line(&mut line)
        .unwrap();

    let a: Vec<i64> =
        line
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    let mut balls = HashMap::new();

    for ball in &a {
        let counter = balls.entry(ball).or_insert(0);
        *counter += 1;
    }

    let mut ways = 0;
    for ball in balls.keys() {
        let n: i64 = balls[ball];
        ways += n*(n-1)/2;
    }

    for i in 0..n as usize {
        println!("{}", ways - balls[&a[i]] + 1);
    }
}



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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:

	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	int get_point(){
		return point;
	}

	int get_out(){
		return out;
	}

	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){
			base -= 1000;
			point += 1;
		}
	}

	void home_run(){
		point += 1;
		for(int i = base; i > 0; i /= 10){
			point += i%10;
		}
		base = 0;
	}

	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

	for(int i = 0; i < N; ++i){

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT")
				baseball.hit();
			
			else if(str == "HOMERUN")
				baseball.home_run();

			else if(str == "OUT"){
				baseball.add_out();
			
				if(baseball.get_out() == 3)
					break;
				
			}
		}
	std::cout << baseball.get_point() << std::endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    long long H, W;
    cin >> H >> W;

    vector<string> strVec;
    vector<long long> tmpVec(W, 0);
    vector<vector<long long>> ansVec(H, tmpVec);

    string input;
    for (int i = 0; i < H; i++)
    {
        cin >> input;
        strVec.push_back(input);
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (strVec[i][j] == '#')
            {
                if (i - 1 >= 0 && j - 1 >= 0)
                {
                    ansVec[i - 1][j - 1]++;
                }

                if (i - 1 >= 0)
                {
                    ansVec[i - 1][j]++;
                }

                if (j - 1 >= 0)
                {
                    ansVec[i][j - 1]++;
                }

                if (i - 1 >= 0 && j + 1 < W)
                {
                    ansVec[i - 1][j + 1]++;
                }

                if (i + 1 < H && j - 1 >= 0)
                {
                    ansVec[i + 1][j - 1]++;
                }

                if (i + 1 < H && j + 1 < W)
                {
                    ansVec[i + 1][j + 1]++;
                }

                if (i + 1 < H)
                {
                    ansVec[i + 1][j]++;
                }

                if (j + 1 < W)
                {
                    ansVec[i][j + 1]++;
                }
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (strVec[i][j] == '#')
            {
                cout << "#";
            }
            else
            {
                cout << ansVec[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m,Q;
	cin >> n >> m >> Q;
	vector<int> l(m),r(m);
	vector<vector<int> > t(n+1);
	for(int i = 0; i < n+1; i++){
		t[i].resize(n+1);
		t[i].assign(t[i].size(),0);
	}
	for(int i = 0; i < m; i++){
		cin >> l[i] >> r[i];
		t[l[i]][r[i]]++;
	}

	vector<vector<int> > s(n+1);
	for(int i = 0; i < n+1; i++){
		s[i].resize(n+1);
		s[i].assign(s[i].size(),0);
		s[i][0] = t[i][0];
	}

	for(int i = 0; i < n+1; i++){
		for(int j = 1; j < n+1; j++){
			s[i][j] += t[i][j] + s[i][j-1];
		}
	}
	for(int i = 1; i < n+1; i++){
		for(int j = 0; j < n+1; j++){
			s[i][j] += s[i-1][j];
		}
	}
	// printf("\n");
	// for(int i = 0; i < n+1; i++){
	// 	for(int j = 0; j < n+1; j++){
	// 		cout << s[i][j] << " ";
	// 	}printf("\n");
	// }

	for(int i = 0; i < Q; i++){
		int p,q;
		cin >> p >> q;
		// int res = 0;
		// cout << res << endl;
		cout << s[q][q] - s[p-1][q] - s[q][p-1] + s[p-1][p-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 4480
N = input()
n = int(N[len(N)-1] )
if n == 0 or n == 1 or n ==  6 or n == 8   :
    print('pon')
elif n == 2 or n == 4 or n == 5 or n == 7 or n == 9 :
    print('hon')
elif n == 3 :
    print('bon')



Measured memory_bytes: 9172
program who_says_a_pun
  implicit none
  integer :: n, i, j, ans = 0, z(5000) = 0
  character(5000) :: s
  read(*,*) n
  read(*,*) s
  do i = 1, n
    z(1:n-i+1) = z_algorithm(s(i:n))
    do j = 2, n-i+1
      ans = max(ans,min(j-1,z(j)))
    end do
  end do
  write(*,'(i0)') ans
contains
  function z_algorithm(s) result(z)
    implicit none
    character(*) :: s
    integer :: z(len_trim(s)), n, i, j, k
    z = 0
    n = len_trim(s)
    z(1) = n
    i = 1
    j = 0
    do while (i < n)
      do while (i+j < n .and. s(j+1:j+1) == s(i+j+1:i+j+1))
        j = j+1
      end do
      z(i+1) = j
      if (j == 0) then
        i = i+1
        cycle
      end if
      k = 1
      do while (i+k < n .and. k+z(k+1) < j)
        z(i+k+1) = z(k+1)
        k = k+1
      end do
      i = i+k
      j = j-k
    end do
  end
end program who_says_a_pun

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int tt;
  cin >> tt;
  while (tt--) {
    int n;
    cin >> n;
    long long res = 0;
    vector c(2, vector<vector<int>>(n + 1));
    for (int i = 0; i < n; ++i) {
      int k, a, b;
      cin >> k >> a >> b;
      if (a < b) {
        res += a;
        c[1][k].push_back(b - a);
      } else {
        res += b;
        c[0][n - k].push_back(a - b);
      }
    }
    for (int t : {0, 1}) {
      priority_queue<int> pq;
      for (auto&& v : c[t]) {
        if (not empty(pq)) {
          res += pq.top();
          pq.pop();
        }
        for (auto e : v) {
          pq.push(e);
        }
      }
    }
    cout << res << '\n';
  }
}


Measured memory_bytes: 17192
import collections
N = int(input())
A = list(map(int,input().split()))

c = collections.Counter(A)
cc = c.items()

f_ans = 0
for m,n in cc:
  f_ans += n*(n-1)/2

for i in range(N):
  a = A[i]
  b = c[a]
  sa = b*(b-1)/2 - (b-1)*(b-2)/2

  print(int(f_ans - sa))

Measured memory_bytes: 26780
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1005,mod=1e9+7;
int n,m;
LL k;
char s[N][N];
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch))
		ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return x;
}
int Pow(int x,LL y){
	int ans=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1LL)
			ans=1LL*ans*x%mod;
	return ans;
}
int f1=0,f2=0;
int check(){
	for (int i=1;i<=n;i++)
		if (s[i][1]=='#'&&s[i][m]=='#')
			f1++;
	for (int i=1;i<=m;i++)
		if (s[1][i]=='#'&&s[n][i]=='#')
			f2++;
	return (bool)f1+(bool)f2;
}
int cntjing(){
	int cnt=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (s[i][j]=='#')
				cnt++;
	return cnt;
}
struct Mat{
	int v[2][2];
	Mat(){}
	Mat(int x){
		memset(v,0,sizeof v);
		for (int i=0;i<2;i++)
			v[i][i]=x;
	}
	void set(int c0,int c1,int c3){
		v[0][0]=c3	,v[0][1]=mod-c1	;
		v[1][0]=0	,v[1][1]=c0		;
	}
}M;
Mat operator * (Mat A,Mat B){
	Mat C(0);
	for (int i=0;i<2;i++)
		for (int j=0;j<2;j++)
			for (int k=0;k<2;k++)
				C.v[i][j]=(1LL*A.v[i][k]*B.v[k][j]+C.v[i][j])%mod;
	return C;
}
Mat Pow(Mat x,LL y){
	Mat ans(1);
	for (;y;y>>=1,x=x*x)
		if (y&1LL)
			ans=ans*x;
	return ans;
}
int main(){
	n=read(),m=read(),k=read();
	if (k==0)
		return puts("1"),0;
	for (int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	int v=check(),c0=cntjing();
	if (v==0)
		return printf("%d\n",Pow(c0,k-1)),0;
	if (v==2)
		return puts("1"),0;
	int c1=0,c2=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++){
			if (j<m&&s[i][j]=='#'&&s[i][j+1]=='#')
				c1++;
			if (i<n&&s[i][j]=='#'&&s[i+1][j]=='#')
				c2++;
		}
	if (f2)
		swap(c1,c2),swap(f1,f2);
	int c3=f1;
	M.set(c0,c1,c3);
	M=Pow(M,k-1);
	LL ans=M.v[0][1]+M.v[1][1];
	ans=(ans%mod+mod)%mod;
	printf("%d",(int)ans);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
//#define fi first
//#define se second
#define be begin()
#define en end()
#define reverse
const int mod=1000000007;
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
  return max(a,b)-min(a,b);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,x,sum,ans=-1;
  int c[50],a[50][50];
  bool f;
  cin>>n>>m>>x;
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  for(int bit=0;bit<(1<<n);bit++){
    int date[50]={};
    sum=0;
    f=true;
    for(int i=0;i<n;i++){
      if(bit&(1<<i)){
        for(int j=0;j<m;j++){
          date[j]+=a[i][j];
        }
        sum+=c[i];
      }
    }
    for(int j=0;j<m;j++){
      if(date[j]<x) f=false;
    }
    if(f){
      if(ans==-1) ans=sum;
      else ans=min(ans,sum);
    }
  }
  cout<<ans<<"\n";
}

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

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

int cur;
string str;

int expr(int P, int Q, int R)
{
    int a, b, op;
    switch (str[cur]) {
        case '0': case '1': case '2': return str[cur++] - '0';
        case 'P': ++cur; return P;
        case 'Q': ++cur; return Q;
        case 'R': ++cur; return R;
        case '-': ++cur; return 2 - expr(P, Q, R);
        default:
            ++cur;
            a = expr(P, Q, R);
            op = str[cur++] == '*';
            b = expr(P, Q, R);
            ++cur;
            if (op) return min(a, b);
            return max(a, b);
    }
}

int main()
{
    while (cin >> str, str != ".") {
        int cnt = 0;
        rep (P, 3) rep (Q, 3) rep (R, 3) {
            cur = 0;
            if (expr(P, Q, R) == 2) ++cnt;
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,index;
    double p,t,a,temp=9999999.0;
    scanf("%d",&n);
    scanf("%lf %lf",&t,&a);
    vector <double> arr;
    for(int i=0;i<n;i++){
        scanf("%lf",&p);
        arr.push_back(p);
        arr[i]=abs(a-(t - (arr[i]*0.006)));
    }

     for(int i=0;i<n;i++){
        if(arr[i]<temp){
            temp=arr[i];
            index=i;
     }
}
printf("%d",index+1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n;
vector<P> v[101010];//v_from(to, value)
bool used[101010];
bool color[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int a,b,c;
		cin >> a >> b >> c;
		c %= 2;
		v[a].push_back(P(b,c));
		v[b].push_back(P(a,c));
	}
	
	queue<P> q;
	q.push(P(1,0));//ばしょ,色
	while(!q.empty()){
		P p = q.front();
		q.pop();
		used[p.first] = 1;
		color[p.first] = p.second;
		for(int i = 0; i < v[p.first].size();i++){
			if(used[v[p.first][i].first]) continue;
			q.push(P(v[p.first][i].first, (v[p.first][i].second+p.second)%2));
		}
	}
	
	for(int i = 1; i <= n; i++){
		cout << color[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 10112
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

I = np.array(sys.stdin.read().split(), dtype=np.int64)
h, w = I[:2]
c = I[2:102].reshape(10, 10)
a = I[102:].reshape(h, w)
                                                              
def main():
    cost = floyd_warshall(csr_matrix(c), directed=True).astype(np.int64)
    
    res = cost[a[a != -1], 1]
    return np.sum(res)

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 17360
//  SMOKE SHISHA PLAY FIFA  // 
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll t=1;
	//cin >> t;
	while(t--)
	{
		ll n;
		cin>>n;
		ll a[n+1],b[n+1],c[n+1],dp[3][n];
		lp(i,1,n)
			cin>>a[i]>>b[i]>>c[i];
		 dp[0][1] = a[1];
   		 dp[1][1] = b[1];
    	 dp[2][1] = c[1];
    for(int i = 2; i <= n; i++) {
        dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
        dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
        dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
    }
    cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) <<endl; 
	}
	return 0;	
}


Measured memory_bytes: 4992
a,b,c,d=map(int,input().split())
if a<c:
    if c<b and b<d:
        print(b-c)
    elif c<b and b>=d:
        print(d-c)
    else:
        print(0)
else:
    if a<d and d<b:
        print(d-a)
    elif a<d and d>=b:
        print(b-a)
    else:
        print(0)

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

int main()
{
  i64 n, m;
  cin >> n >> m;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  vector<pair<i64, i64>> p(m);
  for (i64 i = 0; i < m; i++)
    cin >> p[i].second >> p[i].first;
  sort(a.begin(), a.end());
  sort(p.begin(), p.end(), greater<pair<i64, i64>>());
  i64 now = 0;
  for (i64 i = 0; i < n; i++)
    if (now < m && a[i] < p[now].first)
    {
      a[i] = p[now].first;
      p[now].second--;
      if (p[now].second == 0)
        now++;
    }
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    ans += a[i];
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n;
	cin>>n;
	
	vector<int> a(n);
	REP(i,n){
		scanf("%d",&a[i]);
	}
	
	vector<int> left(n),right(n);//i番目の要素を書き換えた時の左側、右側それぞれの集合の最大公約数.
	left[1]=a[0];
	for(int i=2;i<n;++i){
		left[i]=__gcd(left[i-1],a[i-1]);
	}
	right[n-2]=a[n-1];
	for(int i=n-3;i>=0;--i){
		right[i]=__gcd(a[i+1],right[i+1]);
	}
	left[0]=right[0];
	right[n-1]=left[n-1];
	
	int ans=0;
	REP(i,n){
		ans=max(ans,__gcd(left[i],right[i]));
	}
	
	cout<<ans<<endl;
}//解説参考.

Measured memory_bytes: 1408
#include <cstdio>
int main()
{
	int K,A,B;scanf("%d%d%d",&K,&A,&B);
	K++;
	if(A>=B || K<A)
		printf("%d\n",K);
	else
	{
		K-=A;
		long long ans=A+(long long)K/2*(B-A)+K%2;
		printf("%lld\n",(ans<=(long long)K+A?(long long)K+A:ans));
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				String s = nextToken();
				if (s.equals("snuke")) {
					out.print((char)('A' + j));
					out.println(i + 1);
					return;
				}
			}
		}
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 8404
n = int(input())
n -= 1
i = 1
temp = 0
while temp <= n:
    temp += 26**i
    i += 1
temp -= 26**(i-1)
#print(n-temp)
R = n-temp
#print(i)

ans = []
for k in range(i-1):
    q, r = divmod(R, 26)
    ans.append(chr(r+ord('a')))
    R = q
#print(ans)
ans.reverse()
print(''.join(ans))


Measured memory_bytes: 61892
using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = true;
            while (flag)
            {
                string[] array = Console.ReadLine().Split(' ');
                int a = int.Parse(array[0]);
                int b = int.Parse(array[2]);
                switch (array[1])
                {
                    case "+":
                        Console.WriteLine(a + b);
                        break;
                    case "-":
                        Console.WriteLine(a - b);
                        break;
                    case "/":
                        Console.WriteLine(a / b);
                        break;
                    case "*":
                        Console.WriteLine(a * b);
                        break;
                    case "?":
                        flag = false;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}

Measured memory_bytes: 9100
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n;
  string s_out;
  cin >> n;
  s_out = to_string(n);
  size_t l = s_out.length();
  for (int i=l-1;i<2;i++) {
    s_out = "0" + s_out;
  }
  s_out = "ABC" + s_out;
  cout << s_out << endl;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	if (s == "RRR")
		cout << "3";
	else if (s == "RRS" || s == "SRR")
		cout << "2";
	else if (s == "RSS" || s == "SRS" || s == "SSR" || s == "RSR")
		cout << "1";
	else
		cout << "0";
	cout << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include  <string>
#include <cmath>

using namespace std;

int main(){
  long long a, k, b;
  cin >> a >> b >> k;
  long long ans;
  if (k >= b-1){
    ans = floor(double(b-1)/double(b) * a) - floor(double(b-1)/double(b))*a;
  }
  else {
    ans = floor(double(k)/double(b) * a) - floor(double(k)/double(b))*a;
  }
  cout << ans << "\n";

}

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

int main(){
    int lim = 1e6;
    vector<bool> p(lim, true);
    p[0] = p[1] = false;
    for(int i=2; i*i<lim; i++){
        if(!p[i]) continue;
        for(int j=i*2; j<lim; j+=i){
            p[j] = false;
        }
    }

    int l,r;
    cin >> l >> r;
    vector<int> npf(r-l+1, 0);
    vector<int> num(r-l+1);
    for(int i=0; i<=r-l; i++){
        num[i] = l+i;
    }
    for(int i=2; i*i<=r; i++){
        if(!p[i]) continue;
        for(int j=-l%i; j<=r-l; j+=i){
            if(j < 0) continue;
            while(num[j]%i == 0){
                npf[j]++;
                num[j] /= i;
            }
        }
    }
    int ans = 0;
    for(int i=0; i<=r-l; i++){
        if(num[i] != 1) npf[i]++;
        if(p[npf[i]]) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define ll long long
const int mod = 1e9+7;
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)res=res*b%mod;
        b>>=1;
        a=a*a%mod;

    }
    return res;
}
vector<int>g[111111];
pair<int,int>E[111111];
map<pair<int,int>,int>m;
int deg[111111];
void dfs(int x,int pre){
    //cout<<x<<" "<<pre<<endl;
    int i;
    int cnt=1;
    for(i=0;i<g[x].size();i++){
        if(cnt==m[{x,pre}])cnt++;
        if(g[x][i]!=pre){
            m[{x,g[x][i]}]=cnt;
            m[{g[x][i],x}]=cnt;
            cnt++;
            dfs(g[x][i],x);
        }
    }
}
int main(){
    int i,n;
    cin>>n;
    for(i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        E[i]={x,y};
        g[x].push_back(y);
        g[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    int ma=0;
    for(i=1;i<=n;i++)ma=max(ma,deg[i]);
    dfs(1,0);
    cout<<ma<<endl;
    for(i=1;i<n;i++){
        cout<<m[E[i]]<<endl;
    }
}


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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)5e6 + 123, mod = (int)1e9 + 7;

ll dp[2500][2500], f[N], rf[N], n, k;
void add(ll &a, ll b){
	a += b;
	if(a >= mod)
		a -= mod;
}
ll binpow(ll x,ll p){
	ll res = 1;
	while(p){
		if(p&1)
			res = res * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return res;
}
ll C(int k,int n){
	return f[n] * rf[k] % mod * rf[n - k] % mod;
}
int main(){    
	f[0] = 1;
	for(int i = 1; i < N; i++)
		f[i] = 1ll * f[i - 1] * i % mod;
	rf[N - 1] = binpow(f[N - 1], mod - 2);
	for(int i = N - 2; i >= 0; i--)
		rf[i] = 1ll * rf[i + 1] * (i + 1) % mod;
	
	cin >> n >> k;

	if(k == 1)
		cout << 1, exit(0);
	
	dp[0][0] = 1;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			add(dp[i + 1][j], dp[i][j]);
			if(j < i)
            	add(dp[i][j + 1], 1ll *  dp[i][j] * C(k - 2, (n - j) * (k - 1) + n - i - 1) % mod );
		//	cerr << dp[i][j] << " ";
		}
		//cerr << endl;
	}

	cout << dp[n][n] * f[n] % mod << endl;
	return 0;
}
                     

Measured memory_bytes: 119040
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int a;
	map<int, int> numbers;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (numbers.count(a)) {
			numbers.erase(a);
		} else {
			numbers[a] = 1;
		}
	}

	cout << numbers.size() << "\n";

	return 0;

}

Measured memory_bytes: 4992
import sys
readline = sys.stdin.readline

S = readline().rstrip()
T = readline().rstrip()

# dp[i][j] = Sをi文字目、Tをj文字目まで進めたときの最長
# S[i] == S[j]のとき
# dp[i][j] = dp[i - 1][j - 1] + 1
# S[i] != S[j]のとき
# dp[i][j] = max(dp[i - 1][j],dp[i][j - 1])

# その際、自分がどこから来たか？を記録する
# dp[i - 1][j] > dp[i][j - 1]であれば
# route[i][j] = (i,j)を記録

dp = [[0] * (len(T) + 1) for i in range(len(S) + 1)]

for i in range(len(S)):
  for j in range(len(T)):
    if S[i] == T[j]:
      dp[i + 1][j + 1] = dp[i][j] + 1
    else:
      if dp[i][j + 1] > dp[i + 1][j]:
        dp[i + 1][j + 1] = dp[i][j + 1]
      else:
        dp[i + 1][j + 1] = dp[i + 1][j]

# dpテーブルの数字を見て復元していく
ans = ""
x = len(S)
y = len(T)
while x != 0 and y != 0:
  if dp[x][y] == dp[x - 1][y]: # x - 1から遷移してきた
    x -= 1
  elif dp[x][y] == dp[x][y - 1]: # y - 1から遷移してきた
    y -= 1
  else:
    ans += S[x - 1]
    x -= 1
    y -= 1

print(ans[::-1])

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

int main() {
  int n;
  cin >> n;
  bool c = false;
  for(int i = 1;i < 10;i++) {
    if(n % i == 0 && n <= i * 9) c = true;
  }
  cout << (c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3588
class D_Linked_List:
    """Doubly Linked List class.

    ?????¢?????´???????????¨??????????§???????p.96-100.
    """
    class Node:
        def __init__(self, key, next = None, prev = None):
            self.next = next
            self.prev = prev
            self.key = key

    def __init__(self):
        self.nil = D_Linked_List.Node(None)
        self.nil.next = self.nil
        self.nil.prev = self.nil

    def insert(self, key):
        node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
        self.nil.next.prev = node_x
        self.nil.next = node_x

    def _listSearch(self, key):
        cur_node = self.nil.next
        while (cur_node != self.nil) and (cur_node.key != key):
            cur_node = cur_node.next
        return cur_node

    def _deleteNode(self, node):
        if node == self.nil:
            return None
        node.prev.next = node.next
        node.next.prev = node.prev

    def deleteFirst(self):
        self._deleteNode(self.nil.next)

    def deleteLast(self):
        self._deleteNode(self.nil.prev)

    def deleteKey(self, key):
        node = self._listSearch(key)
        self._deleteNode(node)

    def show_keys(self):    # ????????????node???key????????????????????§??????????????????????????§???
        cur_node = self.nil.next
        keys = []
        while cur_node != self.nil:
            keys.append(cur_node.key)
            cur_node = cur_node.next
        print(' '.join(keys))


import sys

d_ll = D_Linked_List()

for i in sys.stdin:
    if 'insert' in i:
        x = i[7:-1]
        d_ll.insert(x)
    elif 'deleteFirst' in i:
        d_ll.deleteFirst()
    elif 'deleteLast' in i:
        d_ll.deleteLast()
    elif 'delete' in i:
        x = i[7:-1]
        d_ll.deleteKey(x)
    else:   # ??\??????????????¨?????????command??§??????????????§???pass?????????
        pass

d_ll.show_keys()

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

const int INF=1e+9;
int N;
int h[100010];
int dp[100010];
int main()
{
  cin >> N;
  for(int i=0;i<N;++i){
    cin >> h[i];
  }
  for(int i=0;i<N;++i){
    dp[i]=INF;
  }
  dp[0]=0;
  for(int i=0;i<N;++i){
    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] << "\n";
  return 0;
}


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

using namespace std;

struct Point
{
    int id, x, y;
};

const int MAXN = 1E5;
int parent[MAXN + 1];
int s[MAXN + 1];
Point pts[MAXN + 1];
tuple<int, int, int> edges[2 * (MAXN - 1)];

int getRoot(int x)
{
    if (parent[x] != x)
        parent[x] = getRoot(parent[x]);
    return parent[x];
}

void mge(int a, int b)
{
    int r1 = getRoot(a);
    int r2 = getRoot(b);
    if (r1 == r2)
        return;
    if (s[r1] < s[r2])
        swap(r1, r2);
    parent[r2] = r1;
    s[r1] += s[r2];
}

bool cmpx(Point a, Point b)
{
    return a.x < b.x;
}

bool cmpy(Point a, Point b)
{
    return a.y < b.y;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        parent[i] = i;
        s[i] = 1;
        pts[i].id = i;
        cin >> pts[i].x >> pts[i].y;
    }
    sort(pts + 1, pts + n + 1, cmpx);
    int cnt = 0;
    for (int i = 1; i < n; i++)
    {
        edges[cnt++] = make_tuple(pts[i + 1].x - pts[i].x, pts[i].id, pts[i + 1].id);
    }
    sort(pts + 1, pts + n + 1, cmpy);
    for (int i = 1; i < n; i++)
    {
        edges[cnt++] = make_tuple(pts[i + 1].y - pts[i].y, pts[i].id, pts[i + 1].id);
    }
    sort(edges, edges + cnt);
    long long ans = 0;
    for (int i = 0; i < cnt; i++)
    {
        int a = get<1>(edges[i]);
        int b = get<2>(edges[i]);
        if (getRoot(a) != getRoot(b))
        {
            ans += get<0>(edges[i]);
            mge(a, b);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,n) for(i=0;i<n;i++)

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

  ll sum=min(a,k);
  k=max(0ll,k-a);
  k=max(0ll,k-b);
  sum-=k;
  cout<<sum;


    cout<<endl;




    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+333;
#define ll long long
ll a[N],b[60];
ll n,m,k;
ll az[60],cnt,f[60];
int main(){
	//freopen("p.in","r",stdin);
	//freopen("p.out","w",stdout);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
	cin>>a[i];
	for(int j=1;j<=45;j++)
	if(a[i]&(1ll<<(j-1)))b[j]++;
	}	
	for(int i=45;i>=0;i--){
	ll ax=1ll<<i;
	if(k>=ax){cnt=i+1;break;}}
	for(int i=cnt;i>=1;i--){
	if(k&(1ll<<(i-1)))az[i]=1;
	}
	int dd;
	for(int i=1;i<=cnt;i++){
		ll ans;
	ans=0;
		for(int j=1;j<=i-1;j++)
			ans+=max(n-b[j],b[j])*(1ll<<(j-1));
 		if(az[i]==0){
		 f[i]=f[i-1]+b[i]*(1ll<<(i-1));}
		else f[i]=max(ans+b[i]*(1ll<<(i-1)),f[i-1]+max(n-b[i],b[i])*(1ll<<(i-1)));
	}
	for(int i=cnt+1;i<=45;i++)
	f[cnt]+=b[i]*(1ll<<(i-1));
	cout<<f[cnt];
	return 0;
}

Measured memory_bytes: 1024
n,y = map(int, input().split())

y //= 1000
a,b,c = -1,-1,-1


fit = False
for ai in range(n+1):

    if ai*10> y or fit:
        break
    if ai == y:
        a,b,c = ai,0,0

    remain = n-ai
    for bi in range(remain+1):
        ci = remain - bi
        
        if y == ai *10  + bi * 5 + ci :
            a,b,c = ai,bi,ci
            fit = True

print('{} {} {}'.format(a,b,c))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int compar(const int *val1, const int *val2) {
    if ( *val1 < *val2 ) {
        return -1;
    } else if ( *val1 == * val2 ) {
        return 0;
    } else {
        return 1;
    }
}

int main(){
    int N,K;
int ans=0;
    cin>>N>>K;
    int l[51];
    for(int i=0;i<N;i++){
        scanf("%d",&l[i]);
    }
    qsort(l,N,sizeof(int),(int (*)(const void *, const void *))compar);
//for(int i=0;i<N;i++) printf("%d ",l[i]);
    for(int i=N;i>N-K;i--){
        ans+=l[i-1];
    }
   printf("%d",ans);
    return 0;
    

}

Measured memory_bytes: 764
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

s = N - M * 2
if s < 0:
    print(0)
else:
    print(s)

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

int main(){
	int a,b,c,x,y; cin>>a>>b>>c>>x>>y;
	c*=2;
	int n=max(x,y);
	ll ans;
	for(int i=0; i<=n; i++){
		ll t=a*x+b*y+c*i;
		ans=min(ans,t);
		if(x>0) x--;
		if(y>0) y--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

#include "algorithm"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll N;
  cin >> N;

  ll res = 0;

  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ll j = N / i;
      if (i < j - 1) res += j - 1;
      if (j < i - 1) res += i - 1;
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  int a,l,x;
  double s,in1,in2;
  
  while(scanf("%d%d%d",&a,&l,&x) != EOF){
    
    in1=4*l*l-a*a;
    in2=x*x+2*x*l;
    
    s=(double)a*sqrt(in1)/4 + (double)l*sqrt(in2)/2;
    
    printf("%.10f\n",s);

  }
  
  return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 19 03:01:30 2018

@author: ashida
"""

N = int(input())

ans = []

for i in range(N):
    d = int(input())
    if d in ans:
        tmp = 1
    else:
        ans.append(d)
        
print(len(ans))

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var A = cin.Nextint;
        var B = cin.Nextint;
        var C = cin.Nextint;
        //Ax = By + C
        bool flag = false;
        for (int i = 0; i < B; i++)
        {
            if ((A + A * i) % B == C)
            {
                flag = true;
            }
        }
        WriteLine(flag ? "YES" : "NO");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
mod=10**9+7
n=10**5+100
inv=[0]*(n+1)
inv[1]=1
for i in range(2,n+1):
    inv[i]=-(mod//i)*inv[mod%i]%mod
for i in range(1,n+1):
    inv[i]=(inv[i]+inv[i-1])%mod
N=int(input())
X=[0]+list(map(int,input().split()))
data=[1,1]
for i in range(2,N+1):
    data.append(data[-1]*i%mod)
ans=X[2]-X[1]
for k in range(2,N):
    ans=(k*ans%mod+data[k]*inv[k]*(X[k+1]-X[k])%mod)%mod
print(ans)    

Measured memory_bytes: 67096
#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 vi vector<int>
#define vl vector<long>
#define vll vector<long long>
 
#define infi INT_MAX
#define infl LONG_MAX
#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 F first
#define S second
#define G(a,b) get<a>(b)
#define MP make_pair
#define MT make_tuple

void func()
{
 ll n;
 cin>>n;
 ll dp[n],h[n];
 f(i,0,n)  cin>>h[i],dp[i]=infl;
 dp[0]=0;
 f(i,0,n)
 {
   if(i+1<n)
   {
     dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
   }
   if(i+2<n)
    {
     dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
   }
 }
 cout<<dp[n-1]<<endl;
}
 
int main() 
{
    fast
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    
    ll q=1;
    //cin>>q;
    while(q)
    {
      func();
      q--;
    }
 
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
//#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
//#define int long long
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

const int N = 100100;
int good[N];

int32_t main(){
 fastio;
 int n,k,q;
 cin>>n>>k>>q;
 for(int i=0;i<q;i++){
  int x;
  cin>>x;
  good[x]++;
 }

 for(int i=1;i<=n;i++){
  if(k - (q - good[i])<=0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
 }

  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

Measured memory_bytes: 1024
using AtCoderBeginnerContest120.Questions;
using AtCoderBeginnerContest120.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest120.Questions
{
    public class QuestionC : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            var zeros = s.Count(c => c == '0');
            var ones = s.Count(c => c == '1');
            yield return Math.Min(zeros, ones) * 2;
        }
    }
}


namespace AtCoderBeginnerContest120
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionC();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest120.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest120.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int mat[100001][3];
int solve(int arr[][3] , int size , int col){
	if(size==0){
		return arr[0][col];
	}
	if(mat[size][col]!=-1){
		return mat[size][col];
	}
	if(col==0){
//		cout<<col<<"\n";
//		cout<<solve(arr,size-1,1)+arr[size][col]<<"   ";
//		cout<<solve(arr,size-1,2)+arr[size][col]<<"\n";
	return mat[size][col]  = max( solve(arr,size-1,1)+arr[size][col] , solve(arr,size-1,2)+arr[size][col]  );	
	}
	else if(col==1){
//		cout<<col<<"\n";
//		cout<<solve(arr,size-1,0)+arr[size][col]<<"   ";
//		cout<<solve(arr,size-1,2)+arr[size][col]<<"\n";
		return mat[size][col] =  max( solve(arr,size-1,0)+arr[size][col] , solve(arr,size-1,2)+arr[size][col]  );	
	}
	else if(col==2){
//		cout<<col<<"\n";
//		cout<<solve(arr,size-1,0)+arr[size][col]<<"   ";
//		cout<<solve(arr,size-1,1)+arr[size][col]<<"\n";
		return mat[size][col]  = max( solve(arr,size-1,0)+arr[size][col] , solve(arr,size-1,1)+arr[size][col]  );	
	}
}
int main()
{

memset(mat, -1 ,sizeof(mat));

int n;
cin>>n;
int arr[n][3] ,size;
for(int i=0;i<n;i++){
	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
}
int col = 0;
int s1 ,s2 ,s3 ;

s1 = solve(arr , n-1 ,0 );
s2 = solve(arr , n-1 ,1 );
s3 = solve(arr , n-1 ,2 );

//cout<<s1<<" "<<s2<<" "<<s3;

cout<<max( max(s1,s2) , s3);
	
   return 0;
}


Measured memory_bytes: 12076
#include<bits/stdc++.h>
using namespace std;
 
int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n;
   cin >> n;
   long long int ans = 0;
   for(int i=1;i<n+1;i++)
   {
      int cnt = n / i;
      long long int res = (long long)cnt * (cnt + 1) / 2 * i;
      ans += res;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 3652
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int LL;
char ss[1005];
int main(void){
    scanf("%s",ss);
    int i;
    int s=0,n=0,e=0,w=0;
    for(i=0;ss[i];i++){
		if(ss[i]=='S') s++;
		if(ss[i]=='N') n++;
		if(ss[i]=='W') w++;
		if(ss[i]=='E') e++;
	}
	if((n==0&&s!=0) || (s==0&&n!=0) || (w==0&&e!=0) || (e==0&&w!=0)) printf("No\n");
	else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256