akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb 	push_back
#define ll  long long
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define debug(x) cerr<<#x<<" =: "<<x<<endl;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Find find_by_order
#define Order order_of_key
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 mrand(random_device{}());
ll rnd(ll x) { return mrand() % x;}
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;while(b){if(b&1) ans=ans*a%mod;b>>=1;a=a*a%mod;}return ans;}
ll phi(ll n){ll ans=n;for(ll i=2;i*i<=n;i++){if(n%i==0) {while(n%i==0) n/=i;ans=ans*(i-1)/i;}}if(n>1) ans=ans*(n-1)/n;return ans;}
//head

const int maxn = 1e6 + 7;
vector<int> vec[maxn];
int a[maxn], ans[maxn];
set<int>s;

void dfs(int u, int fa){
    auto it = s.lower_bound(a[u]);
    int flag = -1;
    if (it != s.end()){
        flag=*it;
        s.erase(it);
    }
    s.insert(a[u]);
    ans[u] = s.size();
    for (auto v:vec[u]){
        if (v != fa) dfs(v, u);
    }
    s.erase(a[u]);
    if (flag != -1) s.insert(flag);
}

int main (){
    int n; cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        int x, y; cin >> x >> y;
        x--;
        y--;
        vec[x].pb(y);
        vec[y].pb(x);
    }
    dfs(0, -1);
    for (int i = 0; i < n; i++) cout << ans[i] <<endl;
    return 0;
}


Measured memory_bytes: 46700
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <chrono>
#include <numeric>

using namespace std;

long long n;
char s[500001];
long long z[500001];
vector<vector<long long>> v;

long long solve(const vector<long long> &a) {
  size_t a_len = a.size();
  long long l, r1, r2, l_prev, r1_prev, r2_prev;
  l_prev = 0;
  r1_prev = 0;
  r2_prev = a[0];
  for (long long i=1;i<(a_len-1);i++) {
    if (a[i] > 1) {
      // l:left pattern O
      l = max(l_prev + a[i] - 1, max(r1_prev, r2_prev));
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], max(r1_prev, r2_prev));
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, max(r1_prev, r2_prev - 1)) + a[i];
    } else {
      // l:left pattern O
      l = max(l_prev, r1_prev);
      // r1:left pattern X, segment length not decrease
      r1 = max(l_prev + a[i], r2_prev);
      // r2:left pattern X, segment length decrease
      r2 = max(l_prev, r1_prev) + a[i];
    }
    l_prev = l;
    r1_prev = r1;
    r2_prev = r2;
  }
  l = l_prev + a[a_len-1] ;
  r1 = r1_prev;
  r2 = r2_prev;
  return(max(l_prev + a[a_len-1], max(r1_prev, r2_prev)));
}

int main(){
  cin >> n;
  cin >> s;
  long long l1 = 0;
  long long r1 = 0;
  long long c1 = 0;
  long long ioi = 0;
  long long tot = 0;
  vector<long long> tmpv;
  for (long long i=0;i<n;i++) {
    if (s[i] == '1') {
      c1++;
    } else {
      if (c1==0) {
	if (tmpv.size()>0)
	if (tmpv.size()>1) {
	  tot += solve(tmpv);
	}
	tmpv.clear();
      } else if (c1>0) {
	tmpv.push_back(c1);
      }
      c1 = 0;
    }
  }
  if (c1>0) 
    tmpv.push_back(c1);
  if (tmpv.size() > 1)
    tot += solve(tmpv);
  cout << tot << endl;
}


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

signed main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	long n; cin >> n;
	long i = sqrt(n);
	for (; i; i--) if (n % i == 0) break;
	cout << i + n/i - 2 << '\n';
}


Measured memory_bytes: 3696
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

void solve() {
  string s; cin >> s;
  for(auto &x : s) {
    if(x == '?') x = 'D';
  }
  cout << s << '\n';
}

int main() {
  int t; t = 1;
  while(t--) solve();
}

Measured memory_bytes: 3760
#include <stdio.h>
#include <stdlib.h>
int main() {
  int i, N, T, *c, *t, min = 1001;
  scanf("%d %d%*c", &N, &T);
  c = (int *)malloc(sizeof(int) * N);
  t = (int *)malloc(sizeof(int) * N);
  for (i = 0; i < N; i++) {
    scanf("%d %d%*c", &c[i], &t[i]);
    if (t[i] > T) continue;
    if (c[i] < min) min = c[i];
  }
  if (min == 1001) printf("TLE\n");
  else printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e18)

int main() {
  ll N;
  cin >> N;
  ll ans = 1;
  for (ll i = 0; i < N; i++) {
    ld a;
    cin >> a;
    if (a > 0 && ans > floor(INF / a)) {
      ans = -1;
    }
    if (ans >= 0 || a == 0)
      ans *= ll(a);
  }

  cout << ans << endl;
}


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

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	long long h, d;
	cin >> h >> d;
	if(h % d == 0) cout << h/d;
	else cout << h/d + 1;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent; 
};
 
Node *root,*NIL;
 
Node * treeMinimum(Node *x){
  while(x->left!=NIL) x=x->left;
  return x;
}
 
Node * find(Node *u,int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}
 
Node * treeSuccessor(Node *x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node *y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
 
void treeDelete(Node *z){
  Node *y;
  Node *x;
 
  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);
 
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
 
  if(x!=NIL){
    x->parent=y->parent;
  }
 
  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }
 
  if(y!=z){
    z->key=y->key;
  }
 
  free(y);
}
 
void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  
  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}
  
void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
  
void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com=="delete"){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}

Measured memory_bytes: 22072
#include <iostream>
using namespace std;
int main(void){
    int x, y;
    cin >> x >> y;
    int prize[206]={0,300000,200000,100000};
    int sum = 0;
    if(x==1&&y==1) sum += 1000000;
    else sum += prize[x]+prize[y];
    cout << sum << endl;
}


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

int main(){
	long long n,t,a,l = 0;
	cin >> n >> t;
	long long ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a;
		if(a-l < t) ans += a-l;
		else ans += t;
		l = a;
	}
	cout << ans+t << endl;
}


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

int main() {

    int ans = 700;
    string s;
    cin >> s;
    for(int k=0; k<3; k++) {
        ans += (s[k]=='o')*100;
    }
    cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
l = [list(map(int, input().split())) for _ in range(1)][0]
t = sorted(l)
count = 0
for i in range(len(l)):
    if l[i] == t[i]:
        count += 1

if count == N - 2 or count == N:
    print("YES")
else:
    print("NO")

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

int main(void){
    ll n,k;cin >> n >> k;
    ll num[2] = {};
    ll a[n];
    
    rep(i,n){
        cin >> a[i];
        if(a[i] >= 0)num[0]++;
        else num[1]++;
    }
    sort(a,a+n,greater<ll>());
    
    ll sum = 1,mod = 1e9+7,p = 0,q = n-1,ans = 0;
    
    if(num[1] == n){
        if(k % 2 == 1){
            rep(i,k){
                sum *= a[i];
                sum %= mod;
            }
        } else {
            for(int i = 0;i < k;i++){
                sum *= a[n-1-i];
                sum %= mod;
            }
        }
    } else if(n == k){
        sum = 1;
        rep(i,n){
            sum *= a[i];
            sum %= mod;
        }
    } else {
        for(int i = 0;i < n;i++){
            if(ans >= k || (q >= 0 && p >= num[0]))break;
            if(ans == k-1 || a[q]*a[q-1] <= a[p]*a[p+1]){
                sum = sum * a[p] % mod;
                p++;
                ans++;
            } else {
                sum = sum * (a[q]* a[q-1] % mod) % mod;
                q -= 2;
                ans += 2;
            }
        }
    }
    if(sum < 0){
        sum = mod - abs(sum);
    }
    cout << sum % mod << endl;
}

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

int main() {

  long long int m, t, p, r, in_m, in_t, in_p, in_j;

  while( true ) {

    cin >> m >> t >> p >> r;
    if ( m == 0 ) break;

    vector< pair< long long int, pair< long long int, long long int > > > list;
    for ( long long int i = 0; i < t; i++ ) {
      list.push_back( make_pair( 0, make_pair( 0, -(i+1) ) ) );
    }

    long long int pena[51][11] = {0};

    for ( long long int i = 0; i < r; i++ ) {
      cin >> in_m >> in_t >> in_p >> in_j;
      in_t--;
      in_p--;
      if ( in_j == 0 ) {
	list[in_t].first--;
	list[in_t].second.first += in_m + pena[in_t][in_p] * 20;
      }else {
	pena[in_t][in_p]++;
      }
    }

    sort( list.begin(), list.end() );

    for ( long long int i = 0; i < t; i++ ) {
      if ( i > 0 ) {
	if ( list[i].first == list[i-1].first && list[i].second.first == list[i-1].second.first ) {
	  cout << "=";
	}else {
	  cout << ",";
	}
      }
      cout << -list[i].second.second;
    }
    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1200
MOD = 10**9 + 7
n, k = map(int, input().split())
d = [0] + [pow(k // i, n, MOD) for i in range(1, k + 1)]
for i in range(k, 0, -1):
    for j in range(2*i, k + 1, i):
        d[i] -= d[j]
        d[i] %= MOD
print(sum(i * d[i] % MOD for i in range(1, k + 1)) % MOD)

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, y;
    cin >> n >> y;

    int temp = n;
    int val = y;

    int a = 0, b = 0, c = 0;

    while(val >= 10000 && temp)
    {
        val -= 10000;
        --temp;
        ++a;
    }

    while(val >= 5000 && temp)
    {
        val -= 5000;
        --temp;
        ++b;
    }

    while(val >= 1000 && temp)
    {
        val -= 1000;
        --temp;
        ++c;
    }

    if(temp == 0)
    {
        if(val == 0)
            cout << a << ' ' << b << ' ' << c << '\n';
        else
            cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
        exit(0);
    }


    while(temp && (a || b))
    {
        if(temp >= 9 && a)
        {
            --a;
            c += 10;
            temp -= 9;
        }
        else
        {
            if(b && temp >= 4)
            {
                --b;
                c += 5;
                temp -= 4;
            }
            else
            {
                if(a)
                {
                    --a;
                    b += 2;
                    --temp;
                }
                else
                    break;

            }
        }
    }

    if(temp)
        cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
    else
        cout << a << ' ' << b << ' ' << c << '\n';
}



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

int main() {

  string S;
  ll K;

  cin >> S >> K ;

  char ans;

  for(int i=0;;i++){
    if(S[i]=='1'){
      K--;
      if(K<=0){
        ans=S[i];
        break;
      }
    }

    else{
      ans=S[i];
      break;
    }

    
  }

 
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
def solve() : 
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    m = 1<<n
    dp = [[10000 for i in range(n)] for i in range(m)]
    for i in range(n) :
        dp[1<<i][i]=0
    for i in range(m) :
        c = 0
        for j in range(n) :
            if (1<<j)&i != 0 : c += 1
        cnt = c
        for j in range(n) :
            if (1<<j)&i == 0 : continue
            cnt -= 1
            pre = i - (1<<j)
            for k in range(n) :
                if (1<<k) & i == 0 : continue
                cur = (b[k] if (c-k)%2 == 1 else a[k])
                nxt = (a[j] if (c-j)%2 == 1 else b[j])
                if cur <= nxt : dp[i][j]=min(dp[i][j],dp[pre][k]+cnt)
    ans = 10000
    for i in range(n) :
        ans = min(ans,dp[m-1][i])
    print(ans if ans != 10000 else -1)
solve()


Measured memory_bytes: 129120
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		if(b % a == 0) {
			System.out.println(a + b);
		}else {
			System.out.println(b - a);
		}

	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string c;
  cin >> c;
  
  if(c == "a" || c == "e" || c == "i" || c == "o" || c == "u")
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>


using namespace std;



int main(){
    string in_str,out_str;
    
    while(getline(cin,in_str)){
        out_str=in_str;
        int beg=0;
        
        while(1){
            int beg = in_str.find("apple");
            if(beg==-1){
                break;
            }else{
                in_str[beg]='*';
                out_str[beg]='p';
                beg++;
                in_str[beg]='*';
                out_str[beg]='e';
                beg++;
                in_str[beg]='*';
                out_str[beg]='a';
                beg++;
                in_str[beg]='*';
                out_str[beg]='c';
                beg++;
                in_str[beg]='*';
                out_str[beg]='h';
            }
            beg = in_str.find("peach");
            if(beg==-1){
                break;
            }else{
                in_str[beg]='*';
                out_str[beg]='a';
                beg++;
                in_str[beg]='*';
                out_str[beg]='p';
                beg++;
                in_str[beg]='*';
                out_str[beg]='p';
                beg++;
                in_str[beg]='*';
                out_str[beg]='l';
                beg++;
                in_str[beg]='*';
                out_str[beg]='e';
            }
        }
        cout<<out_str<<endl;
    }
    
}

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

typedef long long ll;

const int N = 200005;
int n;
int A[N];
vector<int> edges[N];
vector<int> V;
int res[N];

void dfs(int par, int u) {
    for (auto v : edges[u]) {
        if (v == par) continue;
        auto it = lower_bound(V.begin(), V.end(), A[v]);
        int pos = it - V.begin();

        res[v] = max(res[u], pos + 1);

        if (it == V.end()) {
            V.push_back(A[v]);
            dfs(u, v);
            V.pop_back();
        } else {
            int temp = V[pos];
            V[pos] = A[v];
            dfs(u, v);
            V[pos] = temp;
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    int u, v;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    res[1] = 1;
    V.push_back(A[1]);
    dfs(0, 1);

    for (int i = 1; i <= n; ++i) {
        cout << res[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 33312
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int[]prime;
	static int n;
	public static void main(String[] args) {
		makePrime();
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		return true;
	}
	static void solve(){
		int p = 0, q = 0;
		for(int i = 3; i <= n; i++){
			if(prime[i] == 1 && prime[i - 2] == 1){
				p = Math.max(p, i - 2);
				q = Math.max(q, i);
			}
		}
		System.out.print(p + " " + q);
		System.out.println();
	}
	static void makePrime(){
		prime = new int[10000+1];
		for(int i = 1; i < prime.length; i++)
			prime[i] = 1;
		for(int i = 2; i < prime.length; i++){
			if(prime[ i ] == 1){
				for(int j = i; i*j < prime.length; j++)
				prime[ i*j ] = 0;
			}
		}
	}
}

Measured memory_bytes: 13000
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    elif op=='+':
        print(a+b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)
    elif op=='-':
        print(a-b)




Measured memory_bytes: 5596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc079.contest.atcoder.jp/tasks/arc079_a>
問題文============================================================
 高橋キングダムには、高橋諸島という、N 個の島からなる諸島があります。
 便宜上、これらの島を島 1、島 2、 ...、島 N と呼ぶことにします。
 
 これらの諸島の間では、船の定期便が M 種類運行されています。
 定期便はそれぞれ 2 つの島の間を行き来しており、i 種類目の定期便を使うと、
 島 ai と島 bi の間を行き来する事ができます。
 
 すぬけくんは今島 1 にいて、島 N に行きたいと思っています。
 しかし、島 1 から島 N への定期便は存在しないことがわかりました。
 なので、定期便を 2 つ使うことで、島 N に行けるか調べたいと思っています。
 
 これを代わりに調べてあげてください。

=================================================================

解説=============================================================

================================================================
*/
ll N,M;
vector<vector<ll>> G;

bool f = false;
void dfs(int n,int x){
    if(n == N - 1) f = true;
    if(x == 2) return;
    if(f) return;
    for(auto v: G[n]) dfs(v,x+1);
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    G.resize(N);
    for(int i = 0; i < M;i++){
        ll a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0,0);
    if(f){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
	return 0;
}


Measured memory_bytes: 12776
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int k;
  string s;
  cin >> k >> s;
  for (int i = 0; i < k && i < (int)s.length(); ++i) {
    cout << s[i];
  }
  if ((int)s.length() > k) cout << "...";
  cout << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	if (n == 1) {
		cout << ans << endl;
		return 0;
	}
	ll x = 1, y = 1, z = 1;
	rep (i, n) {
		x *= 10;
		x %= mod;
		y *= 8;
		y %= mod;
		z *= 9;
		z %= mod;
	}
	ans = x - (2 * z);
	ans %= mod;
	ans += y;
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
/*
 * @Author: Kaizyn
 * @Date: 2020-04-04 19:57:03
 * @LastEditTime: 2020-04-04 20:15:53
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 1e6+7;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;

long long n;
map<int, int> res;

inline void solve()
{
    cin >> n;
    if (n == 2) return void(cout << 1 << endl);
    res.clear();
    res[n] = 1;
    res[n-1] = 1;
    for (long long k = 2, x, d; k*k <= n; ++k) {
        if (n%k) continue;
        x = n; d = k;
        while (x%d == 0) x /= d;
        if ((x-1)%d == 0) res[d] = 1;
        if (n/k == k) continue;
        x = n; d = n/k;
        while (x%d == 0) x /= d;
        if ((x-1)%d == 0) res[d] = 1;
    }
    --n;
    for (long long k = 2; k*k <= n; ++k) {
        if (n%k) continue;
        res[k] = 1;
        res[n/k] = 1;
    }
    cout << res.size() << endl;
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int testcase = 1;
    // cin >> testcase;
    for (int i = 1; i <= testcase; ++i) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 998244353;
const int MAXN = 4010, LOG=20;

ll n, m, k, u, v, x, y, t, a, b;
ll C[MAXN][MAXN];

ll get(ll n, ll sum){
	if (n==0) return (sum==0);
	if (sum<0) return 0;
	return C[n+sum-1][n-1];
}

ll solve(int x){
	ll ans=0, t=0;
	for (int i=0; i<=k; i++) t+=(i<=x-i && x-i<=k);
	for (int i=0; i<=t; i++){
		ll tmp=C[t][i]*get(k+1, n-2*i)%mod;
		if (i&1) tmp=mod-tmp;
		ans+=tmp;
	}
	return ans%mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	for (int i=0; i<MAXN; i++){
		C[i][0]=C[i][i]=1;
		for (int j=1; j<i; j++) C[i][j]=(C[i-1][j-1] + C[i-1][j])%mod;
	}
	cin>>k>>n;
	k--;
	for (int i=0; i<=2*k; i++) cout<<solve(i)<<'\n';
	
	return 0;
}


Measured memory_bytes: 124160
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

ll lcm ( ll x, ll y )
{
	ll gcd = __gcd(x, y);

	if( x % gcd == 0 ) x /= gcd;
	else if ( y % gcd == 0 ) y /= gcd;
	else return x*y / gcd;

	return x*y;
}

int main()
{
	int N;
	ll T[100];

	cin >> N;
	rep(i, N) cin >> T[i];

	ll x = T[0];
	reep(i, 1, N){
		x = lcm(x, T[i]);
	}
	cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if(rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry;  // xとyの根が同じでない時：xの根rxをyの根ryにつける
  }
  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

vi ans;
vector<set<int>> fr, bl;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  fr = vector<set<int>>(n);
  bl = vector<set<int>>(n);
  UnionFind tree(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    fr[a - 1].insert(b - 1);
    fr[b - 1].insert(a - 1);
    tree.unite(a - 1, b - 1);
  }
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    bl[c - 1].insert(d - 1);
    bl[d - 1].insert(c - 1);
  }
  map<int, int> cnt;
  rep(i, n) {
    int r = tree.root(i);
    cnt[r]++;
  }
  ans = vi(n, -1);
  rep(i, n) {
    int r = tree.root(i);
    ans[i] += cnt[r];
    ans[i] -= fr[i].size();
    for(auto v : bl[i])
      if(tree.same(i, v)) ans[i]--;
  }
  rep(i, n) cout << ans[i] << ' ';
  cout << endl;
}

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

int main(int argc, const char * argv[]) {
    int A, B, K;
    
    cin >> A >> B >> K;
    for (int i = 0; i < K; i++) {
        if (i % 2 == 0) {
            if (A % 2 == 1) {
                A -= 1;
            }
            B += (A / 2);
            A /= 2;
        } else {
            if (B % 2 == 1) {
                B -= 1;
            }
            A += (B / 2);
            B /= 2;
        }
    }
    
    cout << A << " " << B << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	string s;
	int a, b;
	a = b = 0;
	cin >> s;

	for (int i = 0;i < s.length();i++)
	{
		if (a == 0 && s[i] == 'A')
		{
			a = i;
			break;
		}
	}
	for (int i = s.length()-1;i >=0;i--)
	{
		if (b == 0 && s[i] == 'Z')
		{
			b = i;
			break;
		}
	}
	cout << b - a+1;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
A, B, C = map(int, readline().split())
N = int(readline())
cnt = 0
while B <= A:
    B*=2
    cnt += 1
while C <= B:
    C*=2
    cnt +=1
if cnt <= N:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int A,B,C; cin >> A >> B >> C;
    C -= (A-B);
    cout << max(C,0) << endl;


    return 0;
}


Measured memory_bytes: 892
# -*- coding: utf-8 -*-

S = input()
T = input()

# 1対1の変換表(dict)
start = {}
goal = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    # 変換表の該当箇所がまだ空いてるかどうか
    if s in start or t in goal:
        # 埋まっている場合、今回の組み合わせと一致しているかどうか
        if start.get(s) != t or goal.get(t) != s:
            print('No')
            exit()
    # 空いていれば変換表を埋める
    else:
        start[s] = t
        goal[t] = s

print('Yes')

Measured memory_bytes: 3632
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 1; i <= n; i++)

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) cout << k << endl;
	else if(a + b >= k) cout << a << endl;
	else cout << a - (k - (a + b)) << endl;
	return 0;
}

Measured memory_bytes: 3620
# AtCoder
N = int(input())
S = input()
count = 0
r = g = b = 0
for s in S:
    if s == 'R':
        r += 1
    elif s == 'G':
        g += 1
    else:
        b += 1

_all = r*g*b
sub = 0

for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            continue
        k = 2*j-i
        if k >= N or S[k] == S[i] or S[k] == S[j]:
            continue
        sub += 1
print(_all-sub)


Measured memory_bytes: 9204
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int A = sc.nextInt();
  int B = sc.nextInt();
  int C = sc.nextInt();
  int D = sc.nextInt();
  if(A*B >= C*D)System.out.println(A*B);
  else System.out.println(C*D);
}
}

Measured memory_bytes: 21972
// ConsoleApplication1.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12


struct ten_t {
	int x;
	int y;
};

int compare_ten(const void *a, const void *b) {
	struct ten_t *A = (struct ten_t *)a;
	struct ten_t *B = (struct ten_t *)b;
	return A->x - B->x;
}

int main(void)
{
	//変数の宣言
	int h, w, n;
	static struct ten_t ten[200010];

	//よく使う変数
	int i, j, k, l;
	int flag = 0;
	int ans = 0;
	int count = 0;
	int temp, temp1, temp2;
	int max, min;
	int len;
	int sum = 0;

	//データの読み込み
	scanf("%d %d %d",&h,&w,&n);
	//scanf_s("%d %d %d", &h, &w, &n);

	for(i=0;i<n;i++){
		scanf("%d %d", &ten[i].x, &ten[i].y);
	//	scanf_s("%d %d", &ten[i].x, &ten[i].y);
	}
	


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
		//実際の処理
	qsort(ten, n, sizeof(struct ten_t), compare_ten);


	j = 0;
	temp = 1;
	for (i = 1;i <= h;i++) {
		while (ten[j].x == i) {
			if (ten[j].y < temp) {
				printf("%d", i - 1);
				return 0;
			}
			else if (ten[j].y == temp) {
				flag = 1;
			}
			j++;
		}
		if (flag == 1) {
			flag = 0;
		}
		else {
			temp++;
		}
	}

	//	printf("計算部分終了\n");
		//出力
	printf("%d", h);


	//	printf("結果の出力終了\n");

	return 0;

}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

void fnInput(int& rnSpcNum, int& rnMinSum, int& rnMaxSum)
{
  cin >> rnSpcNum >> rnMinSum >> rnMaxSum;
}

int fnDigitsSum(int nNum)
{
  int nDigitsSum = 0;
  while ( nNum )
  {
    nDigitsSum += nNum % 10;
    nNum /= 10;
  }
  return nDigitsSum;
}

int fnSomeSums(int nSpcNum, int nMinSum, int nMaxSum)
{
  int nTotal = 0;
  for (int n = 1; n <= nSpcNum; n++)
  {  
    int nDigitsSum = 0;
    nDigitsSum += fnDigitsSum(n);
    if (nMinSum <= nDigitsSum && nDigitsSum <= nMaxSum)
      nTotal += n;
  }
  return nTotal;
}

int main()
{
  int nSpcNum, nMinSum, nMaxSum;
  fnInput(nSpcNum, nMinSum, nMaxSum);

  cout << fnSomeSums(nSpcNum, nMinSum, nMaxSum) << endl;
  return 0;
}
 

Measured memory_bytes: 256
N = int(input())
AList = [int(input()) for i in range(N)]
max_AList = max(AList)
max2nd_AList = sorted(AList, reverse = True)[1]

for i in range(N) :
    if AList[i] == max_AList :
        print(max2nd_AList)
    else :
        print(max_AList)

Measured memory_bytes: 13340
package main

import (
   "fmt"
)

func solution(n int) int {
   s := 0
   for s < n {
        s += 1000
        if s == n {
                break
        }
   }
   return s - n
}

func main() {
   var n int
   fmt.Scan(&n)
   fmt.Println(solution(n))
}

Measured memory_bytes: 1768
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main(){
	string s;
	cin >> s;
	if(s == "ABC")
		cout << "ARC" << endl;
	else
		cout << "ABC" << endl;

	return 0;
}

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

int main(){
    int n;
    int p[15]={};
    int ans = 0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>p[i];
    }
    sort(p,p+n);
    for(int i=0; i<n-1; i++){
        ans += p[i];
    }
    ans += p[n-1]/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	string c=a+b;
	int s=atoi(c.c_str()); 
	for(int i=1;i<=s/2+1;i++){
		if(i*i==s) {
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int count = 0;
    for(int i = 1; i < n; i++){
        if(s[i - 1] == s[i]) {
            while (i < n && s[i - 1] == s[i]) {
                i++;
                count++;
            }
        }
        //cout << i << " " << count << endl;
    }
    cout << n - count << endl;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

void YNout(bool check){
	if(check)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return;
}

void Yayout(bool check){
	if(check) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	
	return;
}

/*
template <typename T>
void vecout(vector<T>& vecout_vec){
	
	rep(i,0,vecout_vec.size()){
		cout << vecout_vec.at(i) << endl;
	}
	
	return ;
}

template <typename T>
void vecin(vector<T>& vecin_vec, ll n){
	
	ll temp ;
	
	rep(i,0,n){
		cin >> temp;
		vecin_vec.push_back(temp);
		
	}
}

template <typename T>
void in(T& literal_in, T& literal_in2, ...){
	cin >> literal_in;
	in(literal_in2, ...);
	
	return;
}

template <typename T>
void in(T& literal_in){
	
	cin >> literal_in;
	
	return;
}

template <typename T>
void out(T& literal_out, T& literal_out2, ...){
	cout << literal_out << endl;
	out(literal_out2, ...);
	
	return;
}

template <typename T>
void out(T& literal_out){
	
	cout << literal_out << endl;
	
	return;
}
*/


signed main(){
	ll n;
	cin >> n;
	ll h[n] = {};
	
	rep(i,0,n) cin >> h[i];
	
	ll dp[n] = {};
	
	rep(i,1,n) dp[i] = INF;
	
	
	rep(i,0,n-1){
		dp[i+1] = min(dp[i] + abs(h[i] - h[i+1]),dp[i+1]);
		if(i < n-1) dp[i+2] = min(dp[i] + abs(h[i] - h[i+2]),dp[i+2]);
	}
	
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;


void solve(){
    int n, ans = LLONG_MAX, mn = 0;
    cin>>n;
    vl v;
    f(i,n){
        int k;
        cin>>k;
        v.pb(k);
        mn = max(mn,k);
    }
    f(i,mn+1){
        int p = i, cnt = 0;
        f(j,v.size())cnt += (abs(p-v[j]) * abs(v[j] - p));
        ans = min(ans,cnt);
    }
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int k,n; cin >> k >> n;
  vector<int> v(n); cin >> v;
  ll sum = 0;
  for(auto e:v)sum += e;
  int maxd = 0;
  for(int i = 1; i < n; ++i){
    maxd = max(maxd, v[i] - v[i-1]);
  }  
  maxd = max(maxd, k - (v[n-1] - v[0]));
  cout << k - maxd << endl;
  return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        # 0-indexed
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        """ [0, i]を合計する """
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        """ 値の追加：添字i, 値x """
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        """ 区間和の取得 [l, r) """
        # 引数が1つなら一点の値を取得
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

def compress(A):
    """ 座標圧縮 """

    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(set(A))):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

N, K = MAP()
# 予め-Kした状態で用意しておく
A = [a-K for a in LIST(N)]

# 累積和
acc = [0] + list(accumulate(A))
# 座標圧縮
zipped, _ = compress(acc)

bit = BIT(len(zipped))
cnt = 0
for a in acc:
    # 自分より左にある、自分の値以下の数(転倒数の数え上げ)
    cnt += bit.sum(zipped[a])
    bit.add(zipped[a], 1)
print(cnt)


Measured memory_bytes: 111616
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
		int a = 10 * input[1] + input[2];
		Console.WriteLine(a % 4 == 0 ? "YES" : "NO");
	}
}

Measured memory_bytes: 13268