akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
cost = list(map(int,input().split()))
ab = [list(map(int, input().split(' '))) for i in range(m)]
graph = [[] for i in range(n)]
visited = [0 for i in range(n)]
vers = []
for a,b in ab:
  graph[a].append(b)
  graph[b].append(a)
for i in range(n):
  if visited[i] == 0:
    vers.append([])
    stack = [i]
    while stack:
      x = stack.pop()
      visited[x] = 1
      vers[-1].append((cost[x],x))
      for y in graph[x]:
        if visited[y] == 0:
          stack.append(y)
n_grph = len(vers)
if (n_grph-1)*2 > n:
  print("Impossible")
  exit()
for ver in vers:
  ver.sort()
visited = [0 for i in range(n)]
i = [i for i in range(n)]
costi = list(zip(cost,i))
costi.sort()
ans = 0
t = n_grph-2
if t >= 0:
  for ver in vers:
    ans += ver[0][0]
    visited[ver[0][1]] = 1

k = 0
while t > 0:
  c = costi[k][1]
  if visited[c] == 0:
    ans += costi[k][0]
    t -= 1
  k += 1
print(ans)

Measured memory_bytes: 97976
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
const double PI=acos(-1.0);
const double eps=1e-6;
int a[25],b[25],c[25];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
    int n;
    while(cin>>n){
        int ans=0;
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        rep(i,1,n) cin>>a[i];
        rep(i,1,n) cin>>b[i];
        rep(i,1,n-1) cin>>c[i];
        rep(i,1,n){
            ans+=b[a[i]];
            if(i==1);
            else if(a[i]==a[i-1]+1) ans+=c[a[i-1]];
        }
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,s,x,w;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<0){
		s=(-1*a)*c;
		if(a==0){
			printf("%d\n",s+d);
		}
		else{
			x=b*e;
			printf("%d\n",s+x+d);
		}
	}
	else{
		if(a==0){
			printf("%d\n",d);
		}
		else{
			w=b-a;
			x=w*e;
			printf("%d\n",x);
		}
	}
	return 0;
}


Measured memory_bytes: 2036
N, a, b = map(int, input().split())

total = 0

for i in range (1,N+1):
    if i == 10000:
        man = 1
        sen = 0
        hyaku = 0
        juu = 0
        ichi = 0
    elif i >= 1000:
        man = 0
        sen = int(i/1000)
        hyaku = int((i - sen*1000)/100)
        juu = int((i - sen*1000 - hyaku*100)/10)
        ichi = i%10
    elif i >= 100:
        man, sen = 0, 0
        hyaku = int(i/100)
        juu = int((i - hyaku*100)/10)
        ichi = i%10
    elif i >= 10:
        man, sen, hyaku = 0, 0, 0
        juu = int(i/10)
        ichi = i%10
    else:
        man, sen, hyaku, juu = 0, 0, 0, 0
        ichi = i
    
    if a <= (man + sen + hyaku + juu + ichi) <= b:
        total += i
    
print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

int main() {
    string s;
    cin >> s;
    cout << s << (s[s.size()-1]=='s'?"es":"s") << endl;
}


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

int main()
{
	string s;
	cin >> s;
	int flag1 = 0;
	int flag2 = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'N'&&flag1==0)
			flag1 = 1;
		if (s[i] == 'S'&&flag1 == 0)
			flag1 = -1;
		if (s[i] == 'E'&&flag2 == 0)
			flag2 = 1;
		if (s[i] == 'W'&&flag2 == 0)
			flag2 = -1;
		if (s[i] == 'N'&&flag1 == -1)
			flag1 = 100;
		if (s[i] == 'S'&&flag1 == 1)
			flag1 = 100;
		if (s[i] == 'E'&&flag2 == -1)
			flag2 = 100;
		if (s[i] == 'W'&&flag2 == 1)
			flag2 = 100;
		
	}
	if ((flag1 == 100 || flag1 == 0) && (flag2 == 100 || flag2 == 0))
		puts("Yes");
	else
		puts("No");


	return 0;
}


Measured memory_bytes: 256
'use strict'
const Main = (arg) => {
  let input = arg.trim().split('\n');
  let n = parseInt(input[0]);
  let pArr = input[1].split(' ').map(Number);
  // console.log({ n, pArr });
  let count = 0;
  for (let i = 1; i - 1 < n; i++) {
    if ((pArr[i - 1] < pArr[i] && pArr[i] < pArr[i + 1])
      || (pArr[i + 1] < pArr[i] && pArr[i] < pArr[i - 1])) {
      count += 1;
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int a[3];

  rep(i,3) cin >> a[i];

  sort(a,a+3);
  if(a[0]==a[1] && a[1]!=a[2] || a[1]==a[2] && a[1]!=a[0])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <vector>
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

bool cleared(vector<int> &v, int k, int a, int b){
  int rest = k;
  int d = a-b;
  for (auto it=v.begin();it != v.end();it++) {
    if (*it <= k*b) {
      continue;
    }
    rest -= (*it - k*b)/d;
    if ((*it - k*b)%d != 0) {
      rest--;
    }
    if (rest < 0) {
      return(false);
    }
  }
  return(true);
}

bool cmp(int a, int b) {
  return(a>b);
}

int main(){
  //  priority_queue<int> q;
  vector<int> v;
  int acc_b = 0;
  int n, a, b, d;
  int max_h;
  int count = 0;
  cin >> n >> a >> b;
  d = a - b;
  for (int i=0;i<n;i++) {
    int h;
    cin >> h;
    //    q.push(h);
    v.push_back(h);
  }
  sort(v.begin(), v.end(), cmp);
  long long ub, lb, ans;
  lb = v.front()/a;
  ub = v.front()/b + 1;

  while (lb<=ub) {
    long long k = (ub + lb)/2;
    bool result = cleared(v, k, a, b);
    if (result) {
      if (k-1 == lb) {
	ans = k;
	break;
      }
      ub = k;
    } else {
      if (k+1 == ub) {
	ans = ub;
	break;
      }
      lb = k;
    }
  }
  cout << ans << endl;
  return(0);
  // while (true) {
  //   max_h = q.top();
  //   if (acc_b >= max_h) {
  //     break;
  //   }
  //   q.pop();
  //   cerr << max_h << endl;
  //   q.push(max_h - d);
  //   acc_b += b;
  //   count++;
  // }
  // cout << count << endl;	
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define FOR(a,b,n) for(int a=b;a<=b;a++)
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("d",&a,&b)
#define sccc(a,b,c) scanf("d%d",&a,&b,&c)
#define sccs(s) scanf("%s",s)
#define pccs(s) printf("%s",s)
#define debug printf("---debug---");
#define pcc(a,b) printf("d",a,b)
#define pccc(a,b,c) printf("d%d",a,b,c)
#define pb push_back
typedef long long ll;
const int MAXN_1e5=1e5+5;
const int MAXN_2e5=2e5+5;
const int MAXN_3e5=3e5+5;
const int MAXN_4e5=4e5+5;
const int MAXN_5e5=5e5+5;
const int INF_INT=0x3f3f3f3f;
const long long INT_LL=2e18;
int main()
{
    ll n;
    cin>>n;
    ll cnt=0;
    for(int i=1;i<=n;i++)if(i%2)cnt++;
    printf("%f\n",cnt*1.0/n);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
#include <stack>
#include <map> // pair
#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
typedef std::stack<int> IntStack;
typedef std::stack<char> charStack;
#define START 0
#define FORWARD 1
#define BACK 2
using namespace std;
using ll = unsigned long long;
typedef pair <ll, ll > pll;
//*********************************************************
// 最大公約数（Greatest Common Divisor）を返す。
// 引数に０がある場合は０を返す。
//*********************************************************
ll gcd(ll a, ll b)
{
	ll tmp, r;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
	//// 引数に０がある場合は０を返す
	//if ((0 == m) || (0 == n))
	//	return 0;

	//// ユークリッドの方法
	//while (m != n)
	//{
	//	if (m > n) m = m - n;
	//	else         n = n - m;
	//}
	//return m;
}//gcd
int main()
{
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll x[100004] = {};
	ll y[100004] = {};
	ll z[100004] = {};
	string s;
	string s1, s2;
	//IntStack yStack;
	//charStack Stack;
	//vector<pair<int, int> > pairs(a);

	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> g;
	//f = LLONG_MAX;
	f = min({b,c,d,e,g});



	cout <<(a+f-1) / f + 4 << endl;



	//cout << ans << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//sort(x, x + a, std::greater<ll>());

//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得
//
//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}
//
//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> s[i][j];
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j]=='#'){
                if(s[i+1][j]!='#' && s[i-1][j]!='#' && s[i][j+1]!='#' && s[i][j-1]!='#'){
                    puts("No");
                    return 0;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

int main() {
  cpp_int a, b, c; cin >> a >> b >> c;
  // sqrt(a) + sqrt(b) < sqrt(c)
  // a + 2 * sqrt(a * b) + b < c
  // 2 * sqrt(a * b) < c - a - b <-- !!
  // 4 * a * b < c^2 + a^2 + b^2 - 2 * c * a + 2 * a * b - 2 * b * c
  // 0 < c^2 + a^2 + b^2  - 2 ca - 2ab - 2bc
  if (c - a - b < 0) {
    cout << "No\n";
  }
  else {
    if (2 * (a * b + b * c + c * a) < a * a + b * b + c * c) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        String s = sc.next();

        int ok = 0;
        int ng = 0;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'W') {
                ok++;
            } else {
                ng++;
            }
        }

        int min = ng;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) == 'E') {
                ng--;
            } else {
                ok--;
            }

            if (s.charAt(i - 1) == 'E') {
                ok++;
            } else {
                ng++;
            }

            min = Math.min(min, ng);
        }

        System.out.println(min);
    }

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


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

using namespace std;

int main(){
    // card array

    int N_symbol = 4, N_num = 13;
    vector<vector<int>> card_array(N_symbol,vector<int>(N_num,0));
    map<char,int> symbol_map1 = {
        {'S',0},
        {'H',1},
        {'C',2},
        {'D',3}
    };
    map<int,char> symbol_map2 = {
        {0,'S'},
        {1,'H'},
        {2,'C'},
        {3,'D'}
    };

    int n;

    std::cin >> n;

    char symbol;
    int  num;

    for(int i = 0;i<n;i++){
        std::cin >> symbol >> num;
        card_array[symbol_map1[symbol]][num-1] = 1;
    }

    for(int i = 0;i < N_symbol;i++){
        for(int ii = 0; ii < N_num;ii++){
            if (card_array[i][ii] == 0){
                cout << symbol_map2[i] << " " << ii+1 << "\n";
            }
        }
    }    

    return 0;   
}


Measured memory_bytes: 3136
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
int t[50][50];
int y[50][50];
int bfs[40][40][4][40][40];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int v[50][50];
int dir[50][50][4];

int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		//printf("%d %d\n",a,b);
		for(int i=0;i<a*2-1;i++){
			if(i%2==0){
				for(int j=0;j<b-1;j++)scanf("%d",&y[i/2][j]);
			}else{
				for(int j=0;j<b;j++)scanf("%d",&t[i/2][j]);
			}
		}
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)for(int k=0;k<4;k++)dir[i][j][k]=0;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			if(i<a-1&&!t[i][j])dir[i][j][0]=1;
			if(j<b-1&&!y[i][j])dir[i][j][1]=1;
			if(i&&!t[i-1][j])dir[i][j][2]=1;
			if(j&&!y[i][j-1])dir[i][j][3]=1;
		}
		int left=0;
		int right=10000;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)for(int k=0;k<4;k++){
			if(!dir[i][j][k])continue;
			queue<pair<int,int> >Q;
			for(int l=0;l<a;l++)for(int m=0;m<b;m++)bfs[i][j][k][l][m]=-1;
			bfs[i][j][k][a-1][b-1]=0;
			Q.push(make_pair(a-1,b-1));
			while(Q.size()){
				int row=Q.front().first;int col=Q.front().second;
				Q.pop();
				for(int l=0;l<4;l++){
					if(row+dx[l]<0||row+dx[l]>=a||col+dy[l]<0||col+dy[l]>=b||~bfs[i][j][k][row+dx[l]][col+dy[l]])continue;
					if(!dir[row][col][l])continue;
					if(row+dx[l]==i&&col+dy[l]==j&&(l^2)==k)continue;
					if(row==i&&col==j&&l==k)continue;
					bfs[i][j][k][row+dx[l]][col+dy[l]]=bfs[i][j][k][row][col]+1;
					Q.push(make_pair(row+dx[l],col+dy[l]));
				}
			}
	/*		printf("%d %d %d\n",i,j,k);
			for(int l=0;l<a;l++){
				for(int m=0;m<b;m++)printf("%d ",bfs[i][j][k][l][m]);
				printf("\n");
			}
			printf("\n");
	*/	}
		while(left+1<right){
			int M=(left+right)/2;
			for(int i=0;i<a;i++)for(int j=0;j<b;j++)v[i][j]=-1;
			queue<pair<pair<int,int>,int> >Q2;
			Q2.push(make_pair(make_pair(0,0),0));
			while(Q2.size()){
				int row=Q2.front().first.first;
				int col=Q2.front().first.second;
				int cost=Q2.front().second;
				Q2.pop();
				int val=0;
				for(int i=0;i<4;i++){
					if(!dir[row][col][i])continue;
					if(!~bfs[row][col][i][row][col])val=999999999;
					val=max(val,bfs[row][col][i][row][col]);
				}
			//	printf("%d %d %d: %d %d %d\n",M,row,col,val,bfs[row][col],cost);
				if(val+cost<=M){
					v[row][col]=cost;
				}else continue;
				for(int i=0;i<4;i++){
					if(row+dx[i]<0||row+dx[i]>=a||col+dy[i]<0||col+dy[i]>=b||~v[row+dx[i]][col+dy[i]])continue;
					if(i==0&&t[row][col])continue;
					if(i==1&&y[row][col])continue;
					if(i==2&&t[row-1][col])continue;
					if(i==3&&y[row][col-1])continue;
				///	if(<=M){
					v[row+dx[i]][col+dy[i]]=-2;
						Q2.push(make_pair(make_pair(row+dx[i],col+dy[i]),cost+1));
					//}
				}
			}
		//	printf("\n");
			if(~v[a-1][b-1])right=M;
			else left=M;
		}
		if(right>9000)printf("-1\n");
		else printf("%d\n",right);
	}
}

Measured memory_bytes: 31160
import sys

s = input()
s = s[:4]
a = s[:2]
b = s[2:]

	
if 0 <  int(a) <= 12 and 0 <  int(b) <= 12:

	print("AMBIGUOUS")
	sys.exit()


if int(a) >= 0 and 0 < int(b) <= 12:

	print("YYMM")
	sys.exit()
#１~12で0より上なら
if 0 < int(a) <= 12 and int(b) >= 0:

	print("MMYY")
	sys.exit()

print("NA")




Measured memory_bytes: 3064
n=int(input())
a=[0]*n
for x in range(1,120):
    for y in range(1,120):
        for z in range(1,120):
            i=(x+y+z)**2-x*y-y*z-z*x
            if i<=n:
                a[i-1]+=1
print(*a,sep="\n")

Measured memory_bytes: 9360
N, M = map(int, input().split())

k = []
s = []

for _ in range(M):
    tmp = tuple(map(int, input().split()))
    k.append(tmp[0])
    s.append(set(tmp[1:tmp[0] + 1]))

p = tuple(map(int, input().split()))

# print(k, s, p, sep="\n")

ans = 0

for i in range(2 ** N):
    # 各iでonになっている電球の数
    light_on = 0

    # 電球jについて
    for j in range(M):
        switch_on = 0

        for k in range(N):
            # onになっているスイッチが
            if (i >> k) & 1:
                # 電球jとつながっているものならカウント
                if k + 1 in s[j]:
                    switch_on += 1

        # onになっているスイッチの個数がp[j]に等しいなら電球jは点灯している
        if switch_on % 2 == p[j]:
            light_on += 1

    # 全ての電球が点灯しているならカウント
    if light_on == M:
        # print(bin(i))
        ans += 1

print(ans)


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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > jobs(m);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue;
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m - 1; i >= 0; i--) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int main() {
	ll x, y; cin >> x >> y;

	ll ans = 0;
	while(x < y) {
		x *= 2;
		if (x <= y) ans++;
	}
	printf("%lld\n", ans + 1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int ans=0,m,k,temp;
  cin >> k;
  for(int i=1;i<k+1;i++){
    for(int j=1;j<k+1;j++){
      for(int l=1;l<k+1;l++){
        temp=min(min(i,j),l);
        for(m=temp;m>1;m--){
          if(i%m==0 and j%m==0 and l%m==0)break;
        }
        ans+=m;
      }
    }
  }
  cout << ans << endl;

}

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

int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

int main(void) {
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i * i <= n; i++) ans = i * i;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < n; ++i)
int main() {

	int n,m;
	cin>>n>>m;
	vector<int> b(m);
	vector<int> v(m);
	REP(i,m){
		int c;
		cin>>v[i]>>c;
		REP(j,c){
			int a;
			cin>>a;
			b[i]|=1<<(a-1);
		}
	}
	vector<int> dp(1<<n,1e9+1);
	dp[0]=0;
	REP(i,m){
		for(int j=(1<<n)-1;j>=0;j--){
			dp[j|b[i]]=min(dp[j|b[i]],dp[j]+v[i]);
		}
	}
	if(dp.back()==1e9+1)cout<<-1<<endl;
	else cout<<dp.back()<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repx(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define repxeq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;

//少数点表示
//cout <<std::fixed << std::setprecision(14) <<double値
string t="";
vector<string> s;
int n;

void dfs(string d,int ch){
    if(d.size() == n){
        cout << d << endl;
        return;
    }
    
    repeq(i,ch){
        if(i != ch){
            dfs(d + (char)('a' + i),ch);
        }else{
            dfs(d + (char)('a' + i),ch+1);
        }
    }
}

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    cin >> n;
    string t = "a";
    dfs("",0);
}

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

int main(){
	double n; cin>>n;
	vector<int> x(n);
	rep(i,n) cin>>x[i];
	
	double y=accumulate(x.begin(),x.end(),0)/n;
	y=round(y);
	
	int cnt=0;
	rep(i,n){
		if(x[i]!=y) cnt+=(x[i]-y)*(x[i]-y);
	}
	cout<<cnt<<endl;
}

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

int main(void)
{
    int K, N;
    cin >> K >> N;
    int A[N];
    for (int &tmp: A) {
        cin >> tmp;
    }
    sort(A, A+N);
    int maxSpace = 0;
    for (int i = 0; i < N-1; i++){
        int tmp = A[i+1] - A[i];
        if (maxSpace < tmp) {
            maxSpace = tmp;
        }
    }
    if (maxSpace < (K - (A[N-1] - A[0]))) {
        maxSpace = K - (A[N-1] - A[0]);
    }
    cout << K - maxSpace << endl;
}



Measured memory_bytes: 1024
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new TEST().doIt();
    }
    class TEST{
        void doIt(){
        	int n = sc.nextInt() + 1;
        	int house[][][] = new int [4][3][10];
        	for(int i = 0;i < n-1;i++){
        		int t = sc.nextInt()-1;
        		int h = sc.nextInt()-1;
        		int w = sc.nextInt()-1;
        		int num = sc.nextInt();
        		house[t][h][w] = house[t][h][w] + num;
        		if(house[t][h][w] < 0)house[t][h][w] = 0;
        	}
        	for(int i = 0;i < 4;i++){
        		for(int j = 0;j < 3;j++){
        			for(int k = 0;k < 10;k++){
        				System.out.print(" "+house[i][j][k]);
        			}
        			System.out.println();
        		}
        		if(i != 3)System.out.println("####################");
        	}
        }
    }
}

Measured memory_bytes: 29420
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[10005];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++)
    {
        int cnt=0;
        for(int j=i+1;j<=n;j++)
        {
            while(cnt<i&&a[cnt]+a[i]<=a[j]) cnt++;
            ans+=i-cnt;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
int n, m;
ll a[100100];
vector<pair<ll, ll>> ops;
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	sort(&a[1], &a[n + 1]);
	for (int i = 1; i <= m; i++)
	{
		ll b, c;
		scanf("%lld%lld", &b, &c);
		ops.push_back(make_pair(c, b));
	}
	sort(ops.begin(), ops.end());
	int p = 1;
	for (int i = ops.size() - 1; i >= 0; i--)
	{
		bool flag = false;
		for (int j = 1; j <= ops[i].second && p>=1; j++)
		{
			if (a[p] >= ops[i].first) {
				flag = true; break;
			}
			a[p++] = ops[i].first;
		}
		if (flag) break;
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) ans += a[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3188
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <complex>
#include <cmath>
using namespace std;


int main(int argc, char const *argv[]) {
    long long n,k;cin>>n>>k;
    vector<long long> a(n);
    for(int i=0;i<n;++i)cin>>a[i];
    sort(a.begin(),a.end());
    long long res = 1ll<<62;
    for(int i=0;i+k-1<n;++i){
        res = min(res,a[i+k-1]-a[i]);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main(){
  int n,m;
  cin>>n>>m;
  Graph g(n+1);
  queue<int> que;
  vector<int> seen(100005,0),ans(100005); 
  seen[1]=1;
  que.push(1);
  rep(i,m){
    int a,b;cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int cnt=1;
  while(!que.empty()){
    int u = que.front();
    que.pop();
    for(int v : g[u]){
      if(seen[v])continue;
      else{
        ans[v] = u;
        cnt++;
        que.push(v);
        seen[v] = 1;
      }
    }
  }
  cout<<"Yes"<<endl;
  for (int i = 2; i <=n; i++)
  {
    cout<< ans[i]<<endl;
  }
  return 0;
}

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

const int N = 5e5 + 7, mod = 1e9 + 7;

int POW(int a, int b, int mod) {
	a %= mod; int r = 1;
	for(int i = b; i > 0; i >>= 1) {
		if(i & 1) r = (r * a) % mod;
		a = (a * a) % mod;
	}
	return r;
}

int f[N];


int nCr(int n, int r) {
	if(n < r) return 0;
	return f[n] * POW(f[n - r] * f[r], mod - 2, mod) % mod;
}

int nPr(int n, int r) {
	return nCr(n, r) * f[r] % mod;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	f[0] = 1;
	for(int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
	}

	int n, m; cin >> n >> m;

	if(m < n) {
		cout << 0 << endl;
		return 0;
	}

	int ans = nPr(m, n) * nPr(m, n) % mod;

	//cout << ans << endl;

	for(int i = 1; i <= n; i++) {
		int k = (nPr(m, i) * nCr(n, i) % mod) * (nPr(m - i, n - i) * nPr(m - i, n - i) % mod) % mod;
		if(i & 1) {
			ans = (ans + mod - k) % mod;
		} else {
			ans = (ans + k) % mod;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7468
#include<bits/stdc++.h>
using namespace std; 
int n,ans,a[25],b[25],c[25];
int main(){	
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int i=1;i<n;i++) cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(a[i+1]==a[i]+1) ans+=c[a[i]];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<string>s(N);
  for(int i=0;i<N;i++){
    cin>>s.at(i);
  }
  int M;
  cin>>M;
  vector<string>t(M);
  for(int i=0;i<M;i++){
    cin>>t.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
    int plus=0;
    int minus=0;
    for(int j=0;j<N;j++){
      if(s.at(j)==s.at(i)){
        plus=plus+1;
      }
      else{
      }
    }
    for(int j=0;j<M;j++){
      if(t.at(j)==s.at(i)){
        minus=minus+1;
      }
      else{
      }
    }
    sum=max(sum,plus-minus);
  }
  cout<<sum<<endl;
}
  

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

int main() {
    int a , b , c;
    cin >> a >> b >> c;
    int diff_ba = b - a;
    int diff_ca = c - a;
    int diff_cb = c - b;

    if (((diff_ba >= 0) && (diff_ca >= 0) && (diff_ca >= diff_ba)) || ((diff_ba <= 0) && (diff_ca <= 0) && (diff_ca <= diff_ba)) || ((diff_ba * diff_ca < 0))) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    string str1, str2, str3;
    cin >> str1 >> str2 >> str3;
    cout << str1[0] << str2[1] << str3[2] << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

## BFS
from collections import deque

def main():

    #入力受け取り
    N, Q = mi()
    x = li2(N-1)

    cnt = [0]*N
    for i in range(Q):
        p0, p1 = mi()
        cnt[p0-1] += p1

    #隣接リスト作成
    adj = [[] for i in range(N)]
    for i in range(N-1):
        adj[x[i][0]-1].append(x[i][1]-1)
        adj[x[i][1]-1].append(x[i][0]-1)

    que = deque()
    ans = [0]*N

    # BFS
    que.append((0, 0))
    num = 0
    while que!=deque():
        v = que.popleft()
        ans[v[1]] = ans[v[0]] + cnt[v[1]]
        for next in adj[v[1]]:
            if next != v[0]:
                que.append((v[1], next))

    print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 104624
# https://atcoder.jp/contests/agc008/tasks/agc008_a
# どう見ても符号反転は1回するのが最適
# ひたすら場合分け


x, y = map(int, input().split())
if x * y < 0:  # 異符号ならば答えは一つ
    print(abs(abs(x) - abs(y)) + 1)
    exit()
elif 0 <= x < y:
    print(y - x)
    exit()
elif 0 < y < x:
    print(2 + x - y)
    exit()
elif y == 0 and y < x:
    print(1 + x)
    exit()
elif x < y <= 0:
    print(y - x)
    exit()
elif y < x < 0:
    print(2 + x - y)
    exit()
elif x == 0 and y < x:
    print(1 - y)
    exit()
raise ValueError()


Measured memory_bytes: 61640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <istream>
#include <set>
#include <queue>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int count = 0;
	vector<ll>a(n);
	rep0(i, n - 1)cin >> a[i];
	rep0(j, n - 1) {
		if (j + 1 != a[j]) {
			++count;
		}
    }
	if (count == 2) {
		cout << "YES" << endl;
	}
	else if (count == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t N, M; cin >> N >> M;
VP LR(M), RL(M); 
rep(i, 0, M) {
    cin >> LR[i].first >> LR[i].second;
    RL[i].first = LR[i].second;
    RL[i].second = LR[i].first;
}
sort(ALL(LR));
sort(ALL(RL));

cout << max(0LL, RL.front().first - LR.back().first + 1LL) << endl;


}

// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



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

def cul(K, n):
    i = 0
    while n < K:
        n = n*2
        i += 1
    return 1/(2**i)

ans = 0
for n in range(1, N+1):
    ans += (1/N) * cul(K, n)

print(ans)

Measured memory_bytes: 2940
#include <stdio.h>
#include <math.h>
int main(void)
{
	int i=0,max=0;
	double x[20],y[20],s1=0,s;
	for(i=0;i<20;i++){
		int ret=scanf("%lf,%lf",&x[i],&y[i]);
		if(ret==EOF) break;
		if(i>max) max=i;
	}
	for(i=0;i<max;i++){
		s1=s1+(fabs((x[i]*y[i+1])-(x[i+1]*y[i])));
	}
	s1=s1+(fabs((x[i]*y[0])-(x[0]*y[i])));
	s=s1/2;			
	
	printf("%f\n",s);
	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

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

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[3],b,c,d,e,f;
		scanf("%d%d%d",&a[0],&a[1],&a[2]);
		for(d=0;d<3;d++)
			for(e=d;e<3;e++)
				if(a[d]<a[e])
				{f=a[d];a[d]=a[e];a[e]=f;}
		f=a[0]*10+a[1];
		f+=a[2];
		printf("%d\n",f);
	return 0;
}

Measured memory_bytes: 256
def main():
    N, K = (int(i) for i in input().split())
    cnt = 0
    for i in range(1, 2*10**5+1):
        if K*i <= N:
            cnt += 1
        else:
            break
    addcnt = 0
    if K % 2 == 0:
        for i in range(1, 2*10**5+1, 2):
            if (K//2)*i <= N:
                addcnt += 1
            else:
                break
    ans = cnt**3 + addcnt**3
    print(ans)


if __name__ == '__main__':
    main()


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

long stpow(long b, long e) {
  long ret = 1;
  while (e--) {
    if (ret < 1e18) {
      ret *= b;
    }
  }
  return ret;
}

long n, a;
long sub(int k) {
  long x = (long)pow(n, 1.0 / (k + 1));
  if (stpow(x, k + 1) >= n) --x;
  long curr = stpow(x, k + 1);
  for (int i = 1; i <= k + 1; ++i) {
    curr /= x;
    curr *= x + 1;
    if (curr >= n) {
      return (k + 1) * x + i + k * a; 
    }
  }
  return 1e18;
}

int main() {
  cin >> n >> a;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  long mn = 1e18;
  for (int k = 0; k < 45; ++k) {
    mn = min(mn, sub(k));
  }
  cout << mn << endl;
}


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


int main()
{
    int N, K;
    cin >> N >> K;
    long long  res = 0;
    long long  tmp1 = N / K;
    if(K % 2== 0)
    {
        long long  tot = N / (K / 2);
        long long  tmp2 = tot - tmp1;
        res = tmp1 * tmp1 * tmp1 + tmp2 * tmp2 * tmp2;
    }

    else res = tmp1 * tmp1 * tmp1;
    cout<< res << endl;
    return 0;
}



Measured memory_bytes: 256
from collections import Counter
from functools import lru_cache
from math import gcd


@lru_cache(maxsize=None)
def get_dividers(n):
    """
    正の整数 n の約数を取得する
    """

    dividers = {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}
    return dividers | {n // d for d in dividers}


@lru_cache(maxsize=None)
def lcm(a, b):
    """
    aとbの最小公倍数を計算する
    """

    return a * b // gcd(a, b)


N = int(input())
A = tuple(map(int, input().split(' ')))

counter = Counter()
for a in A:
    counter.update(get_dividers(a))

ans = 1
candidates = []
for key, value in counter.items():
    if value == N:
        ans = lcm(ans, key)
    elif value == N - 1:
        candidates.append(key)

if candidates:
    ans = max([lcm(ans, c) for c in candidates])

print(ans)


Measured memory_bytes: 21732
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
LL a,b,c;
int main(){
    cin>>a>>b>>c;

    cout<<(a+b)*c/2;
        
    return 0;
}


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

a_list = list(map(int, input().split()))

if len(set(a_list)) == 1:
    print(a_list[0])
else:
    def euclidean_algorithm(a, b):
        a, b = min(a, b), max(a, b)
        while a > 0:
            a, b = b % a, a
        return b

    ans = a_list[0]
    for i in range(len(a_list) - 1):
        ans = euclidean_algorithm(ans, a_list[i + 1])
    print(ans)


Measured memory_bytes: 14224
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long 
#define jaldi_chal  ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c,i) for(auto i=(c).begin(); i != (c).end(); i++)
#define REP(i,k) for( ll i=0;i<k;i++)
#define REW(i,a,b) for(ll i=a;i<=b;i++)
#define M 1000000007
#define F first
#define dbg(x)  cout<<#x<<" " <<x<<endl;
#define S second
#define inf 1e10
#define endl "\n"


int main() {
jaldi_chal
ll n;
cin>>n;
ll a[n];
REP(i,n) 
{
    cin>>a[i];
}
ll dp[n+1];
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
REW(i,2,n-1)
{
    dp[i]=min(dp[i-1]+(abs(a[i]-a[i-1])),dp[i-2]+abs(a[i]-a[i-2]));
}

cout<<dp[n-1];



	return 0;
}

Measured memory_bytes: 1792
s = input()
K = int(input())
alpha = "abcdefghijklmnopqrstuvwxyz"
inv_alpha = "azyxwvutsrqponmlkjihgfedcb"
D = {inv_alpha[i]: i for i in range(26)}
n = len(s)
for i in range(n):
  if i == n - 1:
    x = K % 26
    print(alpha[(26-D[s[i]]+x)%26], end = '')
  else:
    if K >= D[s[i]]:
      K -= D[s[i]]
      print('a', end = '')
    else:
      print(s[i], end = '')
print()

Measured memory_bytes: 9288
#include<iostream>
using namespace std; // 575

int main() {
	int N, X = 0, Y = 0, Z = 0, ans = 0;
	string s;
	cin >> N;
	for (int i = 0;i < N;++ i) {
		cin >> s;
		if (s[0] == 'B') {
			if (s[s.size() - 1] == 'A') ++ Z;
			else ++ Y;
		} else if (s[s.size() - 1] == 'A') ++ X;
		for (int j = 0;j < s.size() - 1;++ j) {
			if (s[j] == 'A' && s[j + 1] == 'B') ++ ans;
		}
	}
	ans += min(X, Y) + Z;
	if (X == Y && Y == 0 && 0 < Z) -- ans;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

1. ABが中に入ってるなら必ず足される
2. ～Aという文字列とB～という文字列は合成でABが作れる
ということで、～Aという文字列がX個、B～という文字列がY個、B～Aという文字列がZ個とする
当然、min(X, Y)個は作れる
同値でなければ、このままZを繋げて作れる(同値ならZ-1個を作れる)
ただし全部0ならもちろん0
反対側も同様

??A B～A B～A B～
が1セット(作れるなら)
??A B～
が残り
で、得られるスコアは(Z+1 + min(X,Y)-1)=min(X,Y)+Z

次に0=X<Yとする
この時、
B～A B～A B～
で、得られるスコアはmin(X,Y)+Zに等しい
最後、X=Y=0とする
この時、得られるスコアはZ-1になるので例外
*/

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
/*		FastScanner sc = new FastScanner("6 6 \r\n" +
				"..#..#\r\n" +
				"......\r\n" +
				"#..#..\r\n" +
				"......\r\n" +
				".#....\r\n" +
				"....#.");*/
    	//FastScanner sc = new FastScanner("13 3 ");
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[h][w];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		int ans;
		if(n-k <0)
		{
			ans = 0;
		}
		else
		{
			ans = n-k+1;
		}



		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }

}

Measured memory_bytes: 22612
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll a[100005];

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

int32_t main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    ll n,k;
    read(n); read(k);
    int m = 0;
    for0(i,n) {
        read(a[i]);
        m = max(m,a[i]);
    }
    ll g = a[0];
    for (int i=1; i<n; i++) {
        g = gcd(g,a[i]);
    }
    prl(g);
    
    bool possible = false;
    for0(i,n) {
        ll dif = fabs(a[i]-k);
        if (dif % g == 0) {
            possible = true; 
            break;
        }
    }
    if (k <= m && possible) 
        cout<<"POSSIBLE"<<endl;
    else 
        cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(void){
int n;
cin>>n;
int N=n;
string ret=to_string(n)+ ":";

int cnt=0;
while(n%2==0){
n/=2;
ret+=" 2";
cnt++;
}

int i=3;


while(n>1){
	if(i>(N/2))break;
	while(n%i==0){
	n/=i;
	ret+=(" "+to_string(i));
	cnt++;
	}
	i+=2;
}
	if(cnt==0)ret+=" "+to_string(n);
	cout<<ret<<endl;
return 0;
	
}


Measured memory_bytes: 3268
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <atcoder/twosat>
using namespace atcoder; 

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, d; cin >> n >> d;

  two_sat SAT(n);
  vector<pair<int, int>> flags(n);
  rep (i, n) {
    int x, y; cin >> x >> y;
    flags[i] = {x, y};
  }

  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      if (abs(flags[i].first-flags[j].first) < d) {
        SAT.add_clause(i, 1, j, 1);
      }
      if (abs(flags[i].first-flags[j].second) < d) {
        SAT.add_clause(i, 1, j, 0);
      }
      if (abs(flags[i].second-flags[j].first) < d) {
        SAT.add_clause(i, 0, j, 1);
      }
      if (abs(flags[i].second-flags[j].second) < d) {
        SAT.add_clause(i, 0, j, 0);
      }
    }
  }

  if (!SAT.satisfiable()) {
    cout << "No" << '\n';
  } else {
    cout << "Yes" << '\n';
    auto answer = SAT.answer();
    for (int i = 0; i < answer.size(); i++) {
      if (answer[i]) cout << flags[i].second << '\n';
      else cout << flags[i].first << '\n';
    }
  }

  return 0;
}

Measured memory_bytes: 3756