akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

class Main {

    void solve(){

	Scanner sc = new Scanner(System.in);
	
	while ( true ) {

	    int n = sc.nextInt();
	    if ( n == 0 ) break;

	    ArrayList<Integer> b = new ArrayList<Integer>();
	    for ( int i=0; i<n; ++i ) {
		int v = sc.nextInt();
		b.add( v );
	    }

	    int cnt = 0;
	    while ( cnt <= 10000 ) {

		//三角形になっているか
		boolean tri_num = true;
		if ( b.get(0) != 1 ) tri_num = false;
		for ( int i=1; i<b.size(); ++i ) {
		    if ( b.get(i) != b.get(i-1)+1 ) {
			tri_num = false;
			break;
		    }
		}
		if ( tri_num ) break;

		ArrayList<Integer> b_tmp = new ArrayList<Integer>();
		for ( int i : b ) {
		    if ( i > 1 ) b_tmp.add( i-1 );
		}
		b_tmp.add( b.size() );
		b = b_tmp;

		++cnt;
	    }
	    
	    if ( cnt > 10000 ) System.out.println(-1);
	    else System.out.println( cnt );
	    

	}

    }

    public static void main(String[] a) { new Main().solve(); }
}



Measured memory_bytes: 437944
n=int(input())
r=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(n)]
r=sorted(r,key=lambda x:x[0]*2*n+x[1])
b=sorted(b,key=lambda x:x[0]*2*n-x[1])
cnt=0
i=0
while i!=n:
    t=[0,0]
    for x,y in r:
        if x<b[i][0] and y<b[i][1] and t[1]<=y:
            t=[x,y]
    if t in r:
        r.remove(t)
        cnt+=1
    i+=1
print(cnt)

Measured memory_bytes: 3064
import math
a,b,x = list(map(int, input().split()))

x = x / a

if a*b == x:
  print(0)
elif x > a*b / 2:
  print(90 - math.degrees(math.atan(a*a/2/(a*b - x))))
else:
  print(90 - math.degrees(math.atan(2*x/b/b)))
  
  

Measured memory_bytes: 3060
A, B = map( int, input().split())
S = input()
ans = 'Yes'
R = [str(i) for i in range(10)]
for i in range(A):
    if S[i] in R:
        pass
    else:
        ans = 'No'
if S[A] == '-':
    pass
else:
    ans = 'No'
for i in range(B):
    if S[A+1+i] in R:
        pass
    else:
        ans = 'No'
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
const ll INF=1000000000000000;

struct edge{ll from,to,cost;};//?から?まで?コスト
edge es[2000];//辺

vector<ll> d(1001,0);//最短距離

ll N,E;//頂点数、辺数

bool find_negative_loop(){
    rep(i,N*2){
        rep(j,E){
            edge e=es[j];
            if(d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;

                //n回目にも更新があるなら負の閉路が存在
                if(i>=N && e.to==N) return true;
            }
        }
    }
    return false;
}

void shortest_path(ll s){ //s番目の頂点からの各点の最短距離を出す
    rep(i,N+1) d[i]=INF;
    d[s]=0;
    rep(i,N*2){
        bool update=false;
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
            }
        }
        if(!update) break;
    }
}

int main(){
	cin>>N>>E;//辺数
    //Vコの辺の情報入力
    rep(i,E){
        ll from,to,cost; cin>>from>>to>>cost;
        es[i].from=from;
        es[i].to=to;
        es[i].cost=cost*(-1);
    }

    bool loop=find_negative_loop();
    if(loop) cout<<"inf";
    else{
        shortest_path(1);
        cout<<d[N]*(-1);
    }
}

Measured memory_bytes: 256
#include<algorithm>
#include<chrono>
#include<climits>
#include<numeric>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<vector>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
using namespace std;
 
#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define print(v) {for(auto x : v) cout << x << ' '; cout << endl;}
#define printn(v, n) {for(int _i = 0; _i < n; _i++) cout << *(v + _i) << ' '; cout << endl;}
 
typedef unsigned long long ull;
typedef long long ll;
 
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
 
const int MAXN = 1e5 + 20;



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


    string s, t;
    cin >> s >> t;
    int res = 0;
    for(int i = 0; i < 3; i++)
    	res += (s[i] == t[i]);
    cout << res << endl;
    return 0;
}











Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
void func(int,int);
int n,m,a[9][8],cnt[9],sum,flg[9];
int main(void)
{
	int i,j,x,y;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++)	cnt[i]=0;
	for(i=0;i<m;i++)	{
		scanf("%d %d",&x,&y);
		a[x][cnt[x]]=y;
		cnt[x]++;
		a[y][cnt[y]]=x;
		cnt[y]++;
	}
	sum=0;
	for(i=1;i<=n;i++)	flg[i]=0;
	flg[1]=1;
	func(1,1);
	printf("%d\n",sum);
	return 0;
}
void func(int xx,int nn)
{
	int i,x2;
//	printf("xx=%d nn=%d\n",xx,nn);
	if(nn==n)	{
		sum++;
	}
	else {
		for(i=0;i<cnt[xx];i++)	{
			x2=a[xx][i];
			if(flg[x2]==0)	{
				flg[x2]=1;
				func(x2,nn+1);
				flg[x2]=0;
			}
		}
	}
}

Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
s = []
H.times do
  s << gets.chomp
end

s2 = Array.new(H, '')
H.times do |i|
  W.times do |j|
    if s[i][j] == '#'
      s2[i] += '#'
      next
    end

    c = 0

    if i > 0 && j > 0 && s[i - 1][j - 1] == '#'
      c += 1
    end
    if i > 0 && s[i - 1][j] == '#'
      c += 1
    end
    if i > 0 && j < W - 1 && s[i - 1][j + 1] == '#'
      c += 1
    end
    if j > 0 && s[i][j - 1] == '#'
      c += 1
    end
    if j < W - 1 && s[i][j + 1] == '#'
      c += 1
    end
    if i < H - 1 && j > 0 && s[i + 1][j - 1] == '#'
      c += 1
    end
    if i < H - 1 && s[i + 1][j] == '#'
      c += 1
    end
    if i < H - 1 && j < W - 1 && s[i + 1][j + 1] == '#'
      c += 1
    end

    s2[i] += c.to_s
  end
end

puts s2

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <map>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct A{
	bool a[256];
	A(){
		for(int i = 0; i < 256; i++) a[i] = false;
	}
	A(llint x){
		for(int i = 0; i < 256; i++) a[i] = false;
		a[x] = true;
	}
};

llint m, n;
map<string, P> mp;
stack<A> stk;

A add(A a, A b)
{
	A ret;
	for(int i = 0; i < 256; i++){
		for(int j = 0; j < 256; j++){
			if(a.a[i] && b.a[j]) ret.a[(i+j)%256] = true;
		}
	}
	return ret;
}
A sub(A a, A b)
{
	A ret;
	for(int i = 0; i < 256; i++){
		for(int j = 0; j < 256; j++){
			if(a.a[i] && b.a[j]) ret.a[(i-j+256)%256] = true;
		}
	}
	return ret;
}
A mul(A a, A b)
{
	A ret;
	for(int i = 0; i < 256; i++){
		for(int j = 0; j < 256; j++){
			if(a.a[i] && b.a[j]) ret.a[(i*j)%256] = true;
		}
	}
	return ret;
}
A divi(A a, A b)
{
	A ret;
	for(int i = 0; i < 256; i++){
		for(int j = 0; j < 256; j++){
			if(a.a[i] && b.a[j]) ret.a[(i/j)%256] = true;
		}
	}
	return ret;
}

int main(void)
{
	cin >> m;
	llint lb, ub; string s;
	for(int i = 1; i <= m; i++){
		cin >> s >> lb >> ub;
		mp[s] = P(lb, ub);
	}
	
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> s;
		//cout << s << endl;
		if(s == "+"){
			A b = stk.top(); stk.pop();
			A a = stk.top(); stk.pop();
			stk.push(add(a, b));
		}
		else if(s == "-"){
			A b = stk.top(); stk.pop();
			A a = stk.top(); stk.pop();
			stk.push(sub(a, b));
		}
		else if(s == "*"){
			A b = stk.top(); stk.pop();
			A a = stk.top(); stk.pop();
			stk.push(mul(a, b));
		}
		else if(s == "/"){
			A b = stk.top(); stk.pop();
			A a = stk.top(); stk.pop();
			if(b.a[0]){
				cout << "error" << endl;
				return 0;
			}
			stk.push(divi(a, b));
		}
		else if(s[0] >= '0' && s[0] <= '9'){
			llint x = atoi(s.c_str());
			stk.push(A(x % 256));
		}
		else{
			llint lb = mp[s].first, ub = mp[s].second;
			A a;
			for(int j = lb; j <= ub; j++) a.a[j] = true;
			stk.push(a);
		}
	}
	cout << "correct" << endl;
	
	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <queue>
using namespace std;
static const int N=100,INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  for (int i=0; i<n; i++) {
    d[i]=INFTY;
  }
  d[s]=0;
  int u;
  while (!q.empty()) {
    u=q.front();
    q.pop();
    for (int v=0; v<n; v++) {
      if (M[u][v]==0) {
        continue;
      }
      if (d[v]!=INFTY) {
        continue;
      }
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for (int i=0; i<n; i++) {
    cout<<i+1<<" "<<((d[i]==INFTY)?(-1):d[i])<<endl;
  }
}
int main() {
  int u,v,k,i,j;
  cin>>n;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      M[i][j]=0;
    }
  }
  for (i=0; i<n; i++) {
    cin>>u>>k;
    u--;
    for (j=0; j<k; j++) {
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  bfs(0);
  return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,ans;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	ans=0;
	if(d<=a && d<=b && d<=c){
		ans=a+b+c;
	}
	else if(c<=a && c<=b && c<=d){
		ans=a+b+d;
	}
	else if(b<=a && b<=c && b<=d){
		ans=a+c+d;
	}
	else{
		ans=b+c+d;
	}
	if(f<=e){
		printf("%d\n",ans+e);
	}
	else{
		printf("%d\n",ans+f);
	}
	return 0;
}


Measured memory_bytes: 2080
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[n-1]
dp=[0]*(m+1)
ans=0
for i in a:
  for j in range(i,m+1,i):
    dp[j]+=1
for i in a:
  if dp[i]==1:
    ans+=1
print(ans)

Measured memory_bytes: 32232
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int x,a;
    cin>>x>>a;
    if(x < a){
        cout<<0<<"\n";
    }else{
        cout<<10<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	words := make([]int, 3)
	fmt.Scan(&words[0], &words[1], &words[2])

	answer := "No"
	if words[0] == words[1] && words[0] != words[2] {
		answer = "Yes"
	} else if words[0] == words[2] && words[0] != words[1] {
		answer = "Yes"
	} else if words[1] == words[2] && words[0] != words[1] {
		answer = "Yes"
	}

	fmt.Println(answer)
}


Measured memory_bytes: 512
/*  3_4
    Y_Aizaki    */

#include <stdio.h>

int main(void){
    int n;
    scanf("%d", &n);
    // nが1~9の二つの整数の積かどうかを判定する

    int i = 1;
    while(i < 10){
        if(n % i == 0 && n / i < 10){
            printf("Yes\n");
            break;
        }
        i += 1;
    }

    if(i == 10){
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int graph[101][101], d[101], f[101], n, color[101], timee;

void visit(int u) {
    int i;
    color[u] = 0;
    d[u] = ++timee;
    for (i = 1; i <= n; i++) {
        if (graph[u][i] == 1) {
            if (color[i] == 1) visit(i);
        }
    }
    color[u] = -1;
    f[u] = ++timee;
}

void dfs() {
    int i;
    for (i = 1; i <= n; i++) color[i] = 1;
    timee = 0;
    for (i = 1; i <= n; i++) {
        if (color[i] == 1) visit(i);
    }
}

int main(void){
    int dd, i, a, j, n2;
    scanf("%d", &n);
    
    for (i = 1; i <= 100; i++) {
        for (j = 1; j <= 100; j++) {
            graph[i][j] = 0;
        }
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d %d", &dd, &n2);
        for (j = 0; j < n2; j++) {
            scanf("%d", &a);
            graph[dd][a] = 1;
        }
    }
    
    dfs();
    
    for (i = 1; i <= n; i++) {
        printf("%d %d %d\n", i, d[i], f[i]);
    }
    
    return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int H,W;cin>>H>>W;
    char A[H][W];
    REP(i,H){
        REP(j,W)cin>>A[i][j];
    }
    REP(i,H){
        REP(j,W){
            cout<<A[i][j];
        }
        cout<<endl;
        REP(j,W){
            cout<<A[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll A, B, N;
    cin >> N >> A >> B;
    cout << max((ll)0, ((N - 1) * B + A) - ((N - 1) * A + B) + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  
  for(int i = 0 ; i < N ; i++){
   cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      break;
    }
    
    if(N-1 == i)
      cout << "Three" <<endl;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scanln(&n)

	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, n-1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}
	for i := 0; i < n-1; i++ {
		fmt.Scan(&c[i])
	}

	fmt.Println(logic(a, b, c))
}

func logic(a, b, c []int) int {
	before := -2
	count := 0
	for _, v := range a {
		i := v - 1
		count += b[i]

		if i-before == 1 {
			count += c[before]
		}

		before = i
	}
	return count
}

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

int main(){
  int n;
  int b=1;
  int count = 0;
  bool ans=false;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    count++;
    b=a[b-1];
    if(b==2){
      ans=true;
      break;
    }
  }
  if(ans){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using std::cin;
using std::cout;
typedef long long ll;
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
struct str
{
	int cnt, *addr;
	bool operator<(str A) const { return cnt < A.cnt; }
} d[Maxn];
int Disc(int t)
{
	rg int tmp = 0;
	std::sort(d + 1, d + t + 1);
	for (int i = 1; i <= t; i++)
	{
		if (i == 1 || d[i].cnt != d[i - 1].cnt)
			d[++tmp] = d[i];
		*d[i].addr = tmp;
	}
	return tmp;
}
int n, k, ans;
int main()
{
	rg int a;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		ans += read() >= k;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#%%
n = int(input())
a = list(map(int ,input().split()))

a.sort(reverse=True)
ans = []
for i in range(n):
    if i == 0:
        tmp = a[i]
    elif 1 <= i < n - 1:
        if a[i] > 0:
            ans.append(str(a[-1]) + ' ' +  str(a[i]))
            a[-1] -= a[i]
        else:
            ans.append(str(tmp) + ' ' +  str(a[i]))
            tmp -= a[i]
    else:
        ans.append(str(tmp) + ' ' +  str(a[-1]))
        a = tmp - a[-1]
        print(a)

for i in range(len(ans)):
    x, y = map(int, ans[i].split())
    print(x, y)


Measured memory_bytes: 14884
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { //WOOOOOOOO!
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		boolean[] diff = new boolean[N]; //N not possible as max gap = N-1; N/2 is bad for even
		boolean[] used = new boolean[N+1];
		int bad = -1;
		if (N%2==0) bad=N/2;
		System.out.println(1+" "+N);
		diff[1]=true;
		diff[N-1]=true;
		used[1]=true;
		used[N]=true;
		M--;
		int START = 2;
		while (M>0) {
			for (int d = N-1; d>=1; d--) {
				int diff1 = d;
				int diff2 = N-d;
				int END = START+diff1;
				if (!diff[diff1]&&!diff[diff2]&&!used[END]&&diff1!=bad) {
					System.out.println(START+" "+END);
					diff[diff1]=true;
					diff[diff2]=true;
					used[END]=true;
					START++;
					M--;
					if (M==0) break;
				}
			}
		}
	}	
}

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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7

int main() {
    string ss;
    cin >> ss;
    int s[100002];
    int g[100002];

    // R = 0   L = 1

    int n = (int)ss.length();
    for(int i=0; i<n;i++){
        if(ss[i]=='R') s[i] = 0;
        else s[i] = 1;
        g[i]=0;
    }
    vector<int> c;
    c.push_back(-1);
    for(int i=0; i<n-1;i++){
        if(s[i]==0){
            if(s[i+1]==1){
                c.push_back(i);
            }
        }
    }
    c.push_back(n+1);

    for(int i=0; i<n;i++){
        int x,y;

        int left = 0, right = (int)c.size();
        
            int mid = (right+left)/2;
            if(c[mid] >= i){
                mid=0;
            }

        for(int j=mid; j<(int)c.size()-1; j++){
            if(c[j]<=i&&i<=c[j+1]){
                x = c[j];
                y = c[j+1];
                break;
            }
        }
        if(s[i]==0) x = y;
        int dis = abs(i-x);
        if(dis%2==0) g[x]++;
        else g[x+1]++;
    }

    for(int i=0; i<n;i++){
        cout << g[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1664
use std::io;
use std::collections::BTreeSet;
fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let n = input.trim().parse::<u32>().unwrap();

    let s_n = (0..n)
        .map(|_| {
            let mut input = String::new();
            io::stdin().read_line(&mut input);
            input
        })
        .collect::<Vec<_>>();
    let intersect = s_n.iter().fold(s_n[0].chars().collect::<BTreeSet<_>>(), |set, s| {
        let a = s.trim().chars().collect::<BTreeSet<_>>();
        set.intersection(&a).cloned().collect()
    });


    let mut nums = Vec::new();

    for c in intersect.iter() {
        let gr = s_n.iter()
            .map(|st| st.chars().collect::<Vec<_>>().iter().filter(|&k| c == k).count())
            .min()
            .unwrap();
        nums.push(gr);
    }

    let ans = intersect.iter().zip(nums.iter()).fold(String::from(""), |mut st, (&c, &n)| {
        for _ in 0..n {
            st.push(c);
        }
        st
    });

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(void)
{
	int i,x,j;
	char s[3];	
	scanf("%s",s);
	x=0;
	j=0;
	for(i=0;i<3;i++) {
		
		if(s[j]=='1') {
			x=x+1;
		}
		j=j+1;
	}
	printf("%d\n",x);
	return 0;
}
	
	

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		MDT = new int[16][16];
		for (int i = 0; i < 16; i++) {
			for (int j = 0; j < 16; j++) {
				MDT[i][j] = Math.abs(i / 4 - j / 4) + Math.abs(i % 4 - j % 4);
			}
		}
		int[] a = new int[16];
		int zero = -1;
		for (int i = 0; i < 16; i++) {
			a[i] = scanner.nextInt();
			if (a[i] == 0)
				zero = i;
		}
		int md = getMD(a);
		PriorityQueue<Puzzle> pq = new PriorityQueue<Puzzle>();
		Set<Puzzle> set = new HashSet<Puzzle>();
		pq.offer(new Puzzle(a, zero, md, 0));

		while (!pq.isEmpty()) {
			Puzzle p = pq.poll();
			if (p.md == 0) {
				System.out.println(p.cost);
				break;
			}
			int y = p.zero / 4;
			int x = p.zero % 4;
			for (int[] m : move) {
				int ny = y + m[0];
				int nx = x + m[1];
				if (ny < 0 || 4 <= ny || nx < 0 || 4 <= nx)
					continue;
				int[] tmpMap = Arrays.copyOf(p.map, 16);
				int nz = ny * 4 + nx;
				int nmd = p.md;
				nmd -= MDT[nz][p.map[nz] - 1];
				nmd += MDT[p.zero][p.map[nz] - 1];
				swap(tmpMap, p.zero, nz);
				Puzzle np = new Puzzle(tmpMap, nz, nmd, p.cost + 1);
				if (set.contains(np))
					continue;
				set.add(np);
				pq.offer(np);

			}
		}
	}

	private void swap(int[] tmpMap, int zero, int nz) {
		int tmp = tmpMap[zero];
		tmpMap[zero] = tmpMap[nz];
		tmpMap[nz] = tmp;
	}

	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

	private int getMD(int[] a) {
		int sum = 0;
		for (int i = 0; i < 16; i++) {
			if (a[i] == 0)
				continue;
			sum += MDT[i][a[i] - 1];
		}
		return sum;
	}

	int[][] MDT;

	class Puzzle implements Comparable<Puzzle> {
		int[] map;
		int zero;
		int md;
		int cost;
		int est;

		public Puzzle(int[] map, int zero, int md, int cost) {
			super();
			this.map = map;
			this.zero = zero;
			this.md = md;
			this.cost = cost;
			this.est = cost + md;
		}

		@Override
		public String toString() {
			return "Puzzle [map=" + Arrays.toString(map) + ", zero=" + zero
					+ ", md=" + md + ", cost=" + cost + ", est=" + est + "]";
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + Arrays.hashCode(map);
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Puzzle other = (Puzzle) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (!Arrays.equals(map, other.map))
				return false;
			return true;
		}

		@Override
		public int compareTo(Puzzle o) {
			if (this.est == o.est)
				return o.cost - this.cost;
			return this.est - o.est;

		}

		private Main getOuterType() {
			return Main.this;
		}

	}
}

Measured memory_bytes: 187260
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

string reverse(string input, int length);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string S;
	cin >> S;
	string revS = reverse(S, S.size());
	if(revS == S)
	{
		int a = (S.size()-1)/2-1;
		int b = (S.size()+3)/2-1;
		string s1 = S.substr(0, a+1);
		string s2 = S.substr(b, S.size()-b);
		if(s1 == reverse(s1, s1.size()) && s2 == reverse(s2, s2.size())) cout << "Yes";
		else cout << "No";
	}
	else
	{
		cout << "No";
	}
}

string reverse(string input, int length)
{
	string rev = input;
	for(int i=0; i<(length/2); i++)
	{
		char temp = rev[i];
		rev[i] = rev[length-i-1];
		rev[length-i-1] = temp;
	}
	return rev;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

int main(void){
  ll n,m;
  cin>>n>>m;

  if(n==1 && m==1){
    cout<<1<<endl;
    return 0;
  }
  if(n<=2 && m<=2){
    cout<<0<<endl;
    return 0;
  }
  if(n==1 || m==1){
    cout<<max(n,m)-2<<endl;
    return 0;
  }
  if(n==2 || m==2){
    cout<<0<<endl;
    return 0;
  }
  cout<<(n-2)*(m-2)<<endl;
  return 0;
}


Measured memory_bytes: 256
X = input()

S_cnt = 0
T_cnt = 0
for i in range(len(X)):
    if X[i] == 'S':
        S_cnt += 1
    else:
        if S_cnt > 0:
            S_cnt -= 1
        else:
            T_cnt += 1

print(S_cnt+T_cnt)


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

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

const int MAX { 1000010 };
const ll MOD { 1000000007 };
const double PI = acos(-1.0);

class UFDS {
public:
    vector<int> parents, rank;

    UFDS(int N) {
        rank.assign(N, 1);
        parents.assign(N, 0);
        for(int i = 0; i < N; ++i) parents[i] = i;
    }

    int findSet(int i) {
        if (parents[i] == i) return i;
        return parents[i] = findSet(parents[i]);
    }

    bool isSameSet(int i, int j) {
        return findSet(i) == findSet(j);
    }

    void unionSet(int i, int j) {
        if (!isSameSet(i, j)) {
            int x = findSet(i), y = findSet(j);
            if (rank[x] > rank[y]) swap(x, y);

            parents[x] = y;
            rank[y]+=rank[x];
        }
    }
};

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

    int N, M;
    cin >> N >> M;

    UFDS ufds(N);

    for(int i=0; i<M; ++i){
        int A, B;
        cin >> A >> B;
        A--; B--;
        ufds.unionSet(A, B);
    }

    int maior = -1;
    for(int i=0; i<N; ++i){
        maior < ufds.rank[i] ? maior = ufds.rank[i] : maior;
    }

    cout << maior << endl;

    return 0;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int challenge = S.size() -T.size();
  int mindeff = T.size();
  int ts = T.size();
  for(int i = 0;i < challenge+1;i++){
    int deff = 0;
    for(int j = 0; j < ts;j++){
      if(S.at(i+j) != T.at(j))deff++;
    }
    if(deff < mindeff)mindeff = deff;
  }
	cout << mindeff << endl;  
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int c1 = scan.nextInt();
        int c5 = scan.nextInt();
        int c10 = scan.nextInt();
        int c50 = scan.nextInt();
        int c100 = scan.nextInt();
        int c500 = scan.nextInt();
        if(c1 + (c5 * 5) + (c10 * 10) + (c50 * 50) + (c100 * 100) + (c500 * 500) >= 1000){
        System.out.println("1");
        }else{
    System.out.println("0");

    }

}
}



Measured memory_bytes: 26316
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,m,x,y,a[100009];
int par[100009];

int mark[100009],sz[100009];
multiset<LL> ms[100009];
multiset<pair<LL,int> >mg;
int findpar(int u)
{
    if(par[u]==u)return u;
    return par[u]=findpar(par[u]);
}

struct data
{
    int x;
};

bool operator <(data a, data b)
{
    return ms[a.x].size()>ms[b.x].size();
}

multiset<data>lst;

int main()
{
    scanf("%lld %lld",&n,&m);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    for(int i=0;i<n;i++)par[i]=i;
    //cout<<"a";
    while(m--)
    {
        scanf("%lld %lld",&x,&y);
        par[findpar(x)]=findpar(y);
    }
    for(int i=0;i<n;i++)
    {
       (ms[findpar(i)]).insert(a[i]);
    }
    for(int i=0;i<n;i++)if(findpar(i)==i){data d;d.x=i;lst.insert(d);}
    LL ans=0;
   // cout<<lst.size()<<endl;
    while(lst.size()>1)
    {
        int a=(*lst.begin()).x;
        lst.erase(lst.begin());
        int b=(*lst.begin()).x;
        lst.erase(lst.begin());
        //cout<<a<<" "<<ms[a].size()<<" "<<b<<" "<<ms[b].size()<<endl;
        if(ms[a].empty()||ms[b].empty())
        {
            cout<<"Impossible"<<endl;
            return 0;
        }
        ans+=(*ms[a].begin())+(*ms[b].begin());
        ms[a].erase(ms[a].begin());
        ms[b].erase(ms[b].begin());
        if(!ms[b].empty())
        {
            auto it=ms[b].begin();
            while(it!=ms[b].end())
            {
                ms[a].insert(*it);
                it++;
            }
        }
        data d;d.x=a;
        lst.insert(d);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 16256
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;

int main() {

    int N; cin>>N;
    set<ll> A;
    for (int i = 0; i < N; ++i) {
        ll a; cin>>a;
        if(!A.count(a)){
            A.insert(a);
        }else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep(x,to) for(int x = 0; x < (to); ++(x))
int main() {
	string s;
	while(cin >> s) {
		int a[128], b[128], c[128], la, lb, lc;
		rep(j,128) {
			a[j] = b[j] = c[j] = 0;
		}
		int i = 0;
		for(; s[i] != '+'; i++) {
			if(s[i] == 'X') a[i] = -1;
			else a[i] = s[i] - '0';
		}
		la = i;
		i++;

		for(; s[i] != '='; i++) {
			if(s[i] == 'X') b[i-la-1] = -1;
			else b[i-la-1] = s[i] - '0';
		}
		lb = i - la - 1;
		i++;

		for(; s[i] != '\0'; i++) {
			if(s[i] == 'X') c[i-la-lb-2] = -1;
			else c[i-la-lb-2] = s[i] - '0';
		}
		lc = i - la - lb - 2;
		
		if(la > lc || lb > lc) {
			cout << "NA" << endl;
			continue;
		}
		rep(j,lc) {
			if(j<la)a[lc-1-j] = a[la-1-j];
			else a[lc-1-j] = 0;
		}
		rep(j,lc) {
			if(j<lb)b[lc-1-j] = b[lb-1-j];
			else b[lc-1-j] = 0;
		}
		
		bool ret = 1;
		rep(i,10) {

			int na[128], nb[128], nc[128];
			if(i == 0 && lc > 1 && (a[lc-la] == -1 || b[lc-lb] == -1 || c[0] == -1)) continue;
			
			rep(j,lc) {
				if(a[j] == -1) na[j] = i;
				else na[j] = a[j];
				if(b[j] == -1) nb[j] = i;
				else nb[j] = b[j];
				if(c[j] == -1) nc[j] = i;
				else nc[j] = c[j];
			}
			
			bool f = 0;
			ret = 1;
			for(int j = lc-1; j >= 0; j--) {
				int x = na[j] + nb[j] + f;
				f = 0;
				if(x >= 10) f = 1, x -= 10;
				if(nc[j] != x) {
					ret = 0;
					break;
				}
			}
			if(f) ret = 0;
			if(ret) {
				cout << i << endl;
				break;
			}
		}
		if(!ret) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1188
#!/usr/bin/env perl

use strict;
use warnings;

my $XN = <STDIN>; chomp($XN);
my $PN = <STDIN>; chomp($PN);

my ( $X, $N ) = split qr(\s+), $XN;
my @nums = sort { $a <=> $b } split qr(\s+), $PN;

if ( $N == 0 ) {
  print $X, "\n";
  exit 0;
}

my %exists = map { $_ => 1 } @nums;

my $start = 101;
my $diff = abs($X - $start);
my $n = 101;

for ( my $x = $start; $x > -2; $x-- ) {
  if ( exists $exists{$x} ) {
    next;
  }

  if ( abs($X - $x) <= $diff ) {
    $diff = abs($X - $x);
    $n = $x;
  }
}

print $n, "\n";


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  string s; cin >> s;
  ll K; cin >> K;

  set<string> ss;
  rep(i, s.size()) {
    rep1(j, s.size()-i) {
      ss.insert(s.substr(i, j));
      //      cerr << s.substr(i, j) << " " ;
      if(ss.size() > 5) ss.erase(--ss.end());
    }
  }
  
  for(auto itr : ss) {
    K--;
    //    cerr << K <<  " " << itr << endl;
    if(K <=0) {
      cout  << itr << endl;
      break;
    }
  }
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3672
n = int(input())
B = [input() for _ in range(n)]
m = int(input())
R = [input() for _ in range(m)]
L = list(set(B) | set(R))
dict = {key:0 for key in L}
for b in B:
    dict[b] += 1
for r in R:
    dict[r] -=1
dict.update({"AAA":0})
print(max(dict.values()))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] S = new int[N];
		int[] T = new int[M];
		
		for(int i=0; i<N; i++)
			S[i] = sc.nextInt();
		for(int i=0; i<M; i++)
			T[i] = sc.nextInt();
		
		final long MOD = 1000000007;
		long[][] dp = new long[N+1][M+1];
		long[][] sum = new long[N+1][M+1];
		dp[0][0] = 1;
		sum[0][0] = 1;
		for(int i=0; i<N+1; i++) {
			for(int j=0; j<M+1; j++) {
				if(i>0 && j>0 && S[i-1]==T[j-1])
					dp[i][j] = sum[i-1][j-1];
				sum[i][j] = ((i>0 ? sum[i-1][j] : 0) + (j>0 ? sum[i][j-1] : 0) - (i>0 && j>0 ? sum[i-1][j-1] : 0) + dp[i][j] + MOD) % MOD;
			}
		}
		
		System.out.println(sum[N][M]);
		sc.close();
	}
}


Measured memory_bytes: 129732
#include <cstdio>
#include <string>
#include <cmath>
#include <iostream>
using namespace std;


int a[50];
int main(){
    long long N;
    scanf("%lld",&N);
    N++;
    int op = log2(N);
    int cnt = 0;
    while (N){
        a[op-cnt] = N&1;
        N>>=1;
        cnt ++;
    }
    //for (int i=0;i<=op;i++) printf("%d ",a[i]);

    string l = "";
    string r = "";
    cnt = 0;
    int len = 0;
    for (int i=1;i<=op;i++){
        string s = to_string(++cnt);
        l = l+" "+s;
        r = r+" "+s;
        len+=2;
        if (a[i]){
            string s = to_string(++cnt);
            l = s+" "+l;
            r = r+" "+s;
            len+=2;
        }



    }
    cout << len << endl;
    cout << l+" "+r << endl;
    return 0;
}



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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int N = 2e3 + 10;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

int n, m;
LL a[N];

bool check(int i, int j, int k)
{
    if (a[i] == a[j]) return false;
    if (a[i] == a[k]) return false;
    if (a[j] == a[k]) return false;

    vector<int> vec;
    vec.push_back(a[i]);
    vec.push_back(a[j]);
    vec.push_back(a[k]);
    sort(all(vec));
    if (vec[0] + vec[1] > vec[2]) return true;
    return false;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        for (int i = 1; i <= n; i++) cin >> a[i];
        if (n <= 2)
        {
            cout << 0 << endl;
            continue;
        }

        int ans = 0;

        for (int i = 1; i <= n; ++i)
        {
            for (int j = i + 1; j <= n; ++j)
            {
                for (int k = j + 1; k <= n; ++k)
                {
                    if (check(i, j, k))
                    {
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,x[200005],y[200005];
int mx1=0,mn1=INF,mx2=-INF,mn2=INF,mx3=-INF,mn3=INF;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	forn(i,n)
	{
		cin>>x[i]>>y[i];
		mx1=max(mx1,x[i]+y[i]);
		mn1=min(mn1,x[i]+y[i]);
		mx2=max(mx2,x[i]-y[i]);
		mn2=min(mn2,x[i]-y[i]);
		mx3=max(mx3,y[i]-x[i]);
		mn3=min(mn3,y[i]-x[i]);
	}
	cout<<max(max(mx1-mn1,mx2-mn2),mx3-mn3);
	return 0;
}


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

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  if(k <= a) cout << k << endl;
  
  if(k > a && k <= a+b) cout << a << endl;
  
  if(k > a+b) cout << a -(k-a-b) << endl; //-1をk-a-b枚とる
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    int n; cin>>n;
    int a[n+1];
    a[0]=0;
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i];
    }
    int dp[n+1]={};
    dp[1]=0; dp[2]=abs(a[2]-a[1]);
    for (int i = 3; i <= n; ++i)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
        // cout<<i<<" "<<dp[i]<<"\n";
    }
    cout<<dp[n];
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 5216
s1 = raw_input()
s2 = raw_input()
ans = ''
for i in range(min(len(s1), len(s2))):
    ans += s1[i] + s2[i]
if len(s2) < len(s1):
    ans += s1[-1]
if len(s1) < len(s2):
    ans += s2[-1]
print ans

Measured memory_bytes: 2568
#include<stdio.h>

int main() {
	int n;
	int a, b, c, d;
	int count=0;
	while (scanf("%d", &n) != EOF) {
		count = 0;
		for (a = 0;a < 10;a++) {
			for (b = 0;b < 10;b++) {
				for (c = 0;c < 10;c++) {
					d = n - a - b - c;
					if (0 <= d&&d < 10)
						count++;
				}
			}
		}
		printf("%d\n", count);
	}
}

Measured memory_bytes: 1648
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> Hs(N);
    rep(i,0,N) {
        cin >> Hs[i];
    }
    sort(Hs.begin(), Hs.end());
    if (K >= N) {
        cout << 0 << endl;
        return 0;
    }
    ll sum = 0;
    rep(i,0,N-K) {
        sum += Hs[i];
    }
    cout << sum << endl;
}



Measured memory_bytes: 2424
//ABC 175 C
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long int x,d,k,ans,fl,flfl,flflfl=0,fm;
    cin >> x >> k >>d;
    fl = 1;
    if(k % 2==0){
        fl = 0;
    }
    if(x < 0){
        x *= -1;
    }
    flfl=0;
    if(d >= x){
        flfl=1;
    }
  //cout << flfl<<endl;
    if(flfl==0){
        fm = x / d;
        if(fm % 2!=0){
            flflfl=1;
        }
      //cout << fm <<endl;
      if(fm <= k){
        if(fl == 0){
            if(flflfl==0){
                ans = x - fm*d;
            }else{
                ans = (fm+1)*d -x;
            }
        }else{
            if(flflfl==0){
                ans = (fm+1)*d -x;
            }else{
                ans = x - fm*d;
            }
        }
      }else{
        ans = x - k*d;
      }
    }else{
        if(fl == 0){
            ans = x;
        }else{
            if(x == d){
                ans = 0;
            }else{
                ans = d - x;
            }
        }
      //cout << "haha";
    }
    cout << ans;
 
}

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

// Optimization

// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 2e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e9 + 7;
const ll infll = 1e18 + 7;

int n, m, k;
int ans, cnt, tmp, idx, sum, mx = -infll, mn = infll;
int x, y, z;
string s, t;
int a[N], b[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, n){
        ForE(j, 1, n){
            ForE(k, 1, n){
                ans += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout << ans;
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/

Measured memory_bytes: 3656
a,b,c,x,y = map(int,input().split())

amax = x*a
bmax = y*b

ans = amax+bmax

for _ in range(max(x,y)):
    if x <= 0:
        ans = min(ans-b+2*c,ans)

    elif y <= 0:
        ans = min(ans-a+2*c,ans)

    else:
        ans = min(ans-a-b+2*c,ans)
        
    x-=1
    y-=1
 #   print(x,y,ans)

print(ans)

Measured memory_bytes: 3064
#n=int(input())
n,m=map(int,input().split())
hl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
dic={}
for i in range(n):
    dic[i+1]=True
for i in range(m):
    a,b=map(int,input().split())
    if hl[a-1]<=hl[b-1]:
        dic[a]=False
    if hl[b-1]<=hl[a-1]:
        dic[b]=False
ans=0
for k,v in dic.items():
    if v :
        ans+=1

print(ans)







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

int main(){
    ll N;
    ll ans = 1001001001001;
    cin >> N;
    for(ll i=1; i*i<=N; ++i){
        if(N%i==0){
            ans = min(ans, i+N/i);
        }
    }
    cout << ans-2 << endl;
}


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

a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

manzoku=0
for i in range(n):
    food = a[i]
    manzoku += b[food-1]
    if i!=0 and a[i-1]+1==a[i]:
        manzoku += c[a[i-1]-1]

print(manzoku)

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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    int n;
    cin >> n;
    int counter = 0;
    for(int i=1; i<=n; i++) {
        int l = log10(i);
        l++;
        if (l%2!=0) counter++;
    }
    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 512