akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 101010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T>
void DEBUG(T e)
{
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T>
void DEBUG(const std::vector<T> &v)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v)
  {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T>
void DEBUG(const std::vector<std::vector<T>> &vv)
{
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv)
  {
    DEBUG(v);
  }
}
template <class T, class... Ts>
void DEBUG(T d, Ts... e)
{
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T>
void corner(bool flg, T hoge)
{
  if (flg)
  {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//BELOW
//solve

void solve(void)
{
  string s, t;
  cin >> s >> t;
  int res = INF;
  for (int i = 0; i < (int)s.size() - (int)t.size() + 1; i++)
  {
    int cnt = 0;
    for (int j = 0; j < t.size(); j++)
    {
      if (s[i + j] != t[j])
        cnt++;
    }
    chmin(res, cnt);
  }
  cout << res << endl;

  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int card[20];

int solve(int m){
  int now[20];
  int cnt = 0;
  int toi[20];
  bool flag = true;

  REP(i,20) if((m & (1 << i)) != 0){
    now[cnt] = card[i];
    toi[cnt] = i;

    //printf("%d%c", card[i], (cnt % 4 == 3 ? '\n' : ' '));

    cnt++;
  }
  //if(cnt % 4 != 0) puts("");
  //puts("");

  int ans = cnt;

  REP(i,cnt){
    if(i % 4 != 3){
      if(i + 1 < cnt){
        if(now[i] == now[i+1]){
          int mm = m ^ (1 << toi[i]) ^ (1 << toi[i+1]);
          ans = min(ans, solve(mm));
        }
      }
    }
    if(i < 16){
      if(i + 4 < cnt){
        if(now[i] == now[i+4]){
          int mm = m ^ (1 << toi[i]) ^ (1 << toi[i+4]);
          ans = min(ans, solve(mm));
        }
      }
    }
    if(i % 4 != 3 && i < 16){
      if(i + 5 < cnt){
        if(now[i] == now[i+5]){
          int mm = m ^ (1 << toi[i]) ^ (1 << toi[i+5]);
          ans = min(ans, solve(mm));
        }
      }
    }
    if(i % 4 != 0 && i < 16){
      if(i + 3 < cnt){
        if(now[i] == now[i+3]){
          int mm = m ^ (1 << toi[i]) ^ (1 << toi[i+3]);
          ans = min(ans, solve(mm));
        }
      }
    }
  }

  return ans;
}

int main(){
  int cc = getInt();
  while(cc --> 0){
    REP(i,20) card[i] = getInt();
    print(solve((1<<20)-1));
  }
  return 0;
}

Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll a,b;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>a>>b;
	if(a<b)swap(a,b);
	if((a-b)%2==0){
		cout<<(a+b)/2;
	}else{
		cout<<"IMPOSSIBLE";
	}
	return 0;
}



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

using namespace std;

int main()
{
    long long nMax=1e5+5,N, W, d[2][nMax], w[102], v[102];
    cin >> N >> W;
    for(int i=0;i<N;i++)
        cin >> w[i] >> v[i];
    for(int j=0;j<nMax;j++)
        d[0][j]=d[1][j]=LLONG_MAX/2;
    d[1][0]=0;
    for(int i=0;i<N;i++)
        for(int j=0;j<nMax;j++)
            if(j>=v[i])
                d[i&1][j]=min(d[i&1^1][j-v[i]]+w[i],d[i&1^1][j]);
            else
                d[i&1][j]=d[i&1^1][j];
    for(int q = nMax-1; q > 0; q--)
        if(d[N&1^1][q] <= W)
            return 0*printf("%i\n",q);
}


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

long long maximum;
long long mod;
vector<long long> fct(0),invfct(0);

long long modpow(long long a,long long n, long long mod){
    long long res = 1;
    while(n>0){
        if ( n & 1 ) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    } 
    return res;
}

void fct_input(long long maximum,long long mod){
    fct.resize(maximum+1,-1);
    fct.at(0) = 1;
    fct.at(1) = 1;
    long long x = 1;
    for(long long i=2;i<=maximum;i++){
        x = x * i % mod;
        fct.at(i) = x;
    }
 }

void invfct_input(long long maximum,long long mod){
    invfct.resize(maximum+1,-1);
    invfct.at(0) = 1;
    invfct.at(1) = 1;
    long long x = 1;
    for(long long i=2;i<=maximum;i++){
        x = x * i % mod;
        invfct.at(i) = modpow(x,mod - 2,mod);
    }
}

long long nhk(long long n, long long k,long long mod){
    n = n + k;
    long ans;
    ans = ((invfct.at(k) * invfct.at(n-k) % mod) * fct.at(n) ) % mod;
    return ans;
}

  int main(){
    long long h,w,n,m;
    mod = 1000000007;
    maximum = 200000; 
    cin >> h >> w >> n >> m;
    fct_input(maximum,mod);
    invfct_input(maximum,mod);
    long long ans = 0;
    for(long long i=0;i<w-m;i++){
      ans = ans + (nhk(m+i,h-n-1,mod) * nhk(w-m-1-i,n-1,mod) % mod);
      ans %= mod;
    } 
    cout << ans << endl;;
  }


Measured memory_bytes: 3328
import java.io.*;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{	
		
		 Scanner cthanh = new Scanner(System.in);
        int x;
        int y;
        x= cthanh.nextInt(); y= cthanh.nextInt();
        System.out.print(x * y);
        System.out.print(" ");
        System.out.println(2*x + 2*y);		
	}
}
		
    
    
   

Measured memory_bytes: 26152
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		if(n%k==0)
		{
			System.out.print(n/k);
		}
		else
		{
			System.out.println((n/k)+1);
		}

	}

}


Measured memory_bytes: 23764
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(N)]
AB = sorted(AB, key=lambda x: x[0])
ans = 0
for a, b in AB:
    if M < b:
        ans += a*M
        break
    else:
        ans += a*b
        M -= b
print(ans)


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

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if (x - r < 0 || y - r < 0 || w < x + r || h < y + r) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}




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

int main(){

    while(1){

    int n,ma,mi; cin>>n>>mi>>ma;

    if(n == 0 & ma == 0 && mi == 0) break;

    vector<int> sco(n);

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

        cin>>sco[i];

    }

    int ans=0,gap=0;

    for(int i=mi; i<=ma; i++){

        if(sco[i-1] - sco[i] >= gap){

            gap = sco[i-1] - sco[i];

            ans = i;
        }
    }

    cout<<ans<<endl;
   
    }

    return 0;
}


Measured memory_bytes: 3100
s = input()

n = len(s)

h = int((n-1)/2)
t = int((n+3)/2 - 1)

head = s[:h]

tail = s[t:]


if s == s[::-1] and head == head[::-1] and tail == tail[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <set>
using namespace std;


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

  if (K % 7 == 0) K /= 7;

  long long ans = 1;
  long long x = 1;
  while (x < K) { x = 10 *x + 1; ans++; }

  set<int> seen;

  int r;

  while (true) {
    r = x % K;
    if (r == 0) break;
    if (seen.find(r) != seen.end()) {ans = -1; break;}
    seen.insert(r);
    x = (r) * 10 + 1;
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 50432
/**
    Sweet!
**/
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pp pop_back()
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

inline int min(int a, int b) {
    return (a > b) ? b : a;
}

inline int max(int a, int b) {
    return (a > b) ? a : b;
}

const int N = 105;
const int inf = 1e9+10;
const ll linf = 1e18+9;

int n, k, ans, mn;
int a[N], b[N];
ll dp[N][1000][N];

int main() {
    scanf("%d%d", &n, &k);
    mn = 0;
    for(int i = 1; i <= n; i++)
        scanf("%d%d", &a[i], &b[i]), mn += (a[i] - a[1]);

    for(int t = 1; t <= min(n, k / a[1]); t++) {
        int s = min(k - a[1] * t, mn);
        dp[0][0][0] = 0;

        for(int i = 0; i <= n; i++)
            for(int j = 0; j <= s; j++)
                for(int l = 0; l <= t; l++)
                    dp[i][j][l] = 0;

        for(int i = 1; i <= n; i++) {
            for(int j = 0; j <= s; j++) {
                for(int l = 0; l <= t; l++) {
                    dp[i][j][l] = dp[i - 1][j][l];
                    if(l > 0 && j >= a[i] - a[1])
                        dp[i][j][l] = max(dp[i][j][l], dp[i - 1][j - a[i] + a[1]][l - 1] + b[i]);
                }
            }
        }
        for(int i = 0; i <= s; i ++)
            ans = max(ans, dp[n][i][t]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 82560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            int[] l = new int[n];
            string[] s = Console.ReadLine().Split(' ');
            for(int i = 0; i < n; i++)
            {
                l[i] = int.Parse(s[i]);
            }

            if (l.Max() * 2 < l.Sum())
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }



        }
    }
}


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

ll f(ll a) {
  ll temp=(a+1)/2%2;
  if(a%2) {
    return temp;
  }
  return temp^a;
}

int main() {
  ll a, b;
  cin >> a >> b;
  if(a==b) {
    cout << a << endl;
    return 0;
  }
  ll bit=f(a-1)^f(b);
  cout << bit << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
d = [0]*K
A = [[]]*K
test = [0]*N
for i in range(K):
	d[i]=int(input())
	A[i]=list(map(int,input().split()))

for i in range(K):
	for j in A[i]:
		test[j-1] =1
print(N-sum(test))

Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

int main(int argc, const char * argv[]) {
    
    // source code
    int N;
	N = inputValue();
  	int C[N], V[N];
  	inputArray(V, N);
  	inputArray(C, N);
  	int sum_ = 0;
  	for (int i=0; i<N; i++) {
    	if (0 < (V[i] - C[i]) ){
          sum_ += V[i] - C[i];
        }
    }
	printf("%d\n", sum_);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint n; cin >> n;
    vector<lint> a(n), b(n);
    repeat (i, n) cin >> a[i];
    repeat (i, n) cin >> b[i];
    
    auto pow2 = [](lint n) -> lint {
        return (1 << n);
    };
    
    auto fn = [](lint a, const vector<lint> &b, lint T) -> lint {
        lint x = max(0LL, T - a);
        lint y = 2 * T - 1 - a;
        lint z = 3 * T - a;
        lint w = 4 * T - 1 - a;
        auto itx = lower_bound(b.begin(), b.end(), x);
        auto ity = upper_bound(b.begin(), b.end(), y);
        auto itz = lower_bound(b.begin(), b.end(), z);
        auto itw = upper_bound(b.begin(), b.end(), w);
        //cout << "in fn "; dump(a); dump(T); dump(x); dump(y); dump(z); dump(w); dump(distance(itx, ity)); dump(distance(itz, itw)); vdump(b);
        return distance(itx, ity) + distance(itz, itw);
    };
    
    // k-bit目を決める
    lint ans = 0;
    repeat (k, 30) {
        vector<lint> amod(n), bmod(n);
        lint T = pow2(k);
        repeat (i, n) {
            amod[i] = a[i] % (T * 2);
            bmod[i] = b[i] % (T * 2);
        }
        sort(bmod.begin(), bmod.end());
        //vdump(bmod);
        lint cnt = 0;
        repeat (i, n) {
            lint t = fn(amod[i], bmod, T);
            cnt += t;
            //dump(k); dump(T); dump(i); dump(amod[i]); dump(t); dump(cnt); el;
        }
        if (cnt % 2 == 1) ans += T;
    }
    cout << ans << endl;
}

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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    ll n, k;
    cin >> n >> k;
    ll opr = n / k;
    ll ans = abs(n - k * opr);
    chmin(ans, abs(n - k * (opr + 1)));
    cout << ans << endl;
    return 0;
}
// ===========================================

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

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;
}


Measured memory_bytes: 256
require 'numo/narray'
include Numo

h, w, k = gets.split.map(&:to_i)
rows = Array.new(h){gets.chomp.bytes}
cnt = 0
[0, 1].repeated_permutation(h).each do |x|
  m = Int32[*rows.dup]
  x.each_with_index do |y, i|
    next if y == 0
    m[i, true] = '.'.ord
  end
  [0, 1].repeated_permutation(w) do |u|
    mc = Marshal.load(Marshal.dump(m))
    u.each_with_index do |v, l|
      next if v == 0
      mc[true, l] = '.'.ord
    end
    cnt += 1 if mc.to_a.flatten.count('#'.ord) == k
  end
end
puts cnt

Measured memory_bytes: 16388
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());


            if (N % 2 == 0){
                Console.WriteLine(N);
            }
            else{
                Console.WriteLine(N *2 );
            }

        }
    }
}


Measured memory_bytes: 13140
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) as[i] = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = n - 1; i >= 0; i--) sb.append(as[i]).append(' ');
        System.out.println(sb.toString().trim());
    }
}


Measured memory_bytes: 26228
#include<iostream>
int n;
int main(){
	std::cin>>n;
	for(int i=1;i<=n;++i){
		if(i%3==0){
			std::cout<<" "<<i;
		}else for(int j=i;j>0;j/=10){
			if(j%10==3){
				std::cout<<" "<<i;
				break;
			}
		}
	}
	std::cout<<std::endl;
	return 0;
}

Measured memory_bytes: 1160
n, m = map(int, input().split())
res = ['-1' for i in range(n)]
f = 1
for _ in range(m):
    s, c = map(int, input().split())
    if res[s-1] == '-1' or res[s-1] == str(c):
        res[s-1] = str(c)
    else:
        f = 0
if not f:
    print(-1)
    exit()
if res[0] == '0' or res[0] == '-1':
    if n == 1:
        print(0)
        exit()
    else:
        if res[0] == '0':
            print(-1)
            exit()
        else:
            res[0] = '1'
for i in range(1, n):
    if res[i] == '-1':
        res[i] = '0'
print(''.join(res))



Measured memory_bytes: 3064
#include<iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
//0544
int a,b,masu[1000],dice[1000],turn=0,genzaiti=0;
	int main(){
		while(cin>>a>>b){
			if(a==0&&b==0){
			break;}
			for(int i=0;i<a;i++){
			cin>>masu[i];}
			for(int j=0;j<b;j++){
				cin>>dice[j];}
			for(int p=0;p<b;p++){
				turn++;
			genzaiti+=dice[p];
			genzaiti+=masu[genzaiti];
			if(genzaiti+1>=a){
			cout<<turn<<endl;
			turn=0;genzaiti=0;p=b;}}}
		return 0;}


Measured memory_bytes: 1168
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORS(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define SORT(v,n) sort(v,v+n)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,n,0)
#define si(n) scanf("%d",&n)
#define sc(s) scanf("%s",s)
#define EPS (1e-7)
#define INF (1e9)

using namespace std;
typedef long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

ll N, M;
vector<ll> G[100001];
ll S, T;

int main(void){
    cin >> N >> M;
    for(ll i=0;i < M;i++){
        ll s, t;
        scanf("%ld %ld",&s,&t);
        G[s].push_back(t);
    }
    cin >> S >> T;

    ll A[3][100001];
    memset(A, -1, sizeof(A));

    A[0][S] = 0;

    queue<PL> q;
    q.push(PL(S,0));
    while(q.size()){
        PL t = q.front();
        q.pop();
        for (int j=0;j<G[t.first].size();j++){
            if(A[(t.second+1) % 3][G[t.first][j]] == -1){
                q.push(PL(G[t.first][j], t.second+1));
                A[(t.second+1) % 3][G[t.first][j]] = (t.second+1) / 3;
            }
            if((t.second+1) % 3 == 0 and T == G[t.first][j]){
                cout << A[0][G[t.first][j]] << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 8064
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  double n,h;
  cin >> n >> h;
  int a[100000];
  int b[100000];
  int m = 0;
  vector<int> srow;
  for(int i = 0; i < n ; i++){
    cin >> a[i] >> b[i];
    if(m < a[i]) m = a[i];
  }
  for(int i = 0; i < n ; i++){
    if(m < b[i]) srow.push_back(b[i]);
  }
  sort(srow.begin(), srow.end(), greater<int>());
  int count = 0;
//  double sum = 0;
/*  while(sum < h){
    if(count < srow.size()){
      sum += srow[count];
      count++;
    }
    else{
      int tmp = (int)(ceil((h - sum) / m));
      count += tmp;
      sum += tmp * m;
    }
  }*/
  for(int i = 0; i < srow.size() && h > 0; i++){
    h -= srow[i];
    count++;
    if(h <= 0){
      cout << count << endl;
      return 0;
    }
  }
  count += ceil((double)h / m);
  cout << count << endl;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
vector<int> nex[114514];
int deg[114514];
int used[114514];
int dp[114514];
int zerable[114514];
signed main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		nex[x].pb(y);
		nex[y].pb(x);
		deg[x]++;
		deg[y]++;
	}
	int root = -1;
	for(int i=0;i<n;i++){
		if(deg[i] >= 3){
			root = i;
			break;
		}
	}
	if( root == -1){
		cout<<1<<endl;
		return 0;
	}
	queue<int> que;
	for(int i=0;i<n;i++){
		if( i != root && deg[i] == 1 ){
			que.push(i);
			used[i] = 1;
			zerable[i] = 1;
		}
	}
	while(!que.empty()){
		int cur = que.front(); que.pop();
		used[cur] = 1;
		vector<int> ch;
		vector<int> zer;
		for(int i=0;i<nex[cur].size();i++){
			int nx = nex[cur][i];
			if( used[nx] == 1 ){
				ch.pb(nx);
				if(zerable[nx] == 1){
					zer.pb(nx);
				}
			}
			else{
				deg[nx]--;
				if( deg[nx] == 1 && nx != root){
					que.push(nx);
				}
			}
		}
		if( ch.size() == 0){
			zerable[cur] = 1;
		}
		else if( ch.size() == 1 && zer.size() == 1){
			dp[cur] = dp[ ch[0] ];
			zerable[cur] = 1;
		}
		else if( ch.size() == 1 ){
			dp[cur] = dp[ ch[0] ];
		}
		else{
			for(int i=0;i<ch.size();i++){
				dp[cur] += dp[ ch[i] ];
			}
			int zes = zer.size();
			dp[cur] += max( 0LL, zes-1 );
		}
	}
	que.push(root);
	while(!que.empty()){
		int cur = que.front(); que.pop();
		used[cur] = 1;
		vector<int> ch;
		vector<int> zer;
		for(int i=0;i<nex[cur].size();i++){
			int nx = nex[cur][i];
			if( used[nx] == 1 ){
				ch.pb(nx);
				if(zerable[nx] == 1){
					zer.pb(nx);
				}
			}
			else{
				deg[nx]--;
				if( deg[nx] == 1 && nx != root){
					que.push(nx);
				}
			}
		}
		if( ch.size() == 1 && zer.size() == 1){
			dp[cur] = dp[ ch[0] ];
			zerable[cur] = 1;
		}
		else if( ch.size() == 1 ){
			dp[cur] = dp[ ch[0] ];
		}
		else{
			for(int i=0;i<ch.size();i++){
				dp[cur] += dp[ ch[i] ];
			}
			int zes = zer.size();
			dp[cur] += max( 0LL, zes-1 );
		}
	}
	cout<<dp[root]<<endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	ll C[3]={};
	int num=0;
	FORR(c,S) {
		if(c=='R') {
			C[0]++;
		}
		else {
			C[1]++;
		}
	}
	FOR(i,C[0]) if(S[i]=='W') C[2]++;
	
	cout<<min({N-C[0],N-C[1],C[2]})<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3724
N,M=map(int,input().split())
S=[]
C=[]
ans=[0]*N
if N>1:
	ans[0]=1
A=[]
B=[]
D=[]
for i in range (M):
	x,y=map(int,input().split())
	S.append(x)
	C.append(y)
for i in range (M):
	if S[i]==1:
		A.append(C[i])
	if S[i]==2:
		B.append(C[i])
	if S[i]==3:
		D.append(C[i])
if len(set(A))>1:
	print(-1)
	exit()
if len(set(B))>1:
	print(-1)
	exit()
if len(set(D))>1:
	print(-1)
	exit()
for i in range (M):
	ans[(S[i]-1)]=C[i]
end=0
for i in range(1,N+1):
	end+=ans[-i]*10**(i-1)
if len(str(end))!=N:
	print(-1)
else:
	print(end)

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

using namespace std;
//#define ll long long int;
vector <pair<long long int,long long int> > v;
long long int dp[105][100005];
long long int maxi(long long int w,long long int i, long long int n)
{
    if(i==n) return 0;
    if(w-v[i].first>=0)
    {
        if(dp[i][w]==-1)
        return dp[i][w]=max(v[i].second+maxi(w-v[i].first,i+1,n),maxi(w,i+1,n));
        else return dp[i][w];
    }
    else
    {
        if(dp[i+1][w]==-1)
        return dp[i+1][w]=maxi(w,i+1,n);
        else return dp[i+1][w];
    }
}
int main()
{
    memset(dp,-1,sizeof(dp));
    long long int n,w,x,y;
    cin>>n>>w;
 
    for(int i=0;i<n;i++)
    {
        cin>>x>>y;
        v.push_back({x,y});
    }
    cout<<maxi(w,0,n);
    
}

Measured memory_bytes: 85640
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t n,k;
  cin >> n >> k;
  n = (n % k);
  cout << min(abs(n),abs(k-n));
  
}
      
    

Measured memory_bytes: 256
import sys
import math
import bisect
MAX_INT = int(10e12)
MIN_NUM = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

import sys
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
a = IL()

hpop = heapq.heappop
hpush = heapq.heappush
data = []

for i in a:
    hpush(data, -i)

for i in range(M):
  tmp = math.ceil(hpop(data)/2)
  hpush(data, tmp)
  #print(data)

print(-sum(data))

Measured memory_bytes: 91928
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,ans=0;
    cin >> n;
    while(n>0){
        if(n%10==2)ans++;
        n/=10;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;

    bool ok = true;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                ok = false;
                break;
            }
        }
    }

    if(ok){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(j,a,b) for(int j = a; j < (b); j++)
using namespace std;
using ll = long long;

int main() {

	int N;
	int k = 0;
	cin >> N;
	vector<int> d(N);

	rep(i, N) {
		cin >> d[i];
		if (k - 10 > d[i]) {
			k -= 10;
		}
		else if (k - 10 <= d[i]) {
			k = d[i];
		}

		if (k < 10) {
			cout << "no" << endl;
			return 0;
		}
	}
	k = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (k - 10 > d[i]) {
			k -= 10;
		}
		else if (k - 10 <= d[i]) {
			k = d[i];
		}

		if (k < 10) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;

}


Measured memory_bytes: 3828
n = int(input())
a = [int(input()) for _ in range(n)]
max_a = max(a)
set_a = set(a)
max_n = a.count(max_a)
if len(set_a) == 1:
    s_set_a = max_a
else:
    if max_n > 1:
        s_set_a = max_a
    else:
        s_set_a = sorted(set_a)[-2]

for i in range(n):
    if max_a == a[i]:
        print(s_set_a)
    else:
        print(max_a)


Measured memory_bytes: 17320
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var N = one[0];
  var R = one[1];
  if(N >= 10){
     myout(R);
   }else{
     myout(R + (100 * (10 - N)));
   }
}

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

int main() {
	int n;
	cin>>n;
	if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9)
		cout<<"hon";
	else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
		cout<<"pon";
	else cout<<"bon";
	return 0;
}

Measured memory_bytes: 3636
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;

static int row[110];
static int sum[110];

int main(int argc, char **argv)
{
	int r, c, i, j;
	scanf("%d %d", &r, &c);
	for (i = 0; i < r; i++) {
		row[c] = 0;
		for (j = 0; j < c; j++) {
			scanf("%d", &row[j]);
			row[c] += row[j];
			sum[j] += row[j];
			printf("%d ", row[j]);
		}
		printf("%d\n", row[c]);
		sum[c] += row[c];
	}
	for (j = 0; j < c; j++) {
		printf("%d ", sum[j]);
	}
	printf("%d\n", sum[c]);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
    string S; cin >> S;
    int n;
    n = S.size();
    vector<int> ans(n);

    rep(re,2){
        {int count = 0;
        rep(i,n){
            if(S[i] == 'R') count++;
            else{
                ans[i] += count/2;
                ans[i-1] += (count+1)/2;
                count = 0; 
            }
        }
        }
        reverse(ALL(ans));
        reverse(ALL(S));
        rep(i,n){
            if(S[i] == 'R') S[i] = 'L';
            else S[i] = 'R';
        
        }
    }

    rep(i,n) printf("%d%c",ans[i],i==n-1?'\n':' ');
}

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

int main() {
  int a, b, c, d;
  cin >> a;
  b = a / 100;
  c = ( a - 100 * b ) / 10;
  d = a - 100 * b - 10 * c;
  cout << b + c + d << endl;
}

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

int main(){
    int a, i;
    string N;
    cin >> N;
    a=0;
    for(i=0;i<N.size();i++){
        if(N.at(i)==9){
            a += 9;
        }else if(N.at(i)=='8'){
            a += 8;
        }else if(N.at(i)=='7'){
            a += 7;
        }else if(N.at(i)=='6'){
            a += 6;
        }else if(N.at(i)=='5'){
            a += 5;
        }else if(N.at(i)=='4'){
            a += 4;
        }else if(N.at(i)=='3'){
            a += 3;
        }else if(N.at(i)=='2'){
            a += 2;
        }else if(N.at(i)=='1'){
            a += 1;
        }
    }
    
    if(a%9==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
  string s;
  cin >> s;
  vector<int> A,Z;
  for(int i=0;i<s.size();i++) {
    if(s[i]=='A') {
      A.push_back(i);
    }
    if(s[i]=='Z') {
      Z.push_back(i);
    }
  }
  int max=Z[Z.size()-1]-A[0]+1;
  cout << max << endl;
}

Measured memory_bytes: 1364
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);		
		int N = a.nextInt();
		int[] AArray = new int[N];
		int[] array = new int[N];
		
			for(int j = 1; j < N; j++) {
				AArray[j] = a.nextInt();
				array[AArray[j] - 1] += 1;
				
			
			}
			for(int i = 0; i < N; i++) {
			System.out.println(array[i]);
			
		}

	}
}

Measured memory_bytes: 71372
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main() {
    int total = 0;
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 3){
        rep(j, 3){
            cin >> a[i][j];
            total+=a[i][j];
        }
    }
    int c = a[0][0] + a[1][1] + a[2][2];
    if(c * 2 == total - c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//i個使ったときの最高のスコア
lli dp[1020];

void func(long long D, long long G, std::vector<long long> p, std::vector<long long> c){

    REP(i,0,1020)dp[i]=-INF;
    dp[0]=0;
    REP(i,0,D){
        vector<lli> nextDp(1020,-INF);
        nextDp[0]=0;
        REP(j,1,p[i]+1){
            REP(k,0,1020){
                if(dp[k]<0)continue;
                if(j+k>=1020)continue;
                lli score = (i+1)*j;
                if(j==p[i])score += c[i];
                chmax(nextDp[j+k],dp[k]+score);
            }
        }

        REP(j,0,1020)chmax(dp[j],nextDp[j]);
    }
    REP(i,0,1020){
        if(dp[i]>=G){
            cout<<i<<endl;
            return;
        }
    }
}

int main(){
    // cout << fixed << setprecision(5);

    long long D;
    scanf("%lld",&D);
    long long G;
    scanf("%lld",&G);
    std::vector<long long> p(D);
    std::vector<long long> c(D);
    for(int i = 0 ; i < D ; i++){
        scanf("%lld",&p[i]);
        scanf("%lld",&c[i]);
        c[i]/=100;
    }
    G/=100;
    func(D, G, std::move(p), std::move(c));
    return 0;
}


Measured memory_bytes: 256
import math
import sys
ma = 1<<53 #53ビット表現限界
while 1:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    s = list(sys.stdin.readline()[:-1])
    """aを先頭の1を含む53ビットとして保存"""
    a = 1
    for i in range(52):
        a <<= 1
        a += int(s[i])
    ans = a
    e = 0
    """「切り下げながら足し算」→「aを適時右シフトしながら和を取る」を利用"""
    while n:
        if a == 0: #aを右シフトしていった結果が0となったら終了
            break
        k = math.ceil((ma-ans)/a) #ans+ak >= maを満たす最小の整数、これ以上を足すと桁が増える
        if n < k: #もしkがnより大きかったら桁は増えないので普通に加算して終了
            ans += a*n
            break
        ans += a*k
        """以下桁が増えた時の処理、ansを右シフトして、53ビットに収める。指数部をインクリメント、桁が1増えたためaを1つ右シフト"""
        ans >>= 1
        e += 1
        a >>= 1
        """"""
        n -= k #nをk回分減少させる

    e = list(bin(e)[2:])
    for i in range(12-len(e)):
        e.insert(0,0)
    ans = list(bin(ans)[3:]) #最初の1を忘れずに削る
    for i in range(52-len(ans)):
        ans.insert(0,0)
    for i in e+ans:
        print(i,end = "")
    print()



Measured memory_bytes: 7088
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int x, y;
    cin >> x >> y;
    if (x > 0 && y > 0) {
        if (x < y) cout << y - x << endl;
        else cout << x - y + 2 << endl;
    } else if (x > 0 && y == 0) {
        cout << x + 1 << endl;
    } else if (x > 0 && y < 0) {
        cout << abs(abs(x) - abs(y)) + 1 << endl;
    } else if (x == 0 && y > 0) {
        cout << y << endl;
    } else if (x == 0 && y == 0) {
        // noop
        cout << 0 << endl;
    } else if (x == 0 && y < 0) {
        cout << abs(y) + 1 << endl;
    } else if (x < 0 && y > 0) {
        cout << abs(abs(x) - abs(y)) + 1 << endl;
    } else if (x < 0 && y == 0) {
        cout << abs(abs(x) - abs(y)) << endl;
    } else if (x < 0 && y < 0) {
        if (x <= y) cout << abs(y - x) << endl;
        else cout << abs(x - y) + 2 << endl;
    }
}



Measured memory_bytes: 256
N, M = map(int, input().split())
Edge = [tuple(map(int, input().split())) for _ in range(M)]

Graph = [[] for _ in range(N)]
for a,b in Edge:
    Graph[a-1].append(b-1)
    Graph[b-1].append(a-1)

seen = set()
def dfs(v):
    global Graph, seen
    seen.add(v)
    if len(seen) == N:
        seen.remove(v)
        return 1
    Res = [dfs(nv) for nv in Graph[v] if not nv in seen]
    seen.remove(v)
    return sum(Res)

print(dfs(0))

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

#define N 1000001

bool pri[N];

void pn(){
    pri[0]=pri[1]=true;
    for(int i=2;i*i<N;i++){
        if(pri[i])continue;
        for(int j=2*i;j<N;j+=i){
            pri[j]=true;
        }
    }
}

int main(){
    int a,d,n,cou;
    pn();
    while(cin >> a >> d >> n,n){
        cou=0;
        for(int i=a;;i+=d){
            if(!pri[i]){
                cou++;
            }
            if(cou==n){
                cout << i << endl;
                break;
            }
        }
    }

}



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

h = (0, S[0])
t = (0, S[0])
k = 1 if S[0] == '0' else 0
max_handstands = 1
current_handstands = 1
while True:
    if h[0] == N-1 and t[0] == N-1:
        break
    # kを維持したままtを進める
    elif t[0] < N-1 and not (t[1] == '1' and S[t[0]+1] == '0'):
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    # kを増やしてtを進める
    elif t[0] < N-1 and k < K and S[t[0]+1] != t[1]:
        k += 1
        t = (t[0]+1, S[t[0]+1])
        current_handstands += 1
    # kを維持したままhを進める
    elif not (h[1] == '0' and S[h[0]+1] == '1') and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    # kを減らしてtを進める
    elif S[h[0]+1] != h[1] and h[0] < t[0]:
        max_handstands = max(max_handstands, current_handstands)
        k -= 1
        h = (h[0]+1, S[h[0]+1])
        current_handstands -= 1
    else:
        raise

print(max_handstands)


Measured memory_bytes: 3316
A, B, C, K = map(int, input().split())

Total=()

if K<=A:
      print(K*1)
else:
      Total = A

K=K-A

if K<=B and K>0:
      print(Total)

K=K-B

if K<=C and K>0:
      Total = Total + (K*-1)
      print(Total)

Measured memory_bytes: 9192
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>

using namespace std;

#define trace(...) __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 long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int DIV = 1e6;

vector<int> factorize(long long n) {
  int i = 2;
  vector<int> res;
  for (long long i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      res.push_back(i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n > 2) {
    res.push_back(n);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  int res = 1;
  cin >> n >> m;
  auto a = factorize(n);
  auto b = factorize(m);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int i = 0;
  int j = 0;
  while (i < a.size() && j < b.size()) {
    if (a[i] == b[j]) {
      ++res;
      ++i;
      ++j;
    } else if (a[i] < b[j]) {
      ++i;
    } else {
      ++j;
    }
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repb(i, n) for (int i = (int)n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define repsb(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;

    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    VSORT(v);
    cout << abs(v[0] - v[n - 1]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
long long int Q, H, S, D, N; 
cin >> Q >> H >> S >> D >> N;
long long int M; 
M = min(Q * 2, H); 
long long int K; 
K = min(M * 2, S); 
if(K * 2<= D){
cout << K * N << endl; 
}
else if(N % 2 == 1){
cout << (N - 1)/2 * D + K << endl;
} 
else{
cout << N/2 * D << endl;
}
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
for i in range(k, n + 2):
    mi = i * (i - 1) // 2
    ma = i * (2 * n - i + 1) // 2
    ans += ma - mi + 1
print(ans % mod)

Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for (int i = 0; i < 5; i++) {
            if (sc.nextInt() == 0) {
                System.out.println(i + 1);
                return;
            }
        }

    }
}


Measured memory_bytes: 35840
S = input()
Q = int(input())
QUERY = []
for i in range(Q):
    q = input().split()
    QUERY.append(q)

from collections import deque

l = deque(list(S))
# print(l)

rev = 0
for qi in QUERY:
    if qi[0] == '1':
        rev += 1
    else:
        if rev % 2 == 0:
            if qi[1] == '1':
                l.appendleft(qi[2])
            else:
                l.append(qi[2])
        else:
            if qi[1] == '1':
                l.append(qi[2])
            else:
                l.appendleft(qi[2])

# print(l)
ans = "".join(l)
# print(ans)
if rev % 2 != 0:
    ans = ans[::-1]

print(ans)

Measured memory_bytes: 44644
#include <stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d", a + b + c + 9 * MAX(a, MAX(b, c)));
	return 0;
}


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

int s[15], n;
ll ans=0;

void dfs(int i, ll sum, ll now) {
  if(i==n-1) ans += sum+now;
  else{
    dfs(i+1, sum+now, s[i+1]);
    dfs(i+1, sum, now*10+s[i+1]);
  }
}

int main(){
  string str; cin >> str;
  n = str.size();
  rep(i,n) s[i]=str.at(i)-'0';
  dfs(0,0,s[0]);
  cout << ans;
}

Measured memory_bytes: 256
n = int(input())
h = [list(map(int,input().split()))for _ in range(n)]

x = []*n
y = []*2

ans = 0

for i in range(n):
  y.append(h[i][0]-h[i][1]) #腕が届く地点の最小値
  y.append(h[i][0]+h[i][1]) #腕が届く地点の最大値
  x.append(y) #xに保存
  y = []*2 #yを初期化

x.sort(key = lambda x:x[1]) #腕が届く地点の最大値が小さい順にソート

con = -10 ** 10

for i in range(n):
  if con <= x[i][0]:
    ans += 1
    con = x[i][1]

print(ans)

Measured memory_bytes: 43384