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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		String s = sc.next();
		int min = Integer.MAX_VALUE;
		int num = 753, t;
		for (int i = 0; i < s.length() - 2; i++) {
			t = Integer.parseInt(s.substring(i, i + 3));
			min = Math.min(min, Math.abs(num - t));
		}
		System.out.println(min);
	}
}


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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int N;
        cin >>N;
        vector<ll> A(N+1, 0);
        vector<ll> B(N+1, 0);
        Rep1(i, N)
                cin >>A.at(i) >>B.at(i);
        Sort(A);
        Sort(B);
        if (1==N%2) {
                ll ST=A.at((N+1)/2);
                ll EN=B.at((N+1)/2);
                cout <<EN-ST+1 <<endl;
        } else {
                ll ST1=A.at(N/2);
                ll ST2=A.at(N/2+1);
                ll EN1=B.at(N/2);
                ll EN2=B.at(N/2+1);
                cout <<(EN1+EN2-ST1-ST2)+1 <<endl;
        }
        return 0;
}

Measured memory_bytes: 6440
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  x, y, na, nb, nc = map(int, input().split())
  la = list(map(int, input().split()))
  la.sort(reverse=True)
  lb = list(map(int, input().split()))
  lb.sort(reverse=True)
  lc = list(map(int, input().split()))
  lc.sort(reverse=True)
  ca, cb, cc = 0, 0, 0,
  
  s = 0
  while True:
    if sum([ca, cb, cc]) == x+y:
      break
      
    a = la[ca] if na > ca and ca < x else -1
    b = lb[cb] if nb > cb and cb < y else -1
    c = lc[cc] if nc > cc            else -1
            
    if a >= b and a >= c:
      s += a
      ca += 1
      continue
      
    if b >= a and b >= c:
      s += b
      cb += 1
      continue
      
    if c >= b and c >= a:
      s += c
      cc += 1
      
  print(s)

if __name__=='__main__':
  main()



Measured memory_bytes: 22720
def main():
    s = [input() for _ in range(3)]
    s[0] = s[0] + 'k'
    s[1] = s[1] + 'k'
    s[2] = s[2] + 'k'

    k = s[0][0]
    s[0] = s[0][1:]
    ans = ''
    while True:
        if len(s[0]) == 0:
            ans = 'A'
            break
        elif len(s[1]) == 0:
            ans = 'B'
            break
        elif len(s[2]) == 0:
            ans = 'C'
            break

        if k == 'a':
            k = s[0][0]
            s[0] = s[0][1:]
        elif k == 'b':
            k = s[1][0]
            s[1] = s[1][1:]
        elif k == 'c':
            k = s[2][0]
            s[2] = s[2][1:]

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
n,m = map(int, input().split())
s_and_c = []
for i in range(m):
    s_and_c.append(list(map(int, input().split())))

ans = ["-1" for i in range(n)]
s_and_c.sort()


if m == 0:
    if n == 1:
        ans = ["0"]
    else:
        ans[0] = "1"

elif n != 1 and s_and_c[0][0] == 1 and s_and_c[0][1] == 0:
    ans = -1
else:
    for i in range(m):
        if ans[s_and_c[i][0] - 1] == "-1":
            ans[s_and_c[i][0] - 1] = str(s_and_c[i][1])
        elif ans[s_and_c[i][0] - 1] == str(s_and_c[i][1]):
            continue
        else:
            ans = -1


if ans != -1:
    for i in range(n):
        if ans[i] == "-1":
            if i == 0:
                ans[i] = "1"
            else:
                ans[i] = "0"
    ans = "".join(ans)

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
# define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> ba; 
    rep(i,m){
        int a,b;
        cin >> a >> b;
        ba.pb(make_pair(b-1,a));
    }
    sort(ba.begin(),ba.end());
    int tmp_right = -1;
    int ans = 0;
    rep(i,m){
        int left = ba[i].second;
        int right = ba[i].first;
        if(left <= tmp_right){

        }else{
            tmp_right = right;
            ans ++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 1400
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, t = map(int, input().split())
    T = list(map(int, input().split()))

    res = 0
    for i in range(1, n):
        if T[i - 1] + t < T[i]:
            res += t
        else:
            res += T[i] - T[i - 1]

    print(res + t)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 25708
# -*- coding: utf-8 -*-
import io
import sys
import math

def format_multi_answer(lst):
    ans = ""
    ans += f"{len(lst)}\n"
    for y in lst:
        ans += f"{y[0]} {y[1]}\n"
    return ans

def is_condition_ok(lst):
    for i in range(len(lst)-1):
        if lst[i] > lst[i+1]:
            return False
    return True

def solve(n,a_lst):
    """
    D_2: 記述軽く、アルゴリズムやや悪い？バージョン
    """
    # implement process
    if is_condition_ok(a_lst):
        return 0

    # get max / min value and index
    i_max, a_max = -1,-1
    i_min, a_min = +1,+1
    for i in range(len(a_lst)):
        if a_max < a_lst[i]:
            a_max = a_lst[i]
            i_max = i
        if a_min > a_lst[i]:
            a_min = a_lst[i]
            i_min = i

    ans_lst = []
    if a_max >= 0 and a_max >= abs(a_min):
        # 全ての負の値にmax値を足し込み正の値にする。次に、plus時の処理を行う。
        if _DEB: logd(f"plus")
        for i in range(len(a_lst)):
            if a_lst[i] < 0:
                ans_lst.append([i_max+1,i+1])
        ans_lst.append([i_max+1,1])
        for i in range(len(a_lst)-1):
            ans_lst.append([i+1,i+2])
    else:
        # 全ての正の値を負の値にし、minus時の処理を行う。
        if _DEB: logd(f"minus")
        for i in range(len(a_lst)):
            if a_lst[i] >= 0:
                ans_lst.append([i_min+1,i+1])
        ans_lst.append([i_min+1,len(a_lst)])
        for i in range(len(a_lst)-1,0,-1):
            ans_lst.append([i+1,i])

    return format_multi_answer(ans_lst)

def main():
    # input
    n = int(input())
    a_lst = list(map(int, input().split()))

    # process
    ans = str( solve(n,a_lst) ).strip()
    
    # output
    print(ans)
    return ans
        
### DEBUG I/O ###
_DEB = 0   # 1:ON / 0:OFF

_INPUT = """\
2
-1 -3
"""
_EXPECTED = """\
2
2 3
3 3
"""

def logd(str):
    """usage:
    if _DEB: logd(f"{str}")
    """
    if _DEB: print(f"[deb] {str}")

### MAIN ###
if __name__ == "__main__":
    if _DEB:
        sys.stdin = io.StringIO(_INPUT)
        print("!! Debug Mode !!")

    ans = main()

    if _DEB:
        print()
        if _EXPECTED.strip() == ans.strip(): print("!! Success !!")
        else: print(f"!! Failed... !!\nANSWER:   {ans}\nExpected: {_EXPECTED}")

Measured memory_bytes: 9356
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)


int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;

    for (int i= 1;i < n;i++){
        string s1,s2;
        int cnt=0;
        s1 = s.substr(0,i);
        s2 = s.substr(i,n-i);
        map<char,int> m,mx;
        for (int j = 0;j < i;j++){
            m[s1[j]]++;
        }
        for (int k = 0;k < n-i;k++){
            mx[s2[k]]++;
        }
        for (auto q:m){
            for (auto e:mx){
                if (q.first == e.first) cnt++;
            }
        }
        ans = max(cnt,ans);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int hoge[1000];
int main() {
	int X, Y;
	cin >> X >> Y;
	hoge[1] = 300000;
	hoge[2] = 200000;
	hoge[3] = 100000;
	int r = hoge[X] + hoge[Y];
	if (X == 1 && Y == 1) r += 400000;
	cout << r << endl;
}


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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	vector<int> d(n);
	rep(i, n) {
		d[i] = s[i] - '0';
	}
	ll ans = 0;
	for(int bit = 0; bit < (1 << (n-1)); bit++) {
		ll now = 0;
		ll tmp = d[0];
		rep(i, n-1) {
			if((bit >> i) & 1) {
				// +
				now += tmp;
				tmp = d[i+1];
			} else {
				// +なし
				tmp = tmp*10 + d[i+1];
			}
		}
		now += tmp;
		// cout << now << endl;
		ans += now;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <utility>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  long long int c[100010];
  for (int i = 0; i < 100010; i++)
    c[i] = 0;
  long long int m = 0;
  for (int i = 0; i < N; i++) {
    long long int a; cin >> a;
    c[a]++;
    m = max(m, a);
  }
  long long int ans = 0;
  for (int i = 1; i < 100000; i++)
    ans = max(ans, c[i-1]+c[i]+c[i+1]);
  cout << ans << endl;
}


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

int N;
int Ans = INT_MAX, w[101], psum[101];

inline int Rd() {
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
inline void ChkMin(int &aa, int bb) {
	if(aa > bb) aa = bb;
	return;
}

int main() {
	N = Rd();
	for(int i = 1; i <= N; ++i)
		w[i] = Rd(), psum[i] = psum[i - 1] + w[i];
	for(int i = 1; i <= N; ++i)
		ChkMin(Ans, abs(psum[N] - (psum[i] << 1)));
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

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


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int h,w;
  cin>>h>>w;
  string mp[h];
  queue<pair<PII,char>> bfs;
  int cntb=0,cntw=0,ans=0;
  rep(i,h) cin>>mp[i];
  rep(i,h){
    rep(j,w){
      if(mp[i][j]!='!'){
	cntb=cntw=0;
	bfs.push(make_pair(make_pair(i,j),mp[i][j]));
	mp[i][j]='!';
	while(!bfs.empty() ){
	  pair<PII,char> prev=bfs.front();
	  bfs.pop();
	  int X=prev.F.F,Y=prev.F.S;
	  if(prev.S=='.') cntb++;
	  else cntw++;
	  rep(k,4){
	    if(0<=X+dx[k] && X+dx[k]<h && 0<=Y+dy[k] && Y+dy[k]<w){
	      if(prev.S=='.' && mp[X+dx[k]][Y+dy[k]]=='#'){
		bfs.push(make_pair(make_pair(X+dx[k],Y+dy[k]),mp[X+dx[k]][Y+dy[k]]));
		mp[X+dx[k]][Y+dy[k]]='!';
	      }else if(prev.S=='#' && mp[X+dx[k]][Y+dy[k]]=='.'){
		bfs.push(make_pair(make_pair(X+dx[k],Y+dy[k]),mp[X+dx[k]][Y+dy[k]]));
		mp[X+dx[k]][Y+dy[k]]='!';
	      }
	    }
	  }
	}
	ans+=(cntb*cntw);
	
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Trim();
            var n = int.Parse(Console.ReadLine());

            var isReverse = false;
            var head = new List<string>();
            var tail = new List<string>();

            foreach(var i in Enumerable.Range(0, n)){
                var q = Console.ReadLine().Split().ToArray();

                if(q[0].Equals("1")){
                    isReverse = !isReverse;
                }else{
                    if(isReverse){
                        if(q[1].Equals("1")){
                            tail.Add(q[2]);
                        }else{
                            head.Add(q[2]);
                        }
                    }else{
                        if(q[1].Equals("1")){
                            head.Add(q[2]);
                        }else{
                            tail.Add(q[2]);
                        }
                    }
                }
            }

            head.Reverse();
            var x = head.Count > 0 ? string.Join("",head) : "";
            var y = string.Join("",s);
            var z = tail.Count > 0 ? string.Join("",tail) : "";
            var ans = isReverse ? string.Join("",(x + y + z).Reverse()) : x + y + z;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 32552
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	int c, f;
	
	cin >> str;
	
	c = (int)str.find("C");
	f = (int)str.rfind("F");
	
	cout << (c < f && (c != -1 && f != -1) ? "Yes" : "No") << endl;
	
	return (0);
}

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

int main(void){
    double a, b, x;
    double PI=3.14159265358979323846;
    scanf("%lf%lf%lf", &a, &b, &x);
    if (x<=a*a*b/2) {
        printf("%.15f", (180/PI)*atan(a*b*b/(2*x)));
    }
    else {
        // printf("%.15f", (180/PI)*atan(2*(a*a*b-x)/(a*a*a*b)));
        printf("%.15f", (180/PI)*atan((b-(2*x/(a*a)-b))/a));
    }
    return 0;
}


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

int main(){
    ll x; cin >> x;
    ll a = 100; int ans = 0;
    for(int i=0; ;i++){
        a += a/100;
        ans++;
        if(a >= x) {
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3528
import collections as c
n = int(input())
v = list(map(int, input().split()))
v_odd  = []
v_even = []
for i in range(n):
    if i % 2 == 0: v_even.append(v[i])
    else: v_odd.append(v[i])
od_counter = c.Counter(v_odd)
ev_counter = c.Counter(v_even)
odmode = od_counter.most_common()
evmode = ev_counter.most_common()

if odmode[0][0] != evmode[0][0]:
    total = len(v) - odmode[0][1] - evmode[0][1]
    print(total)
else:
    if len(odmode) == 1:
        if len(evmode) == 1:
            print(min(len(v_odd), len(v_even)))
        else:
            print(len(v_even) - evmode[1][1])
    elif len(evmode) == 1:
        print(len(v_odd) - odmode[1][1])
    else:
        odc = len(v) - odmode[0][1] - evmode[1][1]
        evc = len(v) - evmode[0][1] - odmode[1][1]
        print(min(odc, evc))


Measured memory_bytes: 23552
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6, INF = 1e9 * 1e9 + 10, MOD = 998244353, B = 9;

ll dpt[SIZE];
vector<pair<ll, ll>> vec;
vector<vector<pair<ll, ll>>> vls;

int main()
{
	fastInp;

	ll n;
	cin >> n;

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

		vec.push_back({ x, y });
	}
	ll q;
	cin >> q;
	dpt[0] = 0;

	vls.resize(n);
	vls[0].push_back({ 0, 0 });
	vls[0].push_back(vec[0]);
	for (int i = 1; i < n; i++) {
		dpt[i] = dpt[(i - 1) / 2] + 1;
		if (dpt[i] <= B) {
			vector<pair<ll, ll>> nw;
			for (auto cur : vls[(i - 1) / 2]) {
				nw.push_back(cur);
				nw.push_back({ cur.first + vec[i].first, cur.second + vec[i].second });
			}
			vls[i] = nw;
			sort(vls[i].begin(), vls[i].end());

			nw.clear();

			nw.push_back(vls[i][0]);
			for (int j = 1; j < vls[i].size(); j++) {
				while (nw.size() > 0 && nw.back().second >= vls[i][j].second) nw.pop_back();
				nw.push_back(vls[i][j]);
			}
		}
	}

	while (q--) {
		ll v, l;
		cin >> v >> l;
		v--;
		ll ans = 0;
		if (dpt[v] <= B) {
			for (auto cur : vls[v]) {
				if (cur.second <= l) ans = max(ans, cur.first);
			}
			cout << ans << "\n";
		}
		else {
			vector<pair<ll, ll>> nw;
			ll u = v;
			nw.push_back({ 0, 0 });
			nw.push_back(vec[u]);
			u = (u - 1) / 2;
			while (dpt[u] > B) {
				vector<pair<ll, ll>> nw2;
				for (auto cur : nw) {
					nw2.push_back(cur);
					nw2.push_back({ cur.first + vec[u].first, cur.second + vec[u].second });
				}
				nw = nw2;

				nw2.clear();
				nw2.push_back(nw[0]);
				sort(nw.begin(), nw.end());
				for (int j = 1; j < nw.size(); j++) {
					while (nw2.size() > 0 && nw2.back().second >= nw[j].second) nw2.pop_back();
					nw2.push_back(nw[j]);
				}

				nw = nw2;

				u = (u - 1) / 2;
			}

			ll i = vls[u].size() - 1, i2 = 0, ans = 0;
			while (i2 < nw.size() && i >= 0) {
				while (i2 < nw.size() && i >= 0 && (nw[i2].second + vls[u][i].second > l)) {
					i--;
				}
				if (i == -1) break;

				ans = max(ans, nw[i2].first + vls[u][i].first);
				i2++;
			}

			cout << ans << "\n";
		}
	}
	return 0;
}

// 192 / 216 - 8 / 9
// 192 / 8

// 54 / 72 - 3 / 4
// 54 / 6



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

using namespace std;

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < n - 1; i++) {
    int s, e, w;
    cin >> s >> e >> w;
    s--;
    e--;
    g[s].push_back({e, w});
    g[e].push_back({s, w});
  }
  vector<int> dist (n, INT_MAX);
  queue<pair<int, int > > q;
  q.push({0, 0});
  while (!q.empty()) {
    int cur = q.front().first;
    int w = q.front().second;
    q.pop();
    if (dist[cur] < INT_MAX) continue;
    dist[cur] = w;
    for (auto to : g[cur]) {
      if (dist[to.first] > w + to.second) {
        q.push({to.first, w + to.second});
      }
    }
  }
  for (auto it : dist) {
    if (it % 2 == 0) cout << 0 <<'\n';
    else cout << 1 << '\n';
  }
}

Measured memory_bytes: 6912
#include <iostream>
#include <map>
#include <string>
#include <numeric>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll cnt = 0, dec = 1;
    map<ll, ll> m;
    ++m[0];
    for (int i = (int)s.size() - 1; i >= 0; --i) ++m[(cnt += (s.at(i) - '0') * dec) %= 2019], (dec *= 10) %= 2019;
    cout << accumulate(m.begin(), m.end(), 0LL, [](ll i, pair<ll, ll> j) {
        return i += j.second * (j.second - 1) / 2;
    }) << endl;
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;
#define MOD 1000000007LL

int main(){
  ll N;
  cin >> N;
  string S1, S2;
  cin >> S1 >> S2;
  vi pat(0);
  for(int i = 0; i < N; i++){
    if(S1.at(i) == S2.at(i)) pat.push_back(0);
    else{
      pat.push_back(1);
      i++;
    }
  }
  ll ans;
  for(int i = 0; i < pat.size(); i++){
    if(i==0){
      if(pat.at(i) == 0) ans = 3LL;
      else ans = 6LL;
    }
    else{
      if(pat.at(i-1) == 0) ans *= 2LL;
      else if(pat.at(i) == 0) ans *= 1LL;
      else ans *= 3LL;
    }
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T>inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}

int n;
ll a[100010][3]; 
ll dp[100010][3];

int main(){
  cin>>n;
  for(int i=0;i<n;++i)for(int j=0;j<3;++j)cin>>a[i][j];
  for(int i=0;i<n;++i){
    for(int j=0;j<3;++j){
      for(int k=0;k<3;++k){
        if(j==k)continue;
        chmax(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  ll res=0;
  for(int j=0;j<3;++j)chmax(res,dp[n][j]);
  cout<<res;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

int main(void){
    int n; cin >> n;
    map<int, int> mp;
    for(int i=2; i<=n; i++){
        int a; cin >> a;
        mp[a]++;
    }
    for(int i=1; i<=n; i++){
        cout << mp[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12996
#include<stdio.h>
#include<math.h>

int isprime(int);

int main(){

  int N,i,p,count = 0;
  
  scanf("%d", &N);
  int A[N];

  for(i=0;i<N;i++)scanf("%d",&A[i]);

  for(i=0;i<N;i++){
    p = isprime(A[i]);
    if(p == 1)count++;
  }

  printf("%d\n",count);

  return 0;
}

int isprime(int x){

  int i;
  
  if(x == 2)return 1;

  if(x < 2 || x % 2 == 0)return 0;

  i = 3;
  
  while(i <= sqrt(x)){
    if(x % i == 0)return 0;
    i = i + 2;
  }

  return 1;
}



Measured memory_bytes: 2032
def f(str)
    case str
    when 'D'..'Z'
        [str.unpack("C")[0]-3].pack("C")
    when 'A'
        'X'
    when 'B'
        'Y'
    when 'C'
        'Z'
    end
end

puts gets.chomp.split(//).map{|c| f c}.join

Measured memory_bytes: 5004
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1004
#define mod 998244353
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
void solve(){
    ll x;
    cin>>x;
    ll p=x/500;
    x%=500;
    ll p2=x/5;
    x%=5;
    cout<<p*1000+p2*5<<"\n";
}
int main(){
    clock_t t1=clock();
    gear_change;
    ll test=1;
    // in(test);
    while(test--){
        solve();
    }
    clock_t t2=clock();
    cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}    

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

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int x;cin>>x;
  int k = x/100;
  int r = x%100;
  dump(x, k, r);
  if (r<=k*5){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
void main(){
	int[] ab = _scanln();
	(ab[0]*ab[1]&1)?writeln("Odd"):writeln("Even");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <cctype>
#include <numeric>
#include <memory>
#include <functional>
using namespace std;
#define Debug(x) cerr << #x << " = " << x << endl
#define Debug22(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<endl;
#define Debug2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define Debug3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<")\n";
#define Debug_arr(v,n) for(int i=0;i<n;++i) cerr<<#v<<"["<<i<<"]"<<" = "<<v[i]<<endl;
#define SET(p,v) fill((__typeof(**p)*)p,(__typeof(**p)*)p+sizeof(p),v);
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define prl cerr << "called: " << __LINE__ << endl
//#define FILE_JUDGE
//#define TIMES
//#define LINES
//#define home
vector <int> v[100005];
int L[100005],P[100005],cnt[100005],n;
inline void dfs(int x)
{
	cnt[x]=1;
	for (int i=0;i<v[x].size();++i)
	{
		int cur=v[x][i];
		if (P[x]==cur)
		{
			continue;
		}
		L[cur]=L[x]+1;
		P[cur]=x;
		dfs(cur);
		cnt[x]+=cnt[cur];
	}
}
int main()
{
	#ifdef FILE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=0;i<n-1;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1);
	int up=(L[n]-1)/2;
	int p=n;
	while (up--)
	{
		p=P[p];
	}
	if (cnt[p]>=n-cnt[p])
	{
		puts("Snuke");
	}
	else
	{
		puts("Fennec");
	}
	#ifdef TIMES
	eprintf("Times = %d ms.\n",clock());
	#endif
	#ifdef LINES
	eprintf("lines : %d line.\n",__LINE__+3);
	#endif
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	ll n,m;
	cin>>n>>m;
	vll A(n);
	for(int i=0;i<n;i++)
		cin>>A[i];
	sort(all(A));
	ll idx=-1;
	for(int i=0;i<n;i++)
		if(m>=A[i])
			m-=A[i];
		else 
		{idx = i;break;}
	if(idx==-1) cout<<n-1+(m==0)<<"\n";
	else cout<<idx<<"\n";
	
		

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define inf    0x3f3f3f3f
#define ll long long
#define pb push_back
#define upperlimit 1000100
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]

int main(){

 ll n; cin>>n;
   int a[n];

   for(int i=0;i<n;i++)cin>>a[i];

   int ans=0;

   for(int i=0;i<n;i++)
  {
      //  cout<<"animesh "<<i<<endl;

      while(i+1 <n && a[i+1]  == a[i]) i++;

      if(i+1 < n && a[i+1] > a[i]){
            while(i+1 < n && a[i+1]>= a[i]) i++;
      }
      else if(i+1 < n && a[i+1] < a[i]){
            while(i+1 < n && a[i+1]<= a[i])
                  i++;
      }
      ans++;
   }

   cout<<ans<<endl;


 return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define ll long long
#define PI 3,14
using namespace std;

int main()
{
    ll n,m,s=0;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        ll x;
        cin>>x;
        s=s+x;
    }
    if(s>n)
        cout<<-1;
    else
        cout<<n-s;
    return 0;
}


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

using namespace std;

int main(void) {
  string s;
  while (cin >> s, s != "0") {
    int a = 0, b = 0;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] == 'A') a++;
      else b++;
    }

    if (a > b) a++;
    else b++;

    cout << a << " " << b << endl;
  }
  
  return 0;
}


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

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

int main() {
  vector<int> d(110);
  int a =0;
  int b = 0;
  int ans = 0;
  int N = 0;
  cin >> N;
  for(int i = 0; i < N; i++) cin >> d.at(i);
  sort(d.rbegin(), d.rend()); 
  // rep(i,N) cout << d.at(i) << endl;
  for(int i =0; i < N; i+=2) a += d.at(i);
  for(int i =1; i < N; i+=2) b += d.at(i);
  ans = a - b;
  cout << ans << endl;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

s = input()

if (s[0] != "A"):
    print("WA")
    exit()

s = s[1:]

if (s[1:-1].count("C") != 1):
    print("WA")
    exit()

s = s.replace("C","")

if (s.islower()):
    print("AC")
else:
    print("WA")




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

int main() {
  int a,b;
  cin >> a >> b ;
 if((a==1 && b==2)||(a== 2 && b==1)){
  cout << 3<<endl;
 }
  if((a==1 && b==3)||(a==3 && b==1)){
    cout << 2 << endl;
  }
  if((a==2 && b==3)||(a==3 && b==2)){
	cout << 1 << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+20;
const int m = 2e2+20;
long long v[N], c[m][m];
void init()
{
	memset(c, 0, sizeof(c));
	c[0][0] = 1;
	for (int i = 1; i <= 50; i++)
	{
		c[i][0] = 1;
		for (int j = 1; j <= i; j++)
			c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
	}
}
int main()
{
	int n, a, b;
	init();
	while(cin >> n >> a >> b)
	{
		double ave;
		for (int i = 0; i < n; i++)
			cin >> v[i];
		sort(v, v + n);
		reverse(v, v + n);
		for (int i = 0; i < a; i++) 
			ave += v[i];
		ave /= a;
		int num = 0, k = 0;
		for (int i = 0; i < n; i++)
		{
			if (v[i] == v[a - 1])
			{
				num++;
				if (i < a) k++;
			}
		}	
		long long ans = 0; 
		if (k == a)
		{
			for (int i = a; i <= b; i++)
				ans += c[num][i];
		}
		else ans += c[num][k];
        cout.precision(20);
 		cout << fixed << ave << endl << ans;
	}
}


Measured memory_bytes: 4168
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;
const int INF = 1e12;

char c[110][110];
int d[110][110][4];
int h, w, l;
string str = "NESW";
int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0,-1};
bool contain(int y, int x){

   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        cin >> h >> w >> l;
        if(h + w + l == 0) break;
        int dr = 0, y = 0, x = 0;
        rep(i, 0, h) rep(j, 0, w) rep(k, 0, 4) d[i][j][k] = -1;
        rep(i, 0, h){
            rep(j, 0, w){
                cin >> c[i][j];
                if(str.find(c[i][j]) != string::npos){
                    dr = str.find(c[i][j]);
                    y = i; x = j;
                }
            }
        }
        // cerr << dr << endl;
        d[y][x][dr] = 0;
        vector<PP> sv;
        sv.push_back(PP(P(y, x), dr));
        for(int i = 1;; i++){
            int ny = 0, nx = 0;
            // cerr << i << ' ' << ny << ' ' << nx << ' ' << dr << endl;
            for(int j = 0;; j++){
                ny = y + dy[dr];
                nx = x + dx[dr];
                if(contain(ny, nx) && c[ny][nx] != '#'){
                    break;
                }
                dr = (dr + 1) % 4;
                // cerr << dr << endl;
            }
            y = ny; x = nx;    
            if(i == l){
                cout << y + 1 << ' ' << x + 1 << ' ' << str[dr] << endl;
                break;
            }        
            if(d[y][x][dr] != -1){
                int loop = i - d[y][x][dr];
                int step = d[y][x][dr] + (l - d[y][x][dr]) % loop;
                // cerr << loop << ' ' << step << endl;
                cout << sv[step].first.first + 1 << ' ' << sv[step].first.second + 1 << ' ' << str[sv[step].second] << endl;
                break;
            }
            d[y][x][dr] = i;
            sv.push_back(PP(P(y, x), dr));
        }
    }
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
 #define print(x) cout<<x
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout<<arr[n-1];
	return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int> x(n); for(int i = 0; i < n; ++i) cin >> x[i];
	int l; cin >> l;
	// dp[i][k] := iから2^kで行ける最大
	vector<vector<int>> dpL(n, vector<int>(21));
	vector<vector<int>> dpR(n, vector<int>(21));
	for(int i = 0; i < n; ++i) {
		dpL[i][0] = lower_bound(x.begin(), x.end(), x[i] - l) - x.begin();
		dpR[i][0] = upper_bound(x.begin(), x.end(), x[i] + l) - x.begin() - 1;
	}
	for(int k = 0; k < 20; ++k) {
		for(int i = 0; i < n; ++i) {
			dpL[i][k + 1] = dpL[dpL[i][k]][k];
			dpR[i][k + 1] = dpR[dpR[i][k]][k];
		}
	}
	int q; cin >> q;
	while(q--) {
		int a, b; cin >> a >> b;
		--a; --b;
		int ans = 0;
		int now = a;
		if(a < b) {
			for(int k = 20; k >= 0; --k) {
				if(dpR[now][k] < b) {
					now = dpR[now][k];
					ans += (1 << k);
				}
			}
		} else {
			for(int k = 20; k >= 0; --k) {
				if(b < dpL[now][k]) {
					now = dpL[now][k];
					ans += (1 << k);
				}
			}
		}
		cout << ans + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 24704
#include<stdio.h>
#include<iostream>
#include<string>
using namespace::std;

int main(void) {
	long long n = 100;
	long long x;
	cin >> x;
	int i;
	for (i = 0;  n< x; i++) {
		n+=n*0.01;

	}
	cout << i;
	

	return 0;
}


Measured memory_bytes: 3592
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Beehives
public class Main{

	int[][] d = {{0,1},{-1,0},{-1,-1},{0,-1},{1,0},{1,1}};
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt(), M = 150;
		sc.nextLine();
		while(T--!=0){
			char[] s = sc.nextLine().toCharArray(), t = sc.nextLine().toCharArray();
			sc.nextLine();
			Set<Integer> set = new HashSet<Integer>();
			int x = 100, y = 100;
			set.add(x*M+y);
			for(char c:s){
				x+=d[c-'a'][0]; y+=d[c-'a'][1];
				set.add(x*M+y);
			}
			boolean res = false;
			if(s.length==t.length){
				for(int S:set){
					if(res)break;
					for(int k=0;k<6;k++){
						x = S/M; y = S%M;
						int cnt = 1;
						for(char c:t){
							x+=d[(c-'a'+k)%6][0]; y+=d[(c-'a'+k)%6][1];
							if(!set.contains(x*M+y))break;
							cnt++;
						}
						if(cnt==set.size()){
							res = true; break;
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e5 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

int n, we;
int dp[111][11111], w[111], v[111];

int main() {
    cin >> n >> we;
    for(int i = 1; i <= n; i ++)
        cin >> v[i] >> w[i];
    for(int i = 0; i <= n; i ++) {
        for(int j = 1; j <= (int)1e4; j ++) {
            dp[i][j] = inf;
            if(i > 0)
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            if(i > 0 && j - v[i] >= 0)
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
        }
    }
    int res = 0;
    for(int j = (int) 1e4; j >= 1; j --) {
        if(dp[n][j] <= we) {
            res = j;
            break;
        }
    }
    cout << res << '\n';
    return 0;
}



Measured memory_bytes: 7460
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define N 100007
#define INF 1000000000
using namespace std;

typedef long long ll;

int main()
{
    int n;
    string str[100];
    cin >> n;
    FOR(i, 0, n)
    cin >> str[i];
    FOR(i, 1, n)
    {
        if (*(str[i - 1].end() - 1) != *(str[i].begin()))
        {
            cout << "No" << endl;
            return 0;
        }
        FOR(j, 0, i)
        if (str[i] == str[j])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979
 
void mul_mod(ll& a, ll b){
    a *= b;
    a %= MOD;
}

void add_mod(ll& a, ll b){
    a += b;
    a %= MOD;
}

int main(void){
	int i,j,n;
	bool isp[60000];
	fill(isp,isp+60000,true);
	isp[1] = false;
	for(i=2; i<=235; ++i){
		if(!isp[i]){
			continue;
		}
		for(j=(i*2); j<=55555; j+=i){
			isp[j] = false;
		}
	}
	cin >> n;
	i = 6;
	n -= 1;
	cout << "2";
	while(n){
		if(isp[i]){
			cout << " " << i;
			--n;
		}
		i += 5;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
*A, = map(int, input().split())
C = {0: 1}
ans = 0
s = 0
for a in A:
    s = (s + a) % M
    ans += C.get(s, 0)
    C[s] = C.get(s, 0) + 1
print(ans)

Measured memory_bytes: 14224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int x, y, ans = 0;
    	
        void solve(InputReader in, PrintWriter out) {
            // write your code here
        	x = in.nextInt();
        	y = in.nextInt();
        	
        	ans = Math.abs(Math.abs(x) - Math.abs(y));
        	if (Integer.signum(x)*Integer.signum(y) == -1) {
        		ans += 1;
        	} else if (y < x) {
        		ans += x*y == 0 ? 1 : 2;
        	} 
        	
        	out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 21588
#include <stdio.h>

int main(void)
{
	long long int check;		//[N]
	long long int blue, red;	//[A, B]
	long long int sum;			//answer;
	long long int divide;

	//STDinput (Value N, A, B).
	scanf("%lld %lld %lld", &check, &blue, &red);

	sum = 0;

	//Find the number of sets where RED and BLUE appear.
	//Multiply blue by the number of sets.
	divide = check / (blue + red);
	sum = divide * blue;

	//Check the last set.
	divide = divide * (blue + red);
	check = check - divide;

	check = check - blue;
	if(check < 0)
		blue = blue + check;
	sum = sum + blue;

	printf("%lld", sum);

	return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  for(int i = 0; i < s.size();i++){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

#define         ll          long long int

int main( )
{
    int i, a, b, t, c = 0;

    cin >> a >> b >> t;

    for (i = a; i <= t; i += a)
    {
        c += b;
    }

    cout << c << "\n";

    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int anko=0;
	int maojini=0;
	for(int i = 0; i < s.size();++i){
		if(s[i]=='A'){
			anko = i;
			break;
	}
	}
	for(int i = 0; i < s.size();++i){
		if(s[i]=='Z'){
			maojini = i;
	}
	}
	cout << maojini - anko + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define F(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define VE(i,v) for(int i = 0;i < (v).size();i++)

using namespace std;
#define trace(...) cerr<<__FUNCTION__<<":"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned int ui;
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
typedef pair<ll,ll> pll;
typedef vector<pll> vpll; 
 


unordered_map<int, int> cnt;
int id_cnt = 0;
int N, M, K;
void dfs(int i, int j, vector<string> &arr, vvi &id)
{
	id[i][j] = id_cnt;
	int r[] = {1,-1, 0, 0};
	int c[] = {0,0,1, -1};
	for(int idx =0; idx <4; idx++)
	{
		int u = i + r[idx];
		int v = j + c[idx];
		if((u>=0) && (v>=0) && ( u < N) && (v<M))
		{
			if(arr[u][v]=='*')
				cnt[id_cnt]++;
			else if (id[u][v]==0)
				dfs(u, v, arr, id);
		}
	}
}

int main()

{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	int T;
	T=1;
	for(int tc=1; tc<=T;tc++)
	{
		int A1, A2, A3;
		cin >> A1 >> A2 >>A3;
		int sum = A1 + A2 + A3;
		if(sum >= 22)
			cout<<"bust\n";
		else
			cout<<"win\n";
	}
 
 
 
	return 0;
}
 
 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

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

    int n;
    cin >> n;

    constexpr int T = 0xff;
    constexpr ll X = 0x101010101010101;
    int p0[60] = {};
    ll r = 0;

    for (int i0 = 0; i0 < n; i0 += T) {
        ll p[8] = {};
        int i1 = min(T, n - i0);
        for (int i = 0; i < i1; i++) {
            ll a;
            cin >> a;

            for (int k = 0; k < 8; k++) {
                p[k] += a & X;
                a >>= 1;
            }
        }

        for (int k = 0; k < 8; k++) {
            ll c = p[k];
            for (int h = 0; h < 8; h++) {
                p0[8 * h + k] += c & T;
                c >>= 8;
            }
        }
    }

    for (int k = 0; k < 60; k++) {
        r += (1LL << k) % P * p0[k] % P * (n - p0[k]) % P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int h[300000];
int main(){
	int n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&h[i]);
	sort(h,h+n,greater<>());
	ll ans=0;
	rep(i,n){
		if(i<K)continue;
		else ans+=h[i];
	}
	cout<<ans<<endl;
}

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

//#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    int res = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) for (int k = j+1; k < n; k++) {
        if (a[i]+a[j] > a[k] && a[i]+a[k] > a[j] && a[j]+a[k] > a[i] && a[i] != a[j] && a[i] != a[k] && a[j] != a[k]) res++;
    }
    cout << res << '\n';
}
/*

 */

Measured memory_bytes: 3696
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W, K = MAP()

s = [input() for _ in range(H)]

tmp = 0
ans = [[0]*W for _ in range(H)]
for i in range(H):
	if "#" not in s[i]:
		if i != 0:  # 上が決まっている
			ans[i] = ans[i-1]
			continue
		else:
			continue
	is_first = True
	tmp += 1
	for j in range(W):
		if s[i][j] == "#" and tmp != K:
			if is_first:
				is_first = False
			else:
				tmp += 1
		ans[i][j] = tmp

for i in range(H-1, -1, -1):
	if not any(ans[i]):
		ans[i] = ans[i+1]

for l in ans:
	print(*l)


Measured memory_bytes: 66776
s=input()
l=[]
for i in s:l.append((123-ord(i))%26)
k=int(input())
for i,j in enumerate(l):
    if j<=k:l[i],k=26,k-j
l[-1]=(l[-1]-k%26)+[0,26][l[-1]-k%26<1]
for i,j in enumerate(l):l[i]=chr(123-j)
print(''.join(map(str,l)))

Measured memory_bytes: 4980