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

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

  vector<int> num(N);

  for (int i=0; i<M; i++) {
    int a,b;
    cin >> a >> b;
    
    num[a-1] += 1;
    num[b-1] += 1;

  }

  for (int i=0; i<N; i++) {
    cout << num[i] << endl;
  }
  
}

Measured memory_bytes: 256
n, m, k = map(int,input().split())
mod = 10**9 + 7
l = 3*10**5 + 3

M = [1]  # i!のmod
mul = 1
for i in range(1, l):
    mul = (mul * i) % mod
    M.append(mul)

def pow(x, y, mod):  # x**y の mod を返す関数
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  # x の mod での逆元を返す関数
    return pow(x, mod-2, mod)

# print(inv(8,13))

MI = [0] * (l-1) +[inv(M[l-1], mod)]  # i!の逆元
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  # コンビネーション（組合せ）
    if y < 0 or y > x:
        return 0
    elif x > l:  # O(min(y, x-y))
        y = min(y, x-y)
        ans = 1
        for i in range(x, x-y, -1):
            ans = (ans * i) % mod
        return (ans * MI[y]) % mod
    else:  # O(1)
        ans = M[x]
        ans = (ans * MI[y]) % mod
        return (ans * MI[x-y]) % mod

def P(x, y):  # パーミュテーション（順列）
    if y < 0 or y > x:
        return 0
    elif x > l:  # O(min(y, x-y))
        y = min(y, x-y)
        ans = 1
        for i in range(x, x-y, -1):
            ans = (ans * i) % mod
        return ans % mod
    else:  # O(1)
        ans = M[x]
        return (ans * MI[x-y]) % mod

a = 0
for i in range(1, m):
    a = (a + n*n*(m-i)*i) % mod
for i in range(1, n):
    a = (a + m*m*(n-i)*i) % mod

print((a * C(n*m-2, k-2)) % mod)

Measured memory_bytes: 94016
sx, sy, tx, ty = map(int, input().split())

ans = ""
sa_x = tx-sx
sa_y = ty-sy

for i in range(sa_x):
    ans += "R"
for i in range(sa_y):
    ans += "U"
for i in range(sa_x):
    ans += "L"
for i in range(sa_y):
    ans += "D"
ans += "D"
for i in range(sa_x+1):
    ans += "R"
for i in range(sa_y+1):
    ans += "U"
ans += "LU"
for i in range(sa_x+1):
    ans += "L"
for i in range(sa_y+1):
    ans += "D"
ans +="R"

print(ans)
    

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


using namespace std;
int main(){
	int N;
	cin>>N;
	for(int II=0;II<N;II++){
	long long int AA;
	cin>>AA;
	int YY;
	cin>>YY;

	int N2;
	cin>>N2;
	long long int max=0;
	for(int I=0;I<N2;I++)
	{
		long long int A,B=0;
		A=AA;
		int s;
		int K;
		double R;
		
		cin>>s>>R>>K;
		if(s==0){
			for(int i=0;i<YY;i++)
			{B+=A*R;A-=K;}
			if(max<A+B)max=A+B;
		}
		else{
			for(int i=0;i<YY;i++)
			{A+=A*R;A-=K;}//cout<<A<<endl;}
			if(max<A)max=A;
		}
	}
		cout<<max<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
from collections import defaultdict
def main():
    H,W = map(int,input().split())
    ls = [[str(x) for x in input().split()] for _ in range(H)]
    dic = defaultdict(str)
    for i,now in enumerate([chr(i) for i in range(65, 65+26)]):
        dic[i] = now

    for i in range(H):
        for j in range(W):
            if ls[i][j]=="snuke":
                ans = dic[j]+str(i+1)
                print(ans)
                exit()
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define INF int(1e-6)
#define MAX int(1e9)
typedef long long ll;
typedef long l;




int main (){
	int n,x;
	bool flag = true;
	cin >> n;
	for(int i = 0; i<n; i++){
		cin >> x;
		if(x%2 == 0){
			if(x%3 == 0 or x%5 == 0){
				flag = true;
			}else{
				flag = false;
			}
		}
		if(!flag){
			break;
		}
	}
	if(flag){
		cout << "APPROVED\n";
	}else{
		cout << "DENIED\n";
	}
	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;
 


int main()
{
   
  
    vector<vector<int>>t(3, vector<int>(3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> t[i][j];
        }
    }
    bool f[500] = {};
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        f[a]=1;
    }
    
    for (int i = 0; i < 3; i++) {
        
        if (f[t[0][i]]&& f[t[1][i]]&& f[t[2][i]]) {
            cout << "Yes" << endl;  
            return 0;
        }
    }

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

        if (f[t[i][0]] && f[t[i][1]] && f[t[i][2]]) {
            cout << "Yes" << endl;
            return 0;
        }
    }int x = 0;
    for (int i = 0; i < 3; i++) {
        
       
           if(!f[t[i][i]]) x += t[i][i];
           
      
       
    }  if (!x) {
            cout << "Yes" << endl;
            return 0;
        }
    x = 0;
    for (int i = 0; i < 3; i++) {
       
        if(!f[t[2-i][i]])x += t[2-i][i];

        
    }if (!x) {
            cout << "Yes" << endl;
            return 0;
        }
    cout << "No" << endl;


    return 0;

}

Measured memory_bytes: 3640
import sys 
from collections import Counter
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
mod = 2019
S = readline().decode().rstrip()
N = len(S)
S = S[::-1]
mod_list = [0]*N
mod_list[0] = int(S[0])
power = 1
for i in range(1,N):
    power *=10
    power %= mod
    mod_list[i] = power * int(S[i]) + mod_list[i-1]
    mod_list[i] %= mod
    
mod_cnt = Counter(mod_list)
ans = sum(n*(n-1)//2 for n in mod_cnt.values()) +mod_cnt[0]
print(ans)

Measured memory_bytes: 16612
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
string print(string, int, int);
string reverse(string, int, int);
string replace(string, int, int, string);

string print(string str, int a,int b) {
  string ans="";
  for(int i = a; i < b+1; i++) {
    ans += str[i];
  }
  return ans ;
}
string reverse(string str, int a, int b) {
  string ans="";
  REP(i,a) {
    ans+=str[i];
  }
  for(int i=b;i>=a;i--) {
    ans+=str[i];
  }
  for(int i=b+1;i < str.length();i++) {
    ans+=str[i];
  }
  return ans;
}
string replace(string str, int a, int b, string p) {
  string ans="";
  REP(i,str.length()) {
    if(a<=i&&i<=b) {
      ans+=p[i-a];
    } else {
      ans+=str[i];
    }
  }
  return ans;
}

int main() {
  double x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  double distance = 0.0;
  distance += pow((x1-x2),2.0);
  distance += pow((y1-y2),2.0);
  distance = sqrt(distance);
  cout << setprecision(12) << distance << endl;
  
  return 0;
}



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

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    if (a % 2 == 0) {
      if (a % 3 && a % 5) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;

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

	string S;
	cin >> S;

	cout << S[0] << S[1] << S[2] << endl;
	return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define MP make_pair
#define Mod 998244353
using namespace std;
using lint = long long;
using vi = vector<lint>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

// cout << fixed << setprecision(12)

int main(){
  lint N,M,K;
  cin >> N >> M >> K;
  vi SA(N+1), SB(M+1);
  for(lint i=0; i<N; i++){
    lint a;
    cin >> a;
    SA[i+1] = SA[i] + a;
  }
  for(lint i=0; i<M; i++){
    lint b;
    cin >> b;
    SB[i+1] = SB[i] + b;
  }
  
  lint Amax = 0;
  
  for(lint i=0; i<N+1; i++){
    if(SA[i] > K){
      Amax = i-1;
      break;
    }
  }
  if(SA[N] <= K) Amax = N;
  
  lint maxi = Amax;
  
  
  for(lint i=0; i<=Amax; i++){
    lint nokori = K - SA[i];
    
    lint jj;
    
    if(nokori >= SB[M]) jj = M;
    else{
    auto j = upper_bound(ALL(SB), nokori);
    jj = distance(SB.begin(), j);
    jj--;
    }
    
    
    maxi = max(maxi, i + jj);
  }
  
  cout << maxi << endl;
}
      
    
    
  
  
  
    

Measured memory_bytes: 6332
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    print('YES' if int(input()) in [3, 5, 7] else 'NO')

main()


Measured memory_bytes: 63980
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b,a[li],k,flag,x,dp[li];
lo cev;
string s;
vector<lo> v;

void YES(int xxxxxxx){
	if(xxxxxxx==1){cout<<"YES\n";exit(0);}
	printf("YES\n");
	exit(0);
}

void NO(int xxxxxxx){
	if(xxxxxxx==1){cout<<"NO\n";exit(0);}
	printf("NO\n");
	exit(0);
}

inline lo add(lo x,lo y){
	if(x+y>=mod) return x+y-mod;
	return x+y;
}

inline lo f(lo sira){
	lo cevv=0;
	if(a[sira]==1) return 0;
	if(sira==n) return 1;
	if(sira>n) return 0;
	if(~dp[sira]) return dp[sira];
	cevv=add(cevv,f(sira+1));
	cevv=add(cevv,f(sira+2));
	return dp[sira]=cevv;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%lld",&x);
		a[x]=1;
	}
	printf("%lld\n",f(0));
	return 0;
}


Measured memory_bytes: 9472
#include<stdio.h>
 
int main(void)
{
	int c;
    scanf("%d",&c);
	char a[110];
    char b[110];
    
    scanf("%s%s",a,b);
    
    for( int i=0 ; i < c; i++)
    {
    	printf("%c%c",a[i],b[i]);
  	}
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
  fastio;
  int n, k, q;
  cin >> n >> k >> q;
  int aux = q;
  vector<int> pref(n+1, k);
  while(q--){
    int i;
    cin >> i;
    pref[i]++;
  }
  for(int i = 1; i <= n; i++){
    pref[i] -= aux;
    if(pref[i] > 0) cout << "Yes\n";
    else cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, mm, kk, aa, bb, tmp;
	cin >> nn >> mm >> kk;
	vector<int64> ff[nn], ww[nn], tt(nn, -1);
	for(int64 ii = 0;ii < mm;ii++)
	{
		cin >> aa >> bb;
		aa--;
		bb--;
		ff[aa].push_back(bb);
		ff[bb].push_back(aa);
	}
	for(int64 ii = 0;ii < kk;ii++)
	{
		cin >> aa >> bb;
		aa--;
		bb--;
		ww[aa].push_back(bb);
		ww[bb].push_back(aa);
	}
	int64 cnt = 0;
	queue<int64> qq;
	vector<int64>::iterator ite;
	for(int64 ii = 0;ii < nn;ii++)
	{
		if(tt[ii] != -1)
		{
			continue;
		}
		qq.push(ii);
		while(!qq.empty())
		{
			tmp = qq.front();
			qq.pop();
			tt[tmp] = cnt;
			for(ite = ff[tmp].begin();ite != ff[tmp].end();ite++)
			{
				if(tt[*ite] == -1)
				{
					qq.push(*ite);
				}
			}
		}
		cnt++;
	}
	vector<int64> ee(cnt, 0);
	for(int64 ii = 0;ii < nn;ii++)
	{
		ee[tt[ii]]++;
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		cnt = ee[tt[ii]] - ff[ii].size() - 1;
		for(ite = ww[ii].begin();ite != ww[ii].end();ite++)
		{
			if(tt[ii] == tt[*ite])
			{
				cnt--;
			}
		}
		cout << cnt << ' ';
	}
	cout << endl;
	return 0;
}


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

typedef complex<double> P;
typedef pair<P,P> L;

const double INF = 1e+12;
const double EPS = 1e-8;
const int N = 1000;

struct state{
  int n;
  double c;
  state(int n=0, double c=0):n(n),c(c){}
  bool operator < (const state &s) const {
    return c > s.c;
  }
};

double dot(P a, P b){ return real(conj(a)*b); }

double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  
  if(max(real(s1.first), real(s1.second)) + EPS < min(real(s2.first), real(s2.second)) ||
     max(imag(s1.first), imag(s1.second)) + EPS < min(imag(s2.first), imag(s2.second)) ||
     max(real(s2.first), real(s2.second)) + EPS < min(real(s1.first), real(s1.second)) ||
     max(imag(s2.first), imag(s2.second)) + EPS < min(imag(s1.first), imag(s1.second))) return false;

  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}


int n[2];
double G[2][N][N];
vector<P> v[2];

double dijk(int pos){
  priority_queue<state> pq;
  state u, u2;
  double d[N];

  fill(d, d+N, INF);
  d[0] = 0;

  for(pq.push(state(0, 0)); !pq.empty();){
    u = pq.top();
    pq.pop();

    if(u.n == 1) return u.c;

    for(int i=0;i<n[pos];i++){
      u2 = state(i, u.c + G[pos][u.n][i]);
      if(isIntersect(L(v[pos][u.n], v[pos][i]), L(v[!pos][0], v[!pos][1])) || d[i] <= u2.c + EPS) continue;
      d[i] = u2.c;
      pq.push(u2);
    }
  }

  return INF;
}

double solve(){
  double res = INF;
  double res_dijk[2];

  for(int i=0;i<2;i++){
    for(int j=0;j<n[i];j++){
      for(int k=j+1;k<n[i];k++){
        G[i][j][k] = G[i][k][j] = abs(v[i][j] - v[i][k]);
      }
    }
    res_dijk[i] = dijk(i);
  }

  for(int i=0;i<2;i++){
    res = min(res, res_dijk[i] + abs(v[!i][0] - v[!i][1]));
  }

  return res;
}

int main(){
  while(cin >> n[0] >> n[1]){
    for(int i=0;i<2;i++){
      v[i].clear();
      for(int j=0;j<n[i];j++){
        int x,y;
        cin >> x >> y;
        v[i].push_back(P(x,y));
      }
    }
    double res = solve();
    if(res >= INF - EPS) cout << -1 << endl;
    else printf("%.12f\n", res);
  }
}

Measured memory_bytes: 17020
#include<iostream>
using namespace std;
int main(){
  long long int a, b;
  cin >> a >> b;
  if(a == 1){
    cout << "1\n";
  }
  else if(b == 1){
    cout << "1\n";
  }
  else if(a * b % 2 == 0){
    cout << a * b / 2 << "\n";
  }
  else{
    cout << (a * b + 1) / 2 << "\n";
  }
}

Measured memory_bytes: 3604
import math
A,B,H,M =  list(map(int, input().split()))
time = 60*H+M
long_d = 0.5*time
short_d = 6*time%360
d = abs(long_d - short_d)
Cos = math.cos(math.radians(d))
ans = A*A + B*B - 2*A*B*Cos
ans = math.sqrt(ans)
print(ans)

Measured memory_bytes: 9504
#include <stdio.h>
#include <string.h>
int main(){
	char s[400],t[400];
	scanf("%s",s);
	getchar();
	scanf("%s",t);
	getchar();
	int len = strlen(s);
	t[len] = '\0';
	if (strcmp (s,t) == 0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1660
// abc126_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int M, K;
    cin >> M >> K;
    int N = 1 << M;

    if (K == 0){
        REP(i, N-1) cout << i << " " << i << " ";
        cout << N-1 << " " << N-1 << endl;
        return 0;
    }

    if (N-1 < K){
        print(-1);
        return 0;
    }

    int sm = 0;
    REP(i, N){
        if (i == K) continue;
        sm ^= i;
    }

    if (sm != K) {
        print(-1);
        return 0;
    }

    cout << K << " ";
    REP(i, N) {
        if (i != K) cout << i << " ";
    }
    cout << K << " ";
    REPN_REV(i, 1, N) {
        if (i != K) cout << i << " ";
    }
    cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


map<int, int> cc[100000];
set<int> s[100000];

int n, m;
vector<pair<int, int>> edge[100000];
map<int, int> dp[100000];
int mind[100000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	scanf("%d%d", &n, &m);
	rep(i, m) {
		int p, q, c;
		scanf("%d%d%d", &p, &q, &c);
		p--; q--;
		++cc[p][c];
		++cc[q][c];
		edge[p].emplace_back(q, c);
		edge[q].emplace_back(p, c);
	}
	rep(i, n) {
		for (auto pa : cc[i]) {
			if (pa.second > 1) {
				s[i].insert(pa.first);
			}
		}
		cc[i].clear();
	}

	deque<tuple<int, int,int>> dq;
	set<pair<int, int>> visited;
	dq.emplace_back(0, 0, -1);
	dp[0][0] = 0;
	fill_n(mind, n, INF);
	mind[0] = 0;
	int ans = -1;
	while (!dq.empty()) {
		auto t = dq.front();
		auto pa = make_pair(get<0>(t), get<1>(t));
		dq.pop_front();
		if (visited.count(pa))continue;
		visited.insert(pa);
		int d = dp[pa.first][pa.second];
		if (mind[pa.first] < d)continue;
		if (pa.first == n - 1) {
			ans = d;
			break;
		}
		for (auto e : edge[pa.first]) {
			if (get<2>(t) == e.first)continue;
			int nd = d + (pa.second != e.second);
			int co = s[e.first].find(e.second) == s[e.first].end() ? 0 : e.second;
			auto it = dp[e.first].find(co);
			if (it == dp[e.first].end() || nd < it->second) {		
				if (it == dp[e.first].end())dp[e.first][co] = nd;
				else it->second = nd;
				mind[e.first] = min(mind[e.first], nd);

				if (d == nd)dq.emplace_front(e.first, co, pa.first);
				else dq.emplace_back(e.first, co, pa.first);
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}

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

int main(){
    int n; cin>>n;
    bool flag = 1;
    for(int i=0; i<n && flag==1; i++){
        int a; cin>>a;
        if(a%2==0&&(a%3!=0 && a%5!=0)) flag =0;
    }
    cout << (flag?"APPROVED":"DENIED") << endl;
}

Measured memory_bytes: 256
N = int(input())
L = sorted(list(map(int, input().split())))

ans = 0

for i in range(N):
    for j in range(i):
        for k in range(j):
            if L[i] != L[j] and L[j] != L[k]:
                if L[j] + L[k] > L[i]:
                    ans += 1

print(ans)

Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	deque<int>a(n),b;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i%2==0&&n%2==0){
			b.push_back(a[i]);
		}
		else if(i%2==1&&n%2==0){
			b.push_front(a[i]);	
		}
		else if(i%2==0&&n%2==1){
			b.push_front(a[i]);	
		}
		else if(i%2==1&&n%2==1){
			b.push_back(a[i]);	
		}
	}
	for(int i=0;i<n;i++) cout<<b[i]<<" ";
	return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
    int n; cin >> n;
    int a[n], b[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    int r = 0;
    for(int i = 0; i < n; i++) r += max(0, a[i] - b[i]);
    cout << r << endl;
    
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int x = 0; x <= K; ++x) {
        for (int y = 0; y <= K; ++y) {
            int z = S - x - y;
            if (0 <= z && z <= K)
                ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  string s,t;
  cin >> s >> t;
  int ans=0;
  rep(i,sz(s)){
    if(s[i]==t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  LL N; cin >> N;
  map<LL, LL> m;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    m[a]++;
  }

  vector<LL> keys;
  for (auto [k, v] : m) {
    keys.push_back(k);
  }
  sort(keys.begin(), keys.end());

  if (keys.size() == 1 && keys[0] == 0) {
    cout << "Yes" << endl;
  } else if (N % 3 != 0) {
    cout << "No" << endl;
  } else if (keys.size() == 2) {
    if (keys[0] == 0 && m[keys[0]] == N / 3 && m[keys[1]] == 2*N/3) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else if (keys.size() == 3) {
    LL v = keys[0] ^ keys[1] ^ keys[2];
    if (m[keys[0]] == N / 3 && m[keys[1]] == N/3 && m[keys[2]] == N/3
        && (v == 0)) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 9028
N = int(input())
c = input()
r,w,cnt = 0,0,0
s = 0
flag = False
for i in range(N):
    if c[i] is 'W':
        w += 1
    elif c[i] is 'R':
        r += 1
for i in range(r):
    if c[i] is 'R':
        cnt += 1
print(min(min(r,w),r-cnt))

Measured memory_bytes: 9388
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_3_C-in10.txt"));
		// while (scan.hasNext()) {

		int n = scan.nextInt();
		int k = scan.nextInt();
		int tot = 0, max = 0;
		Tr tr = new Tr(n);
		for (int i = 0; i < n; i++) {
			int w = scan.nextInt();
			tot += w;
			if (w > max)
				max = w;
			tr.add(i, w);
		}
		System.out.println(tr.sesult(k, tot, max));
		scan.close();
		System.exit(0);
	}
}

class Tr {
	int[] w;

	public Tr(int n) {
		w = new int[n];
	}

	public int sesult(int k, int tot, int max) {
		int cp = tot / k;
		if (cp < max)
			cp = max;
		while (true) {
			if (isPossible(cp, (cp * k) - tot))
				return cp;
			else
				cp++;
		}
	}

	private boolean isPossible(int cp, int rm) {
		for (int i = 0, e = cp; i < w.length; i++)
			if (e >= w[i])
				e -= w[i];
			else {
				if (rm >= e)
					rm -= e;
				else
					return false;
				e = cp - w[i];
			}

		return true;
	}

	public void add(int i, int _w) {
		w[i] = _w;
	}

}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  int N; cin >> N;
  int upper[100000];
  int lower[100000];
  REP(i,100000) {
    upper[i] = 0;
    lower[i] = 0;
  }
  REP(i,N) {
    int v;cin >> v;
    if (i%2==0) upper[v-1]++;
    else lower[v-1]++;
  }
  int upper_max=0, upper_second=0, lower_max=0, lower_second=0;
  int upper_max_cnt=0, upper_second_cnt=0, lower_max_cnt=0, lower_second_cnt=0;
  REP(i,100000) {
    if (upper[i] > upper_max_cnt) {
      if (upper_max_cnt > upper_second_cnt) {
        upper_second_cnt = upper_max_cnt;
        upper_second = upper_max;
      }
      upper_max_cnt = upper[i];
      upper_max = i;
    } else if (upper[i] > upper_second_cnt) {
      upper_second_cnt = upper[i];
      upper_second = i;
    }
    if (lower[i] > lower_max_cnt) {
      if (lower_max_cnt > lower_second_cnt) {
        lower_second_cnt = lower_max_cnt;
        lower_second = lower_max;
      }
      lower_max_cnt = lower[i];
      lower_max = i;
    } else if (lower[i] > lower_second_cnt) {
      lower_second_cnt = lower[i];
      lower_second = i;
    }
  }

  if (upper_max != lower_max) {
    cout << N-upper_max_cnt-lower_max_cnt;
  } else {
    cout << N-max(upper_max_cnt+lower_second_cnt,upper_second_cnt+lower_max_cnt);
  }

  return 0;
}

Measured memory_bytes: 1024
n=int(input())

def go(s):
   global n
   if len(s)==n:
       print(s)
       return
   l=max(s)
   for i in range(ord('a'),ord(l)+1):
       go(s+chr(i))
   if l < 'z':
       go(s + chr(ord(l) + 1))

go("a")

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

int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 
    
ll n; 

cin>>n;
ll ans; 
vector<ll> a(n);
for(ll i=0;i<n;i++) cin>>a[i]; 
ll k=1,u=0;
for(ll i=0;i<n;i++) 
  if(k==a[i])
  {
    k++; 
    u++;
  } 
if(u==0) 
{
ans=-1;
}
else 
ans=n-u;
cout<<ans<<"\n";
 return 0;

}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct UnionFind {
    static const int MAX = 1000000;
    int par[MAX];
    void init(int N) {
        for (int i=0; i<N; ++i) {
            par[i] = -1;
        }
    }
    void init() {
        for (int i=0; i<MAX; ++i) {
            par[i] = -1;
        }
    }
    int find(int x) {
        if (par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (par[x] > par[y]) {
            int tmp = x;
            x = y;
            y = tmp;
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    // そのグループの木の大きさを返す
    int size(int x) {
        return -par[find(x)];
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    rep(i, N) {
        cin >> a[i]; a[i]--;
    }
    vector<int> pos(N);
    rep(i, N) pos[a[i]] = i;
    UnionFind uf;
    uf.init(N);
    rep(i, M) {
        int x, y; cin >> x >> y;
        x--; y--;
        uf.unite(x, y);
    }
    int ans = 0;
    rep(i, N) {
        if (uf.same(i, pos[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>

#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, ans = LLONG_MAX;
    cin >> n;

    for (int i = 1; i <= sqrt(n); i++)
        if (n % i == 0)
            ans = min(ans, i + (n / i) - 2);

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();

		double ah = 360D / 12D * ((double)h + (double)m / 60D);
		double am = 360D / 60D * (double)m;


		double vecHX = Math.sin(Math.toRadians(ah)) * (double)a;
		double vecHY = Math.cos(Math.toRadians(ah)) * (double)a;
		double vecMX = Math.sin(Math.toRadians(am)) * (double)b;
		double vecMY = Math.cos(Math.toRadians(am)) * (double)b;

		double d = Math.hypot(Math.abs(vecHX - vecMX), Math.abs(vecHY - vecMY));;

		System.out.println(d);

	}
}



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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int ans=0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        ans+=min(x,abs(k-x));
    }
    cout << ans*2;
    return 0;
}


Measured memory_bytes: 256
class BIT:
    def __init__(self, n):
        self.bit = [0]*(n+1)
    
    def sumB(self, i):
        s = 0
        while(i>0):
            s+=self.bit[i]
            i -= i & -i
        return s
    
    def addB(self, i, x):
        while(i < len(self.bit)):
            self.bit[i] += x
            i += i & -i
            
n = int(input())
A = [(i+1,int(j)) for i,j in enumerate(input().split())]
A = sorted(A, key=lambda x: x[1])
b = BIT(n)
for i in range(n):b.addB(i+1,1)
ans=0
for i,j in A:
    ans+=b.sumB(i-1)
    b.addB(i,-1)
print(ans)


Measured memory_bytes: 47804
#include <bits//stdc++.h>
using namespace std;
#define int long long
#define rep(i,n,k) for(int i=n;i<k;i++)
#define P make_pair
#define F first
#define S second
#define M LLONG_MAX
signed main(void){
    int n,m,ans,p,q,r,c;
    ans=0;
    string s,s1,s2;
    vector<int> v;
    cin>>n>>m;
    cin>>p>>q>>r;
    cin>>s;
    int a[n];
    rep(i,0,n){
        if(s[i]=='r')
        a[i]=r;
        else if(s[i]=='s')
        a[i]=p;
        else
        a[i]=q;
        ans+=a[i];
    }
    bool b[n];
    rep(i,0,n){
        b[i]=true;
    }
    
    rep(i,0,n-m){
        if(s[i]==s[i+m]&&b[i]){
            b[i+m]=false;
            ans-=a[i];
        }
    }
    cout<<ans<<endl;
    
    
}


Measured memory_bytes: 1408
/*
[arc072] D - Alice&Brown
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

ll X, Y;

bool solve() { return abs(X - Y) > 1; }

int main() {
    cin >> X >> Y;

    cout << (solve() ? "Alice" : "Brown") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin>>n;

    int sum=0;

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

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

    cout<<sum-p[n-1]/2<<endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	double x[4], y[4];
	while(1){
		rep(i, 4){
			if(scanf("%lf,%lf,", &x[i], &y[i]) == EOF)
				return 0;
		}

		bool ok = true;
		bool turn = true;
		rep(i, 4){
			bool b = (x[(i+1)%4]-x[i])*(y[(i+2)%4]-y[i])-(y[(i+1)%4]-y[i])*(x[(i+2)%4]-x[i]) < 0.0;
			if(!i) turn = b;
			else if(turn^b){
				ok = false;
				break;
			}
		}
		puts(ok ? "YES" : "NO");
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
char s[maxn];
int main()
{
    int n;
    cin>>n;
    cin>>s;
    int cnt=0,k=0;
    for(int i=0;i<n;++i)
        if(s[i]=='R')cnt++;
    for(int i=0;i<cnt;++i)
        if(s[i]=='R')k++;
    cout<<cnt-k<<endl;
    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i=0; i<N; i++) cin >> S[i];
  sort(S.begin(), S.end());
  for (int i=0; i<N; i++) {
    if (i!=N-1) cout << S[i];
    else cout << S[i] << endl;
  }
}

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

int main(){
	char s[100000];
	scanf("%s",s);
	
	int count[26] = {0};

	for(int i=0; i<strlen(s); i++){
		for(int j=0; j<26; j++){
			if(s[i] == 'a' + j){
				count[j]++;
				break;
			}
		}
	}

	for(int j=0; j<26; j++){
		if(count[j] == 0){
			printf("%c\n",'a' + j);
			return 0;
		}
	}
	printf("None\n");
	return 0;
}

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

void checkseven(int ip){
  while(ip>0){
    int rem = ip % 10;
    if(rem == 7){cout << "Yes" << endl;return;}
    ip /= 10;
  }
  cout << "No" << endl;
  return;
}

int main()
{
  int ip;
  cin >> ip;
  checkseven(ip);
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
using namespace std;

int main(void) {

  int i , j , k;

  string A , right , left;

  while(1) {

    cin >> A;

    if(A == "-") break;

    cin >> j;

    for(i = 0; i < j; i++) {

      cin >> k;

      left = A.substr(0,k);

      right = A.substr(k);

      A = right + left;

    }

    cout << A << "\n";

  }

}

Measured memory_bytes: 1208
import sys

n,p=list(map(int,input().split()))
s=sys.stdin.readline().strip()
reslst=[0]*p

cnt=0

if p==2:
    for i in range(n):
        if int(s[i])%2==0:
            cnt+=i+1
elif p==5:
    for i in range(n):
        if s[i]=='5' or s[i]=='0':
            cnt+=i+1
else:
    reslst[0]+=1
    tmp=1
    now=0
    for i in [int(x) for x in s[::-1]]:
        now+=i*tmp
        now%=p
        reslst[now]+=1
        tmp=(tmp*10)%p
    
    for i in range(p):
        cnt+=reslst[i]*(reslst[i]-1)//2

print(cnt)

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

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

    constexpr int bsize = 512;
    constexpr int max_value = (1LL << 31) - 1;

    int n, q; cin >> n >> q;
    vector<int> v(n, max_value);
    vector<int> bs(n / bsize + 1, max_value);
    while(q--) {
        int com, x, y; cin >> com >> x >> y;
        if(com == 0) {
            const int bi = x / bsize;
            bs[bi] = max_value;
            v[x] = y;
            for(int i = bi * bsize; i < min((bi + 1) * bsize, n); ++i) {
                bs[bi] = min(bs[bi], v[i]);
            }
        } else {
            y += 1;
            int ans = max_value;
            const int bl = x / bsize + 1;
            const int br = y / bsize;
            for(int i = x; i < min(y, bl * bsize); ++i) {
                ans = min(ans, v[i]);
            }
            for(int i = bl; i < br; ++i) {
                ans = min(ans, bs[i]);
            }
            for(int i = max(x, br * bsize); i < y; ++i) {
                ans = min(ans, v[i]);
            }
            cout << ans << endl;
        }
    }
}


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

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    string ans = "";
    if ((e - a) > k) {
        ans = ":(";
    } else {
        ans = "Yay!";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register int i=(a);i<=(b);i++)
using namespace std;
const int N=2e5+5;
int n,k,a[N],ans,st_mn[21][N],st_mx[21][N],b[N],f[N],vis[N];
inline void build_st()
{
	FOR(i,1,n) st_mn[0][i]=st_mx[0][i]=a[i];
	FOR(j,1,20)
		for (register int i=1;i+(1<<j)-1<=n;i++)
		{
			st_mn[j][i]=min(st_mn[j-1][i],st_mn[j-1][i+(1<<(j-1))]);
			st_mx[j][i]=max(st_mx[j-1][i],st_mx[j-1][i+(1<<(j-1))]);
		}
	return;
}
inline int query_min(int l,int r)
{
	int ret,step=log2(r-l+1);
	ret=min(st_mn[step][l],st_mn[step][r-(1<<step)+1]);
	return ret;
}
inline int query_max(int l,int r)
{
	int ret,step=log2(r-l+1);
	ret=max(st_mx[step][l],st_mx[step][r-(1<<step)+1]);
	return ret;
}
inline void pan()
{
	int tag=0;
	FOR(i,1,n) f[i]=1;
	FOR(i,2,n)
		if (a[i]>a[i-1]) f[i]=max(f[i],f[i-1]+1);
	FOR(i,1,n) if (f[i]>=k&&!vis[i]) ans--,tag=1;
	if (tag) ans++;
	return;
}
int main()
{
	scanf("%d%d",&n,&k);
	FOR(i,1,n) scanf("%d",&a[i]);
	build_st();
	ans=n-k+1;
	FOR(i,k+1,n)
	{
		int mx=query_max(i-k+1,i-1),mn=query_min(i-k+1,i-1);
		if (mx<a[i]&&mn>a[i-k]) ans--,vis[i]=1;
	}
	pan();
	printf("%d\n",ans);
//	FOR(i,k,n)
//	{
//		FOR(j,1,n) b[j]=a[j];
//		sort(b+i-k+1,b+i+1);
//		FOR(j,1,n) printf("%d ",b[j]);
//		putchar('\n');
//	}
	return 0;
}

Measured memory_bytes: 31232
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;
const int mxm = 500000;

int dp[mxm],arr[mxm];

void solve(){
    int n;
    cin>>n;
    rep(i,n) cin>>arr[i];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
    }
    cout<<dp[n-1]<<endl;
}

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

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  int x,y;
  vector<list<int>> e(n);
  for(int i=0;i<n-1;i++){
    cin >> x >> y;
    x--,y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  vector<int> pa(n,-1),cn(n,0);
  pa[0]=0;
  queue<int> bfs;
  bfs.push(0);
  int now;
  while(!bfs.empty()){
    now=bfs.front();
    bfs.pop();
    for(auto ne:e[now]){
      if(pa[ne]==-1){
        pa[ne]=now;
        bfs.push(ne);
        cn[now]++;
      }
    }
  }
  vector<vector<LL>> dp(n,vector<LL>(2,1));
  for(int i=0;i<n;i++){
    if(cn[i]==0){
      bfs.push(i);
    }
  }
  while(!bfs.empty()){
    now=bfs.front();
    bfs.pop();
    if(now==0) break;
    // cout << now SP dp[now][0] SP dp[now][1] << endl;
    dp[pa[now]][0]=(dp[now][0]+dp[now][1])*dp[pa[now]][0]%MOD;
    dp[pa[now]][1]=dp[now][0]*dp[pa[now]][1]%MOD;
    cn[pa[now]]--;
    if(cn[pa[now]]==0) bfs.push(pa[now]);
  }
  cout << (dp[0][0]+dp[0][1])%MOD << endl;
  return 0;
}


Measured memory_bytes: 14720
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		boolean[] f = new boolean[1000000];
        Arrays.fill(f, true);
        for(int i=2;i<1000000;i++)if(f[i])for(int j=i*2;j<1000000;j+=i)f[j]=false;
        while(s.hasNext()){
            int n = s.nextInt();
            int c = 0;
            for(int i=2;i<=n;i++)c+=f[i]?1:0;
            System.out.println(c);
        }
	}

}

Measured memory_bytes: 13000
#include <stdio.h>
#include<string.h>

int main(void) {
	char s[100005];
	fgets(s,sizeof(s),stdin);
	int bcount = 0;
	int wcount = 0;
	int ans = 0;
	int flag = 0;
	int blockcount = 1;
	int bpreindex = strlen(s) + 1;
	int wpreindex = strlen(s) + 1;
	if(s[0] == 'B'){
		bpreindex = 0;
	}else if(s[0] == 'W'){
		wpreindex = 0;
	}
	
	for(int i = 1; i < strlen(s); i++){
		if(s[i] =='B'){
			if(bpreindex + 1 != i){
				blockcount++;
			}
			bpreindex = i;
		} 
		else if(s[i] == 'W'){
			if(wpreindex + 1 != i){
				blockcount++;
			}
			wpreindex = i;
		}
	}

	printf("%d\n",(blockcount -1));





	return 0;
}


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

ll a[100005];

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

  ll n, l;
  cin >> n >> l;

  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++) {
    if (a[i] + a[i + 1] >= l) {
      cout << "Possible" << endl;
      for (int j = 1; j < i; j++)
        cout << j << endl;
      for (int j = n - 1; j > i; j--)
        cout << j << endl;
      cout << i << endl;
      return 0;
    }
  }

  cout << "Impossible" << endl;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define sz(x)          (int) x.size()
#define MOD 1000000007
#define EPS 1e-7


typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
    int a, b; cin>>a>>b;
    for(ll i = 1; i<=1000000; i++)
        if(i*8/100==a && i/10==b)
            return cout<<i, 0;
    cout<<-1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
ll INF = 6001001001001001001;
long double EPS = 1e-6;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

// MOD確認

vector<ll> A;

void fact(ll x){
    for(ll i = 1;i * i <= x;i++){
        if(i * i != x){
            if(x % i == 0){
                A.emplace_back(i);
                A.emplace_back(x/i);
            }
        }else{
            A.emplace_back(i);
        }
    }
}

int main(){
    ll N;
    cin >> N;
    ll ans = 0;
    fact(N-1);
    ans += A.size() - 1;
    A = vector<ll>();
    fact(N);
    rep(i,A.size()){
        ll n = N;
        if(A[i] == 1){
            ans++;
            continue;
        }
        while(n % A[i] == 0) n /= A[i];
        if(n % A[i] == 1) ans++;
    }
    cout << ans - 1<< endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
using namespace std;

int main()
{
    vector<string> words;
    char str[1030];
    scanf("%[^\n]", str);
    char* word = strtok(str, " .,");
    while(word != NULL){
        int length = strlen(word);
        if(2 < length && length < 7){
            words.push_back(string(word));
        }
        word = strtok(NULL, " .,");
    }
    
    for(int i = 0; i < words.size(); ++i){
        if(i) cout << ' ';
        cout << words[i];
    }
    cout << endl;
}

Measured memory_bytes: 1192
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	a = int(input())
	s,t = input().split()
	ans = ''
	for i  in  range(a):
		ans += s[i]+t[i]
	print(ans)

def factorization(n):
	if n<2:
		return []
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(fractions.gcd, numbers)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

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

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()


Measured memory_bytes: 69356