akhauriyash/Code-Regression huggingface dataset:
// JOI2017年予選５　尾根
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0634
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int H,W;
    cin >> H >>W;
    int map[H+2][W+2];
    int onecheck[H+2][W+2];
    for(int i=0;i<H+2;i++){
        for(int j=0;j<W+2;j++){
            map[i][j]=H*W+1;
            onecheck[i][j]=0;
        }
    }
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin >> map[i][j];
        }
    }
    // 水たまりを探す
    vector<pair<int,int> > mizutamari;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(map[i][j]<map[i+1][j] && map[i][j]<map[i-1][j] && map[i][j]<map[i][j+1] && map[i][j]<map[i][j-1])mizutamari.push_back(make_pair(i,j));
        }
    }
    
    for(int k=0;k<mizutamari.size();k++){
        queue<pair<int, int> >q;// キュー q を定義
        q.push(make_pair(mizutamari[k].first,mizutamari[k].second));//スタート地点をqにプッシュ
        int step[H+2][W+2];
        for(int i=0;i<H+2;i++){
            for(int j=0;j<W+2;j++){
                step[i][j]=0;
            }
        }
        while(q.empty()==false){// q が空になるまでループを回す
            pair<int, int> point=q.front();
            q.pop();
            int i=point.first;
            int j=point.second;
            if(map[i][j]<map[i+1][j] && step[i+1][j]==0 && onecheck[i+1][j]<2){step[i+1][j]=1;onecheck[i+1][j]++;q.push(make_pair(i+1,j));}
            if(map[i][j]<map[i-1][j] && step[i-1][j]==0 && onecheck[i-1][j]<2){step[i-1][j]=1;onecheck[i-1][j]++;q.push(make_pair(i-1,j));}
            if(map[i][j]<map[i][j+1] && step[i][j+1]==0 && onecheck[i][j+1]<2){step[i][j+1]=1;onecheck[i][j+1]++;q.push(make_pair(i,j+1));}
            if(map[i][j]<map[i][j-1] && step[i][j-1]==0 && onecheck[i][j-1]<2){step[i][j-1]=1;onecheck[i][j-1]++;q.push(make_pair(i,j-1));}
        }
    }

    int count=0;
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(onecheck[i][j]>1)count++;
        }
    }


    cout << count << endl;

    return 0;
}


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


int main()
{
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	//#endif
	int n;
	cin>>n;
	int in[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			cin>>in[i][j];
	}
	int temp_dp[3]={0,0,0};
	int dp[3]={0,0,0};
	for(int i=0;i<n;i++)
	{
		memset(temp_dp,0,3);
		for(int m=0;m<3;m++)
		{
			for(int j=0;j<3;j++)
			{
				if(m!=j)
				{
					temp_dp[j]=max(temp_dp[j],dp[m]+in[i][j]);
				}
			}
		}
		dp[0]=temp_dp[0];
		dp[1]=temp_dp[1];
		dp[2]=temp_dp[2];
	}
	cout<<max({dp[0],dp[1],dp[2]})<<'\n';
	return 0;
}

Measured memory_bytes: 1408
n = int(input())
s = [i for i in input()]

import collections
ans = 0
for i in range(1, n):
    #print(s[:i], s[i:])
    c1 = collections.Counter(s[:i])
    c2 = collections.Counter(s[i:])
    p = c1.keys() & c2.keys()
    #print(p)
    if len(p) > ans:
        ans = len(p)
print(ans)



Measured memory_bytes: 3436
// a template for main.cpp
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, m, k;
const int sz = 2e5 + 10;
ll f[sz], g[sz], inv[sz], e[sz];
const int mod = 998244353;

int com(int N, int K) {
	return f[N] * g[N - K] % mod * g[K] % mod;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> m >> k;
	inv[1] = 1;
	for (int i = 2; i <= n; i++) {
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
	}
	f[0] = g[0] = e[0] = 1;
	for (int i = 1; i <= n; i++) {
		f[i] = (f[i - 1] * i) % mod;
		g[i] = (g[i - 1] * inv[i]) % mod;
		e[i] = (e[i - 1] * (m - 1)) % mod;
	}
	int ans = 0;
	for (int i = 0; i <= k; ++i) {
		ans = (ans + m * e[n - i - 1] % mod * com(n - 1, i)) % mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 9848
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N; cin >> N;
    ll A,B,C,D; cin >> A >> B >> C >> D;
    bool ok = false;
    rep(i,N){
        if(B >= A-i*D+(N-1-i)*C && B <= A+(N-1-i)*D-i*C) ok = true;
    }
    cout << (ok?"YES":"NO") << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    red = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=True
    )
    blue = sorted(
        [list(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[0]
    )
    ans = 0
    for b in blue:
        for i, r in enumerate(red):
            if b[0] > r[0] and b[1] > r[1]:
                ans += 1
                red.pop(i)
                break
    print(ans)


main()


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
  int n,m,i;
  scanf("%d%d",&n,&m);
  int s,c;
  int a[3]={-1,-1,-1};
  for(i=0;i<m;i++){
    scanf("%d%d",&s,&c);
    if(a[s-1]!=-1&&a[s-1]!=c){
      printf("-1");
      return 0;
    }
  a[s-1]=c;
  }
  if(n!=1&&a[0]==0){
    printf("-1");
    return 0;
  }
  if(n==1&&a[0]==-1) a[0]=0;
  if(n!=1&&a[0]==-1) a[0]=1;
  for(i=0;i<n;i++){
    if(a[i]==-1) printf("0");
    else printf("%d",a[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
using namespace std;


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int hantei=0;
    if(a==b)hantei++;
    if(b==c)hantei++;
    if(c==a)hantei++;
    if(hantei==1) cout <<"Yes"<<endl;
    else cout <<"No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N; cin >> N;
	int sum = 0;
	rep(i, 0, N) {
		int tmp; cin >> tmp;
		sum += tmp;
	}
	int ans = sum - N;
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, a, b, t, i, sum = 0;
    scanf("%d%d%d", &n, &a, &b);
    for(i = 1; i <= n; i++)
    {
        if(s(i) >= a && s(i) <= b)
            sum += i;
    }
    printf("%d\n", sum);
    return 0;
}
int s(int n)
{
    int sum2 = 0;
    while( n > 0)
    {
        sum2 += n % 10;
        n /= 10;
    }

    return sum2;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(ll i=a;i<=(ll)b;++i)
#define per(i,a,b) for(ll i=a;i>=(ll)b;--i)
#define ll long long
#define lowbit(x) ((x)&(-x))

const int maxn=1e5+5;
ll a[maxn],b[maxn],c[maxn];
vector<ll>v;
int main()
{
    IOS
    ll x,y,A,B,C; cin>>x>>y>>A>>B>>C;
    rep(i,1,A) cin>>a[i];
    rep(i,1,B) cin>>b[i];
    rep(i,1,C) cin>>c[i];
    sort(a+1,a+A+1); reverse(a+1,a+A+1);
    sort(b+1,b+B+1); reverse(b+1,b+B+1);
    sort(c+1,c+C+1); reverse(c+1,c+C+1);
    rep(i,1,min(x,A)) v.pb(a[i]);
    rep(i,1,min(y,B)) v.pb(b[i]);
    rep(i,1,C) v.pb(c[i]);
    sort(v.begin(),v.end()); reverse(v.begin(),v.end());
    ll sum=0;
    rep(i,0,x+y-1) sum+=v[i];
    cout<<sum<<"\n";
}

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

struct NODE{
	int id = -1;
	int parent = -1;
	int left = -1;
	int right = -1;
	int sibling = -1;
	int degree = 0;
};

void show_id(NODE *nodes, int id){
	cout << " " << nodes[id].id;
}

void show_preorder(NODE *nodes, int id){
	show_id(nodes, id);
	if(nodes[id].left != -1)
		show_preorder(nodes, nodes[id].left);
	if(nodes[id].right != -1)
		show_preorder(nodes, nodes[id].right);
}

void show_inorder(NODE *nodes, int id){
	if(nodes[id].left != -1)
		show_inorder(nodes, nodes[id].left);

	show_id(nodes, id);

	if(nodes[id].right != -1)
		show_inorder(nodes, nodes[id].right);
}

void show_postorder(NODE *nodes, int id){
	if(nodes[id].left != -1)
		show_postorder(nodes, nodes[id].left);

	if(nodes[id].right != -1)
		show_postorder(nodes, nodes[id].right);

	show_id(nodes, id);
}

int main(){
	int n;
	cin >> n;
	NODE *nodes = new NODE[n]; 

	int id;
	for(int i=0; i<n; ++i){
		cin >> id;
		nodes[id].id = id;
		cin >> nodes[id].left >> nodes[id].right;

		nodes[ nodes[id].left ].sibling = nodes[id].right;
		nodes[ nodes[id].right ].sibling = nodes[id].left;
		if(nodes[id].right != -1)
			nodes[ nodes[id].right ].parent = id;
		if(nodes[id].left != -1)
			nodes[ nodes[id].left ].parent = id;
	}

	// Find root
	int root_id;
	for(int i=0; i<n; ++i){
		if(nodes[i].parent == -1){
			root_id = i;
			break;
		}
	}

	cout << "Preorder" << endl;
	show_preorder(nodes, root_id);
	cout << endl;

	cout << "Inorder" << endl;
	show_inorder(nodes, root_id);
	cout << endl;

	cout << "Postorder" << endl;
	show_postorder(nodes, root_id);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3112
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
public static void main(String[] args) throws FileNotFoundException, IOException{
       Scanner s=new Scanner(System.in);
      int n=s.nextInt();s.nextLine();
      char[] ss=s.nextLine().toCharArray();
      int res=0;
      for(int i=0;i<=999;i++){
      	int d1=i%10,d2=(i/10)%10,d3=i/100;
      	int[] d=new int[]{d1,d2,d3};
      	int p=0;
      	for(int j=0;j<n;j++){
      		if(p>2){break;}
      		if(ss[j]-'0'==d[p]){
      			p++;
      		}
      	}
      	if(p>2){res++;}

      }
      	System.out.println(res);
      }
        }
    


Measured memory_bytes: 24652
#include<iostream>
#include<algorithm>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int i;
struct card
{
	char c,x;
};
void print(struct card A[], int n)
{
	r(i, n)
	{
		if (i)cout << " ";
		cout << A[i].c<< A[i].x;
	}
	cout << endl;
}

void selection(struct card A[], int n)
{ 
	bool flag;
	int mini, j;
	r(i, n - 1)
	{
		flag = false;
		mini = i;
		for (j = i; j < n; j++)
			if (A[j].x < A[mini].x)
			{
				mini = j;
				flag = true;
			}
		if (flag)
			swap(A[mini], A[i]);
	}
}

void bubble(struct card A[], int n)
{
	int j;
	r(i, n - 1)
	{
		j = i + 1;
		r(j, n - 1)
			if (A[j].x > A[j + 1].x)
				swap(A[j], A[j + 1]);
	}
}

bool compare(struct card A[], struct card B[], int n)
{
	bool flag = true;
	r(i, n)
	{
		if (A[i].c != B[i].c) 
		{
			flag = false; break;
		}
	}
	if (flag)return true;
	else return false;
}

int main()
{
	int n, i;
	card *A, *B;
	cin >> n;
	A = new card[n];
	B = new card[n];

	r(i, n)
		cin >> A[i].c >> A[i].x;
	r(i,n)
		B[i] = A[i];

	bubble(A, n);
	selection(B, n);

	print(A, n);
	cout << "Stable" << endl;

	print(B, n);
	if (compare(A, B, n))cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	return 0;
}


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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}

int main() {
	int x, y;
	scanf("%d %d", &x, &y);
	if (x%y == 0) {
		PRINTD(-1);
	}
	else {
		PRINTD(x);
	}
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 */
public class Main {

	/** 羊の定義 */
	private static final char SHEEP = 'S';
	/** 狼の定義 */
	private static final char WOLF = 'W';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			char[] s = scanner.next().toCharArray();
			boolean[] b = new boolean[n];
			IntStream.range(0, n).forEach(i -> b[i] = (s[i] == 'o'));
			char[] result = new char[n];
			result[0] = SHEEP;
			result[1] = SHEEP;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = SHEEP;
			result[1] = WOLF;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = WOLF;
			result[1] = WOLF;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			result[0] = WOLF;
			result[1] = SHEEP;
			if (checkResult(n, b, result)) {
				System.out.println(result);
				return;
			}
			System.out.println(-1);
		}
	}

	/**
	 * @param n
	 * @param b
	 * @param result
	 * @return このまま矛盾することなく計算できるかどうか
	 */
	private static boolean checkResult(int n, boolean[] b, char[] result) {
		// 2〜n-1まで動物を計算
		IntStream.range(2, n).forEach(i -> {
			if (WOLF == result[i - 1]) {
				result[i] = (b[i - 1]) ? reverse(result[i - 2]) : result[i - 2];
			} else {
				result[i] = (b[i - 1]) ? result[i - 2] : reverse(result[i - 2]);
			}
		});
		boolean lastOk = false, firstOk = false;
		if (WOLF == result[n - 1]) {
			lastOk = (b[n - 1]) ? (result[0] != result[n - 2]) : (result[0] == result[n - 2]);
		} else {
			lastOk = (b[n - 1]) ? (result[0] == result[n - 2]) : (result[0] != result[n - 2]);
		}
		if (WOLF == result[0]) {
			firstOk = (b[0]) ? (result[1] != result[n - 1]) : (result[1] == result[n - 1]);
		} else {
			firstOk = (b[0]) ? (result[1] == result[n - 1]) : (result[1] != result[n - 1]);
		}
		return lastOk && firstOk;
	}

	/**
	 * @param c
	 * @return cの反対の動物
	 */
	private static char reverse(char c) {
		return (c == SHEEP) ? WOLF : SHEEP;
	}
}


Measured memory_bytes: 27492
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Finish_read;
template<class T>
inline void read(T &x) {
	Finish_read=0;x=0;int f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x*=f;Finish_read=1;
}
template<class T>
inline void print(T x) {
	if(x/10!=0)
		print(x/10);
	putchar(x%10+'0');
}
template<class T>
inline void writeln(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
	putchar('\n');
}
template<class T>
inline void write(T x) {
	if(x<0)
		putchar('-');
	x=abs(x);
	print(x);
}
/*================Header Template==============*/
string s;
int main() {
	cin>>s;
	for(int i=0;i<s.length()-1;i++)
		if(s[i]=='A'&&s[i+1]=='C') {
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                    cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)             cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)         cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll s[n];
    ll sum=0;
    ll mini=inf;
    rep(i,0,n){
        cin >> s[i];
        sum+=s[i];
        if(s[i]%10!=0){
            mini=min(mini,s[i]);
        }
    }
    if(sum%10==0 && mini!=inf){
        sum-=mini;
    }
    if(sum%10==0) cout << 0;
    else cout << sum;
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]

    if A[0] != 0:
        print(-1)
        return
    answer = 0
    flag = 0
    for i in range(N - 1):
        if A[i + 1] - A[i] > 1:
            print(-1)
            return
        elif A[i + 1] == A[i]:
            answer += A[i]
        elif A[i + 1] == A[i] + 1:
            flag = A[i + 1]
        else:
            answer += flag
            flag = A[i + 1]
    answer += flag
    print(answer)


if __name__ == "__main__":
    main()


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

int main() {
  int n;
  scanf("%d", &n);
  int n1, n2;
  n1 = n/100;
  n2 = n/10-n1*10;
  n = n - n1*100 -n2*10;
  if(n == 2|| n== 4|| n == 5||n==7||n == 9) {
    printf("hon\n");
  }else if(n == 0||n==1||n==6||n==8) {
    printf("pon\n");
  }else {
    printf("bon\n");
  }
  return 0;
}


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

int n;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    int l = 1;
    int r = 1;
    int sum = 0;
    int cnt = 0;
    while (l < n) {
      while (sum < n && r < n) {
        sum += r++;
      }

      if (sum == n) cnt++;
      do {
        sum -= l++;
        if (sum == n) cnt++;
      } while (sum >= n);
    }

    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 2584
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)){
        	while(true) {
        		int m = sc.nextInt();
        		int n = sc.nextInt();
        		if(m==0 && n==0) break;
        		int w [] = new int[n];
        		int sum = 0;
        		int max = 0;
        		for(int i=0;i<n;i++) {
        			w[i] = sc.nextInt();
        			sum += w[i];
        			max = Math.max(w[i], max);
        		}
        		max = Math.max(max, sum/m);
        		
        		for(int i=max;;i++) {
        			sum = 0;
        			int count = 0;
        			for(int j=0;j<n;j++) {
        				sum += w[j];
        				if(sum>i) {
        					j--;
        					count++;
        					sum = 0;
        				}
        				if(count==m) break;
        			}
        			if(count<m) {
        			System.out.println(i);
        			break;
        			}
        		}
        	}	
        }
    }
}


Measured memory_bytes: 29792
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = float("inf")
for i in range(n-k+1):
    l = a[i]
    r = a[i+k-1]
    time = min(abs(l) + abs(l-r), abs(r) + abs(l-r))
    # print(l, r, time)
    ans = min(ans, time)

print(ans)


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using ll = long long;
#define show(x) std::cerr << #x << " = " << (x) << std::endl
int main()
{
    ll K;
    std::cin >> K;
    const ll NUM = 700;
    std::vector<ll> num(NUM + 1);
    for (ll i = 0; i <= NUM; i++) { num[i] = i * (i + 1) / 2 * (i + 2) / 3 * (i + 3) / 4 * (i + 4) / 5 * (i + 5) / 6 * (i + 6) / 7; }
    bool usef = false;
    std::string ans;
    for (int i = NUM; i >= 1; i--) {
        const ll f = K / num[i];
        K %= num[i];
        if (f == 0 and not usef) { continue; }
        usef = true, ans += std::string(f, 'F') + "ESTIVAL";
    }
    assert(ans.size() <= 5000);
    std::cout << ans << std::endl;
    return 0;
}


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

using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a>=b)
{
for(int i=0;i<a;i++)
cout<<b;
}
else if(a<b)
{
for(int i=0;i<b;i++)
cout<<a;
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
deque<int>a,b;
ll n;int ly;
void work(ll n)
{
	if (n!=1)
	{
		work(n/2);
		a.push_back(++ly),b.push_back(ly);
		if (n&1) a.push_front(++ly),b.push_back(ly);
	}
}
int main()
{
	scanf("%lld",&n);
	work(n+1);
	printf("%d\n",a.size()*2);
	for (int i=0;i<a.size();i++)
		printf("%d ",a[i]);
	for (int i=0;i<b.size();i++)
		printf("%d ",b[i]);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c;
  int kekka = 3;
  cin >> a >> b >> c;
  if(a == b) kekka--;
  if(a == c) kekka--;
  else if(b==c) kekka--;
  cout << kekka << endl; 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std; const int inf = numeric_limits<int>::max();
struct __io{__io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}} __io; // fast I/O
#ifdef LOCAL // setting up print debugging (yes lol)
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.x<<", "<<p.y<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
#endif

struct query {
    int l;
    int r;
    int i;
    int ans;
};

signed main() {
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<query> q(t);
    for (int i = 0; i < t; ++i) {
        cin >> q[i].l >> q[i].r;
        q[i].i = i;
        q[i].l--;
        q[i].r--;
    }

    int sqrtn = sqrt(n) + 1;
    sort(q.begin(), q.end(), [&sqrtn](query &a, query &b) {
        if (a.l / sqrtn != b.l / sqrtn) {
            return a.l / sqrtn < b.l / sqrtn;
        }
        return a.r < b.r;
    });

    vector<int> m(n+1);
    int l = 0;
    int r = -1;
    int cnt = 0;

    for (auto &q : q) {
        if (r < q.l || q.r < l) {
            print("!");
            m.assign(n+1, 0);
            cnt = 0;
            l = q.l;
            r = q.l - 1;
        }
        while (r < q.r) {
            r++;
            if (m[a[r]] == 0) cnt++;
            m[a[r]]++;
        }
        while (r > q.r) {
            m[a[r]]--;
            if (m[a[r]] == 0) cnt--;
            r--;
        }
        while (l < q.l) {
            m[a[l]]--;
            if (m[a[l]] == 0) cnt--;
            l++;
        }
        while (l > q.l) {
            l--;
            if (m[a[l]] == 0) cnt++;
            m[a[l]]++;
        }
        q.ans = cnt;
    }
    sort(q.begin(), q.end(), [](query &a, query &b) {return a.i < b.i;});

    for (auto &q : q) {
        cout << q.ans << '\n';
    }
}


Measured memory_bytes: 15484
import sys
input = sys.stdin.readline

def main():
    n, x = map(int, input().split())
    A = list(map(int, input().split()))
    
    if A[0] > x:
        yield A[0] - x
        A[0] = x

    for i in range(n-1):
        if A[i] + A[i+1] > x:
            yield A[i] + A[i+1] - x
            A[i+1] = x - A[i]

    
print(sum(main()))

Measured memory_bytes: 14072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  ll sum=1;
  for(ll i=2;i<=N;i++){//iの倍数
    ll count=0;
    for(ll j=2;j<=i;j++){//iが素数か判定
      if(i%j==0){
count++;
      }
    }
if(count==1){
    ll sum2=0;
for(ll j=2;j<=N;j++){//2からNにiの倍数はいくつあるか
  if(j%i==0){
    ll t=1;
    while(j%power(i,t)==0){
      t++;
    }
    
  sum2+=(t-1);
  }
}
   sum*=(sum2+1);
    sum%=mod;
}
  
}
cout<<sum<<endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)

	ls := make([]int, n)
	for i := range ls {
		fmt.Scan(&ls[i])
	}

	d := 0
	count := 1
	for _, l := range ls {
		d += l
		if d <= x {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;

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

	string w;
	if (A == B) {
		w = "Draw";
	}
	else if (B == 1) {
		w = "Bob";
	}
	else if (A == 1) {
		w = "Alice";
	}
	else if (A > B) {
		w = "Alice";
	}
	else if (A < B) {
		w = "Bob";
	}

	cout << w << endl;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int answer = C - (A - B);
  maxs(answer, 0);
  cout << answer << '\n';
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef double db;

#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n") 
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n+1) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_arr2(x,n,m) ____; cout<<#x<<":\n"; rep(i,0,n+1) rep(j,0,m+1) cout<<#x<<"["<<(i)<<"]["<<(j)<<"]= "<<x[i][j]<<((j==m)?"\n\n":"    ")
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

const int N=5e5+5;
int n,a[N],f[N],g[41][N],id[N],c[N],tot=0; bool v[N]; ll k;

inline int o(int x) { ++x; if (x>n) x=1; return x; } 

int G(int x,ll k) {
	per(i,0,41) if (k>>i&1) x=g[i][x];
	return x;
}

int main() {
//	file_put();
	
//	srand(time(0));
	scanf("%d%lld",&n,&k);
	rep(i,1,n+1) scanf("%d",&a[i]),a[i+n]=a[i];
//	rep(i,1,n+1) a[i]=rand(),a[i+n]=a[i];
	per(i,n+1,2*n+1) id[a[i]]=i-n;
	per(i,1,n+1) {
		if (id[a[i]]<=i) f[i]=id[a[i]]+1; else
			if (o(id[a[i]])==1) f[i]=1; else f[i]=f[o(id[a[i]])];
		id[a[i]]=i;
	}
	f[n+1]=1;
	rep(i,1,n+2) g[0][i]=f[i];
	rep(i,1,41) rep(j,1,n+2) g[i][j]=g[i-1][g[i-1][j]];
	int p=G(1,k-1);
	rep(i,p,n+1) {
		if (!v[a[i]]) v[a[i]]=1,c[++tot]=a[i];
		else while (tot && v[a[i]]) v[c[tot--]]=0;
	}
	rep(i,1,tot+1) printf("%d%c",c[i]," \n"[i==tot]);
	
//	memset(v,0,sizeof(v)),tot=0;
//	rep(p,1,k+1) rep(i,1,n+1) {
//		if (!v[a[i]]) v[a[i]]=1,c[++tot]=a[i];
//		else while (tot && v[a[i]]) v[c[tot--]]=0;
//	} 
//	rep(i,1,tot+1) printf("%d%c",c[i]," \n"[i==tot]);
//	
//	debug_arr(a,n);
//	debug_arr(f,n+1);
//	debug_arr2(g,10,n+1);
//	debug(p);
	
	
	return 0;
}



Measured memory_bytes: 88448
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include<unordered_map>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#include <complex>
#define ll long long
#define  point complex<double>
#define  pi acos(-1)
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define arr2dof vector  vector<vector<int>>dp(N,vector<int>(2, inf));
using namespace std;
const ll N = 2e5 + 5, mod = 1e9 + 7, inff = -1e12,inf=1e9+7;
const double ep = 0.0000000001;
//const double pi = 3.14159265359;

double dot(point a, point b) {
	return  (conj(a)*b).real();
}
double cross(point a, point b) {
	return  (conj(a)*b).imag();
}
double angle(point a, point b)
{
	double dt = dot(a, b);
	dt /= abs(a);
	dt /= abs(b);
	return acos(dt) * 180.0 / pi;
}

bool isrightangel(int ind) {//90 degree
	vector<point>v;
	return(angle(v[ind] - v[(ind + 1) % 3], v[ind] - v[(ind + 2) % 3]) == 90);//bshof hal eldot producty3ny fe
	//dl3en 3moden 3ashn yb2a right trinagle
}

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
	if (exp == 0)
		return 1;
	ll ans = fp(base, exp / 2);
	ans = (ans * ans) % mod;
	if (exp % 2 != 0)
		ans = (ans * (base % mod)) % mod;
	return ans;
}

void calcFacAndInv(ll n)
{
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = (i * fact[i - 1]) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
	return (fact[n] * inv[n - r]) % mod;
}
	



char arr[1005][1005];
int dp[1005][1005];
int h, w;


int main()
{
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		for (int l = 0; l < w; ++l) {
			cin >> arr[i][l];
		}
	}
	dp[0][0] = 1;
	for (int i = 0; i < h; ++i) {
		for (int l = 0; l < w; ++l) {
			if (i == 0 && l == 0)
				continue;
			else if (arr[i][l] == '#')
				dp[i][l] = 0;
			else {
				if (i - 1 >= 0)
					dp[i][l] = dp[i - 1][l] ;
				else
					dp[i][l] = 0;
				if (l- 1 >= 0)
					dp[i][l] += dp[i][l-1] ;
				dp[i][l] %= mod;
					
			}
		}
	}
	cout << dp[h - 1][w - 1];
	return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int arr[200005];
int main()

{

    int n;
   map<int,int>v;
    cin >> n;
    for(int i =0;i<n;i++)
    {
        cin >> arr[i];

        v.insert(make_pair(i+1,arr[i]));
    }
    if(n%2==0){
            for(int i =n;i>=2;i-=2)
            {

                cout << v[i] <<" ";
            }
            for(int i =1;i<n;i+=2)
            {

                cout << v[i] << " ";
            }

    }
    else
    {

         for(int i =n;i>=1;i-=2)
            {

                cout << v[i] << " ";
            }
          for(int i =2;i<=n;i+=2)
            {

                cout << v[i] <<" ";
            }


    }

    cout << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

int main() {
  int N; cin >> N;
  ll d[N][N] = {};
  string S[N]; rep(i,N) cin >> S[i];
  rep(i,N) {
    rep(j,N) d[i][j] = S[i][j]=='1' ? 1 : INF;
    d[i][i] = 0;
  }
  rep(k,N) rep(i,N) rep(j,N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
  // rep(i,N) debug(d[i],d[i]+N);

  ll result = 0;
  bool ok = true;
  rep(i,N) rep(j,N) if (S[i][j]=='1'&&abs(d[0][i]-d[0][j])!=1) ok = false;
  if (!ok) result = -1;
  else rep(i,N) rep(j,N) result = max(result, d[i][j]+1);
  cout << result << endl;
  return 0;
}

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

using namespace std;

int n;

char ci(char c){
    if(c == 'R') return 'B';
    return 'R';
}

char ask(vector<int> q){
    cout << '?';
    for(int i = 0;i < n;i++) cout << ' ' << q[i];
    cout << endl;
    string r;
    cin >> r;
    return r[0];
}

void solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> a(n),b(n);
    for(i = 0;i < n;i++){
        a[i] = 1+i;
        b[i] = n+1+i;
    }
    char s = ask(a),c;
    int l = 0,r = n,m;
    while(r-l > 1){
        m = (l+r)/2;
        for(int i = m;i < r;i++){
            swap(a[i],b[i]);
        }
        c = ask(a);
        if(c != s){
            l = m;
            s = c;
        }
        else{
            r = m;
        }
    }
    vector<char> ans(2*n+1);
    ans[a[l]] = s;
    ans[b[l]] = ci(s);
    for(int i = 0;i < n;i++){
        if(i == l) continue;
        swap(a[i],b[l]);
        if(ask(a) == s) ans[b[l]] = ci(s);
        else ans[b[l]] = s;
        swap(a[i],b[l]);
        swap(b[i],a[l]);
        if(ask(a) == s) ans[a[l]] = s;
        else ans[a[l]] = ci(s);
        swap(b[i],a[l]);
    }
    cout << "! ";
    for(i = 0;i < 2*n;i++) cout << ans[i+1];
    cout << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 724
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;
} 

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

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.14159265358979323846264338327950288419

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

int n, s[200005];
bool bin[200005];

bool good(int mid){
	FI(i, 1, n * 2 - 1){
		if(s[i] >= mid) bin[i] = 1;
		else bin[i] = 0;
	}
	//merge 0-1 array using "median" operator N - 1 times
	if(bin[n] == bin[n - 1] || bin[n] == bin[n + 1]) return bin[n];
	FI(i, 1, n - 2){
		if(bin[n - i] == bin[n - i + 1]) return bin[n - i];
		if(bin[n + i] == bin[n + i + 1]) return bin[n + i];
	}
	return bin[1];
}

int main(){
	scanf("%d", &n);
	FI(i, 1, n * 2 - 1) scanf("%d", &s[i]);
	int l = 1, r = n * 2 - 1;
	while(r - l > 1){
		int m = (l + r) >> 1;
		if(good(m)) l = m;
		else r = m;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 1280
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    s=input()
    s=list(s)
    temp=0
    ans="Yes"
    for i in range(len(s)):
        if s[i]=="h" and temp==0:
            temp=1
        elif s[i]=="i" and temp==1:
            temp=0
        else:
            ans="No"
            break
    if len(s)%2!=0:
        ans="No"
    print(ans)


if __name__ == "__main__":
    main()

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

ll N;
ll ans = 0;
void saiki(ll cur, int use)
{
    if (cur > N)
        return;
    if (use == 0b111)
        ans++;

    saiki(cur * 10 + 7, use | 0b001);
    saiki(cur * 10 + 5, use | 0b010);
    saiki(cur * 10 + 3, use | 0b100);
}
int main()
{
    cin >> N;
    saiki(0, 0b000);
    cout << ans << endl;
}

Measured memory_bytes: 256
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;

ll res;
ll a[N];
ll dp[N];

void solve(){
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 2; i <= n; ++i){
        dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
        if(i > 2)   dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout << dp[n];
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	int s = 0;
	char c;
	while (cin >> c)
		s = (s + c - '0') % 9;
	cout << (s ? "No" : "Yes") << endl;

	return 0;
}


Measured memory_bytes: 3640
/*
Rathin Bhargava
IIIT Bangalore

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  ll n,x;
  cin >> n >> x;

  ll cnt = n;
  n = n-x;
  if(n<x) swap(n,x);

  while(n%x)
  {
    // t(n,x);
    cnt += (n-n%x)*2;
    n = n%x;
    swap(n,x);
  }
  cnt += (2*(n/x)-1)*x;

  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=8e5+50,P=924844033;

int head[N],etop;
struct Edge
{
	int v,nxt;
}e[N<<1];
void add(int u,int v)
{
	e[++etop].v=v;
	e[etop].nxt=head[u];
	head[u]=etop;
}

int power(int x,int k)
{
	int ret=1;
	for (;k;k>>=1,x=1LL*x*x%P)
		if (k&1) ret=1LL*ret*x%P;
	return ret;
}
namespace NTT
{
	const int G=5;
	
	int n,r[N],a[N],b[N];
	void init(int m)
	{
		for (n=1;n<m;n<<=1) ;
		for (int i=0;i<n;i++)
			r[i]=(r[i>>1]>>1) | (i&1 ? n>>1 : 0);
	}
	void NTT(int *f,int sgn)
	{
		for (int i=0;i<n;i++)
			if (r[i]>i) swap(f[r[i]],f[i]);
		for (int len,siz=2;siz<=n;siz<<=1)
		{
			len=siz>>1;
			int w=power(G,(P-1)/siz);
			if (sgn==-1) w=power(w,P-2);
			for (int l=0;l<n;l+=siz)
	        {
	            int buf=1;
	            for (int i=l;i<l+len;i++)
	            {
	                int t=1LL*buf*f[i+len]%P;
	                f[i+len]=(f[i]-t)%P;
	                f[i]=(f[i]+t)%P;
	                buf=1LL*buf*w%P;
	            }
	        }
		}
		if (sgn==-1)
	    {
	        int inv=power(n,P-2);
	        for (int i=0;i<n;i++)
	            f[i]=1LL*f[i]*inv%P;
	    }
	    for (int i=0;i<n;i++)
	    	f[i]=(f[i]+P)%P;
	}
	void mul(int la,int *ta,int lb,int *tb,int *res)
	{
		init(la+lb-1);
		for (int i=0;i<la;i++)
			a[i]=ta[i];
		for (int i=0;i<lb;i++)
			b[i]=tb[i];
		NTT(a,1); NTT(b,1);
		for (int i=0;i<n;i++)
			a[i]=1LL*a[i]*b[i]%P;
		NTT(a,-1);
		for (int i=0;i<la+lb-1;i++)
			res[i]=a[i];
	}
}

int n,fac[N],ifac[N],siz[N],a[N];
int g[N],h[N],ans[N];
void dfs(int u,int fa)
{
	siz[u]=1;
	for (int v,i=head[u];i;i=e[i].nxt)
	{
		v=e[i].v;
		if (v==fa) continue;
		dfs(v,u);
		siz[u]+=siz[v];
		--a[siz[v]];
	}
	a[n]++;
	a[n-siz[u]]--;
}
void init()
{
	fac[0]=1;
	for (int i=1;i<=n;i++)
		fac[i]=1LL*fac[i-1]*i%P;
	ifac[n]=power(fac[n],P-2);
	for (int i=n-1;i>=0;i--)
		ifac[i]=1LL*ifac[i+1]*(i+1)%P;
}
int main()
{
	scanf("%d",&n);
	init();
	for (int u,v,i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		add(u,v); add(v,u);
	}
	dfs(1,0);
	for (int i=0;i<n;i++)
	{
		g[i]=ifac[i];
		h[i]=1LL*fac[n-i]*a[n-i]%P;
	}
	NTT::mul(n,g,n,h,ans);
	for (int i=1;i<=n;i++)
		printf("%d\n",1LL*ans[n-i]*ifac[i]%P);
	return 0;
}

Measured memory_bytes: 42368
#include <ctype.h>
#include <stdio.h>
#include <string.h>
static char w[11], t[1001];
static int sum;
void fn(void) {
    int i;
    for (i = 0; t[i]; ++i) t[i] = tolower(t[i]);
}
int main(void) {
    scanf("%s", w);
    while (1) {
        scanf("%s", t);
        if (!strcmp(t, "END_OF_TEXT")) break;
        fn();
        if (!strcmp(t, w)) ++sum;
    }
    printf("%d\n", sum);
    return 0;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M)  //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) {           //bit計算
    if (x == 0) return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) {   //素数判定
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}


int all[51], p[51];

int ans(int N, int X) {
    if (N == 0)
        return ((X <= 0) ? 0 : 1);
    else if (X <= 1 + all[N - 1])
        return ans(N - 1, X - 1);
    else
        return p[N - 1] + 1 + ans(N - 1, X - 2 - all[N - 1]);

}

signed main() {
    int N, X;
    cin >> N >> X;
    all[0] = 1;
    p[0] = 1;
    for (int i = 1; i <= 50; i++) {
        p[i] = p[i - 1] * 2 + 1;
        all[i] = all[i - 1] * 2 + 3;
    }
    cout << ans(N, X) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 300;
const ll INF = 1LL<<50;
bool tag[MAXN + 5];
int f[MAXN + 5][MAXN + 5];
ll G[MAXN + 5][MAXN + 5];
int N, M; ll L;
int main() {
	scanf("%d%d%lld", &N, &M, &L);
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			G[i][j] = (i == j) ? 0 : INF;
	for(int i=1;i<=M;i++) {
		int A, B; scanf("%d%d", &A, &B);
		ll C; scanf("%lld", &C);
		G[A][B] = G[B][A] = C;
	}
	for(int k=1;k<=N;k++)
		for(int i=1;i<=N;i++)
			for(int j=1;j<=N;j++)
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	for(int i=1;i<=N;i++) {
		for(int j=1;j<=N;j++) f[i][j] = -1;
		queue<int>que; que.push(i);
		while( !que.empty() ) {
			int t = que.front(); que.pop();
			for(int k=1;k<=N;k++) {
				if( k != i && f[i][k] == -1 && G[t][k] <= L ) {
					f[i][k] = f[i][t] + 1;
					que.push(k);
				}
			}
		}
	}
	int Q; scanf("%d", &Q);
	for(int i=1;i<=Q;i++) {
		int s, t; scanf("%d%d", &s, &t);
		printf("%d\n", f[s][t]);
	}
}

Measured memory_bytes: 1664
h, w = map(int, input().split())
s = [[j for j in input().split()] for i in range(h)]
# print(s)
for i in range(h):
    for j in range(w):
        if s[i][j] == "snuke":
            ans = chr(ord("A") + j) + str(i + 1)
            print(ans)

Measured memory_bytes: 62216
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
    unsigned long long n,u;
    cin>>n;
    set<unsigned long long> s;
    for(int i=0;i<n;i++){
            cin>>u;
    s.insert(u);

    }
    if(s.size()==n)cout<<"YES";
    else cout<<"NO";



    return 0;


}


Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int table[101][101];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r, c, x;
    cin>>r>>c;
    for(int i=0; i<r; i++) {
        for(int j=0; j<c; j++) {
            cin>>x;
            table[i][j]=x;
            table[i][c]+=x;
            table[r][j]+=x;
            table[r][c]+=x;
        }
    }
    for(int i=0; i<=r; i++) {
        cout<<table[i][0];
        for(int j=1; j<=c; j++) {
            cout<<' '<<table[i][j];
        }
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1244
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int p = scanner.nextInt();
            max = Math.max(max, p);
            sum += p;
        }
        System.out.println(sum - max / 2);
    }
}

Measured memory_bytes: 21716