akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

long long int llpow(long long int a, long long int b){
    long long int res = 1;
    for(long long int i = 0; i<b; i++){
        res *= 10;
    }

    return res;
}


int main(){
    long long int N;
    scanf("%lld", &N);

    if(N == 1000000000){
        printf("Yes\n");
    }else{
        long long int res = 0;
        long long int one = 1;
        long long int nine = 9;
        long long int ten = 10; 
        for(long long int i=0; i<nine; i+=one){
            long long int hoge = llpow(ten, i);
            if(hoge > N){
                ;
            }else{
                res += (N / hoge) % ten;
            }
        }

        long long int zero = 0;
        if(N % res == zero){
            printf("Yes\n");
        }else{
            printf("No\n");
        }

        return 0;
    }
}


Measured memory_bytes: 128
//*****************************believer******************************//
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef map<ll,ll> mi;
 
#define f first
#define ss second
#define ins insert
#define pb push_back
#define lb lower_bound 
#define ub upper_bound 
#define pq priority_queue
#define sqr(n) floor(sqrt(n))
#define sz(v) ((ll)(v.size()))
#define trav(a,x) for (auto& a: x)
#define all(v) (v).begin(),(v).end()
#define arl(v) (v).rbegin(),(v).rend()
#define mem(a) memset(a, -1, sizeof (a))
#define ssort(v) sort((v).begin(),(v).end())
#define rsort(v) sort((v).rbegin(),(v).rend())
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define vmn(a) (*min_element(a.begin(),a.end()))
#define vmx(a) (*max_element(a.begin(),a.end()))
#define foo(i,a,b) for (ll i = (a); i < (b); ++i)
#define foor(i,a,b) for (ll i = (a); i >= (b); --i)

const ll N=1e5+10;
ll c[N];
vi a;

ll solve(ll x)
{
    if(c[x]!=-1)
    return c[x];
    
    return c[x]=min(solve(x-1)+abs(a[x]-a[x-1]),solve(x-2)+abs(a[x]-a[x-2]));
}

int main()
{
        ll n;
        cin>>n;
        vi b(n);
        a=b;
        mem(c);
        foo(i,0,n)
        cin>>a[i];
        
        c[0]=0;
        c[1]=abs(a[1]-a[0]);
        ll ans=solve(n-1);
        cout<<ans<<"\n";
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int i = 0;
    rep(i, n) {
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    i = 0;
    rep(i, n-1) { 
        if (vec[i] == vec[i+1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

int main() {
  long long int N,A,B,output;
  
  cin >> N >> A >> B;
  if( N % (A+B) <= A)
    output = A*(N/(A+B)) + N % (A+B);
  else
    output = A*(N/(A+B)) + A;
  
  cout << output << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
int N, K;
  cin >>N >> K;
  if(500*N < K)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }
template<typename T>
void fin(std::vector<T>const& t, char delim=' '){
  if(t.size() > 0) {
    for(int i = 0; i < t.size() -1; ++i) std::cout << t[i] << delim;
    std::cout << t.back();
  }
  std::cout << std::endl; 
  exit(0);
}

int const MAXN = 2e5;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N; int64_t K; std::cin >> N >> K;
  std::vector<int> A(N+N);
  for(int i = 0; i < N; ++i) { std::cin >> A[i]; A[N+i] = A[i]; }
  std::vector<int> prev(MAXN+1, -1);
  std::vector<int> sk(N);
  for(int i = 0; i < N+N; ++i) {
    int p = prev[A[i]];
    if(0 <= p && p < N) sk[p] = i-p+1;
    prev[A[i]] = i;
  }
  std::vector<int64_t> sum({0});
  std::fill_n(prev.begin(), N, -1);
  prev[0] = 0;
  int b;
  for(;;) {
    int64_t nx = sum.back();
    nx += sk[nx%N];
    if(prev[nx%N] >= 0) {
      b = prev[nx%N];
      sum.push_back(nx);
      break;
    }
    prev[nx%N] = sum.size();
    sum.push_back(nx);
  }
  int64_t l = K*N;
  if(l >= sum[b]) {
    l -= sum[b];
    int64_t p = sum.back() - sum[b];
    l %= p;
    auto it = std::upper_bound(sum.begin(), sum.end(), l+sum[b]);
    if(it != sum.begin()) l -= *(it-1) - sum[b];
  } else {
    l -= *(std::upper_bound(sum.begin(), sum.end(), l)-1);
  }
#if 1
  int ans = -1;
  l = N-l;
  while(l < N) {
    if(l + sk[l] > N) {
      if(ans >= 0) std::cout << ans << " ";
      ans = A[l];
      ++l;
    } else l += sk[l];
  }
  if(ans >= 0) std::cout << ans;
  std::cout << std::endl;
#else 
  std::vector<int> ans;
  std::fill_n(prev.begin(), MAXN+1, -1);
  for(int i = N-l; i < N; ++i) {
    if(prev[A[i]] < 0) {
      prev[A[i]] = ans.size();
      ans.push_back(A[i]);
    } else {
      int nsz = prev[A[i]];
      while(ans.size() > nsz) {
        prev[ans.back()] = -1;
        ans.pop_back();
      }
    }
  }
  fin(ans);
#endif
  return 0;
}


Measured memory_bytes: 6384
//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_a"
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func iabs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func solve(n int, heights []int) int {
	t := make([]int, n+1, n+1)
	for i := range t {
		t[i] = math.MaxInt64
	}

	t[0] = 0
	for i := 1; i < n; i++ {
		if v := t[i-1] + iabs(heights[i]-heights[i-1]); v < t[i] {
			t[i] = v
		}
		if 1 < i {
			if v := t[i-2] + iabs(heights[i]-heights[i-2]); v < t[i] {
				t[i] = v
			}
		}
	}

	return t[n-1]
}

func main() {
	sc := newScanner(os.Stdin)
	n := sc.Int()
	heights := sc.IntSlice(n)
	ans := solve(n, heights)
	fmt.Println(ans)
}


Measured memory_bytes: 3784
/*
ID: varunra2
LANG: C++
TASK: c
*/

#include<bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions


int main() {
#ifndef ONLINE_JUDGE
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif
  cin.sync_with_stdio(0); cin.tie(0);

  int n;
  cin >> n;

  VI vals(n);

  for(int i= 0; i < n; i++) {
    cin >> vals[i];
  }

  int mx = vals[0];
  ll ret = 0;

  for(int i = 1; i < n; i++) {
    ret += max(0, mx - vals[i]);
    mx = max(mx, vals[i]);
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 3916
#include <stdio.h>
#include <algorithm>
typedef long long LL;
using namespace std;
const int maxn = 1e5+5;
int N;
int a[maxn],b[maxn],sum[maxn],bit[maxn*2+1];
int lowbit(int x){return x&-x;}
void add(int x,int v){for(;x<=2*N+1;x+=lowbit(x)) bit[x]+=v;}
int getsum(int x)
{
    int res=0;
    for(;x;x-=lowbit(x)) res+=bit[x];
    return res;
}


bool judge(int x)
{
    sum[0]=N+1; // sum最小可能是-N+1
    for(int i=1;i<=N;i++) sum[i]=sum[i-1]+(a[i]>=x?1:-1);//前缀和
    for(int i=1;i<=2*N+1;i++) bit[i]=0; //初始化树状数组
    //由于是前缀和形式，要包括所有的区间，必然要加上sum[0]
    add(sum[0],1);
    LL cnt=0; // 正序对数量，即区间和>=0
    for(int i=1;i<=N;i++)
    {
        cnt+=getsum(sum[i]);
        add(sum[i],1);
    }
    return cnt >= 1LL*(N+1)*N/4;
}



int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]),b[i]=a[i];
    // n*(n-1)/2个区间
    sort(b+1,b+1+N);
    int l=1,r=N,mid,ans;
    while(l<=r)
    {
        mid = l+(r-l)/2;
        if(judge(b[mid])) ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d",b[ans]);
	return 0;
}

/*
二分
假如只在一个序列中找中位数
即是说找到最大的x使得"大于等于x的数至少有n/2个"，它就是中位数

现在要转换为"有多少个区间的中位数大于等于x"
假如这个x是题设的"中中位数"
那么就会有至少N/2个区间的中位数大于等于x(N是区间数)
我们想办法求出有多少个区间的中位数小于x、大于等于x，分别记为p1,p2

如若p2>=N/2，即是说可能是答案，那么我们不断二分扩大即可
反之缩小

怎么与昂求出p1，p2，我们直接让大于等于x的数为1，小于的为-1，那么前缀和sum[r]-sum[l]<=0就p2++
*/


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>

using namespace std;

#define gettime printf("\nTime : %0.3lf\n",clock()*1.0/CLOCKS_PER_SEC);
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repp(i,a,b) for(int i=a;i>=b;i--)
#define Set(x,a) memset(x,a,sizeof(x));

#define vs vector<string>
#define vi vector<int>
#define ll long long
#define ff first
#define ss second

struct comp {
       bool operator() (int a,int b) {
            return a>b;
       }
};

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    int n, l, r, m;
    bool seat0man, seatMman;
    string data;
    scanf("%d", &n);
    l = 0;
    r = n - 1;
    cout<<"0"<<endl;
    cin>>data;
    if (data[0] == 'V') return 0;
    if (data[0] == 'M') seat0man = true;
    else seat0man = false;
    int x = 1;
    while (x < 20) {
        x++;
        m = (l + r) / 2;
        cout<<m<<endl;
        cin>>data;
        if (data[0] == 'V') return 0;
        if (data[0] == 'M') seatMman = true;
        else seatMman = false;
        if ((m % 2 == 0 && seatMman == seat0man) || (m % 2 == 1 && seatMman == !seat0man)) {
            l = m + 1;
        }
        else r = m;
    }
    return 0;
}


Measured memory_bytes: 852
#include <iostream>

using namespace std;

int main()
{
  int N;
  int hist[9] = { };

  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a < 3200) hist[a/400]++;
    else hist[8]++;
  }

  int sum = 0;
  for (int i = 0; i < 8; i++) {
    if (hist[i] > 0) sum++;
  }
  if (sum == 0) cout << 1 << ' ';
  else cout << sum << ' ';
  
  cout << sum + hist[8] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int b1, b2, b3;
    cin >> b1 >> b2 >> b3;
    if((b1 == 1 && b2 == 1) || b3 == 1){
        cout << "Open" << endl;
    }
    else{
        cout << "Close" << endl;
    }
}



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

const int mod = 1000000007;

int main(){
    int n; cin >> n;
    ll ans = 1;
    vector<int> flag(n);
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        flag[mid]++;
        if(flag[mid] > 2){
            cout << 0 << endl;
            return 0;
        }
    }
    if(n % 2 == 0 && flag[0] != 0){cout << 0 << endl; return 0;}
    for(int i = 0; i < n; i++){
        if(flag[i] == 2){
            ans = ans * 2 % mod;
        }else if(flag[i] == 1 && i != 0){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

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


int main(){
    ll q, h, s, d;
    cin>>q>>h>>s>>d;
    ll n;
    cin>>n;
    cout<<(n/2) * min(min(8 * q, 4 * h),min(2*s, d)) + (n% 2)*min(min(4*q, 2*h), s)<<endl;
}



Measured memory_bytes: 256
def match(a,b):
    for i in range(len(b)):
        if a == b[i:i+len(a)]:
            return(True)
    return(False)

pat = {'A':[1,1]+[0]*6+[1,1],
       'B':([1]+[0]*7)*3+[1],
       'C':[1]*4,
       'D':[1]+[0]*6+[1,1]+[0]*6+[1],
       'E':[1,1]+[0]*7+[1,1],
       'F':[1]+[0]*7+[1,1]+[0]*7+[1],
       'G':[1,1]+[0]*5+[1,1]}

while True:
    try:
        pla = []
        for _ in range(8):
            l = input().strip()
            pla += map(int,list(l))

        for i in ['A','B','C','D','E','F','G']:
            if match(pat[i],pla):
                print(i)
        input()
    except EOFError:
        break

Measured memory_bytes: 7636
A, B = map(int, input().split())
S = input()

if "-" not in S:
    print("No")
elif S.count("-") > 1:
    print("No")
else:
    a,b = S.split("-")
    if (len(a) == A) and (len(b)==B):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
int abss(int a)
{
	return a>0?a:-a;
}
int main()
{
	int i,a[1010],ans,flag=10007;
	char s[1010];
	scanf("%s",s);
	int n=strlen(s);
	for(i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
		//printf("%d...",a[i]);
	}
	for(i=2;i<n;i++)
	{
		ans=abss((a[i]+a[i-1]*10+a[i-2]*100)-753);
		//printf(",,,%d,,,",ans);
		if(ans<flag) flag=ans;
	}
	printf("%d\n",flag);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll h,n; cin>>h>>n;
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];

    vector<ll> dp(h+1,LINF);
    dp[0] = 0;

    rep(i,h) {
        rep(j,n) {
            chmin(dp[min(i+a[j],h)], dp[i]+b[j]);
        }
    }
    cout << dp[h] << '\n';
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int x, y, z; cin >> x >> y >> z;
  cout
    << z << SPACE
    << x << SPACE
    << y << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
line = gets.split(' ').map(&:to_i)

a = line[0]
b = line[1]

i = 2
while i < 200000 do
  if a % i == 0 and b % i == 0 then
    a /= i
    b /= i
  else
    i += 1
  end
end
  
print a * line[1]

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> ks(m);
    vector<int> p(m);
    rep(i, m)
    {
        int k;
        cin >> k;
        ks[i].resize(k);
        rep(j, k) cin >> ks[i][j];
    }
    rep(i, m) cin >> p[i];

    int ans = 0;
    for (int bit = 0; bit < (1 << n); ++bit)
    {
        bool isOK = true;
        rep(i, m)
        {
            int count = 0;
            for (int ksbit : ks[i])
                if (bit & (1 << (ksbit - 1)))
                    ++count;
            if (count % 2 != p[i])
            {
                isOK = false;
                break;
            }
        }
        if (isOK)
            ++ans;
    }

    cout << ans << endl;
}

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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif
const int N = 3005;
int dp[N][N];
const int mod = 998244353;

inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
	int x = 1 % mod;
	while(b){
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

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

	for(int i = A; i <= C; i++) for(int j = B; j <= D; j++){
		if(i == A && j == B){
			dp[i][j] = 1;
			continue;
		}
		dp[i][j] = add(mul(j, dp[i - 1][j]), mul(i, dp[i][j - 1]));
		dp[i][j] = sub(dp[i][j], mul((i-1)*(j-1), dp[i - 1][j - 1]));
	}
	cout << dp[C][D] << endl;
}

Measured memory_bytes: 38848
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// Range系のライブラリ
struct RangeIterator {
	ll v;
	const ll operator*() { return v; }
	RangeIterator& operator++() { ++v; return *this; }
	bool operator!=(const RangeIterator& rhs) { return v != rhs.v; }
};
template<bool INCLUSIVE> struct EndType {};
template<> struct EndType<false> {
	ll end;
	ll operator()() { return end; }
};
template<> struct EndType<true> {
	ll end;
	ll operator()() { return end + 1; }
};
template<bool INCLUSIVE>
struct Range {
	ll s; EndType<INCLUSIVE> e;
	Range(ll end) : s(0), e(EndType<INCLUSIVE>{end}) {}
	Range(ll start, ll end) : s(start), e(EndType<INCLUSIVE>{end}) {}
	RangeIterator begin() { return { s }; }
	RangeIterator end() { return { e() }; }
};
inline Range<false> range(ll start) { return Range<false>(start); }
inline Range<false> range(ll start, ll end) { return Range<false>(start, end); }
inline Range<true> irange(ll start) { return Range<true>(start); }
inline Range<true> irange(ll start, ll end) { return Range<true>(start, end); }

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T & container, typename T::key_type & key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法
ll N, A, B, C, D;
string S;

int main(void) {
	std::ios_base::sync_with_stdio(false);

	cin >> N >> A >> B >> C >> D;
	S.resize(N + 1);
	for (ll i = 1; i <= N; ++i) cin >> S[i];

	bool snuke = true;
	bool funuke = true;

	for (ll i = A + 1; i <= C; ++i)
		if (S[i] == '#' && S[i - 1] == '#') snuke = false;

	for (ll i = B + 1; i <= D; ++i)
		if (S[i] == '#' && S[i - 1] == '#') funuke = false;

	if (C > D)
	{
		bool swap = false;
		for (ll i = B; i <= D; ++i)
		{
			if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') swap = true;
		}
		cout << ((snuke && funuke && swap) ? "Yes" : "No") << endl;
	}
	else
	{
		cout << ((snuke && funuke) ? "Yes" : "No") << endl;
	}

	return 0;
}


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

Measured memory_bytes: 3648
#include <stdio.h>

int sum_up(int x);

int main(void) {
  int n, a, b, min = 100000, sum;

  scanf("%d", &n);

  for (a = 1; a < n; a++) {
    b = n - a;
    sum = sum_up(a) + sum_up(b);
    if (min > sum) {
      min = sum;
    }
  }

  printf("%d\n", min);
  return 0;
}

int sum_up(int x) {
  int one, ten, hundred, thousand, ten_thousand, hundred_thousand, wa;
  one = x % 10;
  ten = (x / 10) % 10;
  hundred = (x / 100) % 10;
  thousand = (x / 1000) % 10;
  ten_thousand = (x / 10000) % 10;
  hundred_thousand = x / 100000;

  wa = one + ten + hundred + thousand + ten_thousand + hundred_thousand;
  return wa;
}


Measured memory_bytes: 128
#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#define Max 0x3F3F3F

#define ll long long
#define MODD 1000000007
#define  pii  pair<int,int>

#include<stdio.h>
#include<queue>
//#include<bits/stdc++.h>
using namespace std;
char ch[10000];

int main() {
    cin>>ch;
    if(ch[2]=='T')cout<<1<<endl;
    else if(ch[2]=='I')cout<<2<<endl;
    else if(ch[2]=='U')cout<<3<<endl;
    else if(ch[2]=='D')cout<<4<<endl;
    else if(ch[2]=='E')cout<<5<<endl;
    else if(ch[2]=='N'&&ch[0]=='M')cout<<6<<endl;
    else cout<<7<<endl;

    return 0;
}
/*
5 300
4 200
4 100
3 156
3 44
2 100
*/


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int W,H,N;
	scanf("%d %d %d",&W,&H,&N);
	int realm[W][H];
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			realm[i][j]=1;
		}
	}
	int x,y,a;
	while(scanf("%d %d %d",&x,&y,&a)!=EOF){
		for(int i=0;i<W;i++){
			for(int j=0;j<H;j++){
				if((i<x&&a==1)||(i>=x&&a==2)||(j<y&&a==3)||(j>=y&&a==4)){
					realm[i][j]=0;
				}
			}
	}
	}
	int sum = 0;
	for(int i=0;i<W;i++){
		for(int j=0;j<H;j++){
			sum += realm[i][j];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);

  string s; cin >> s;

  //ll ans = 0;
  string ans = "";

  rep(i, s.size()){
    ans += "x";
  }
  
  cout << ans << endl;
  

  return 0;
}
//

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>


int main(int argc, char* argv[])
{
    long a, b;
    scanf("%ld %ld", &a, &b);

    printf("%d\n", a - b + 1);

    return 0;
}


Measured memory_bytes: 128
n = int(input())
s = "aaa"
for i in range(n):
  d1 , d2 = map(int,input().split(" "))
  if d1 == d2:
    s += "b"
  else:
    s += "c"

if "bbb" in s:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9100
h, w, k = map(int, raw_input().split())
b = [[0] * w for i in xrange(h)]
c = "YGBR"
for i in xrange(h):
    for j in xrange(w):
        b[i][j] = c[(i+j)/k%2+(i-j)/k%2*2]
    print "".join(b[i])


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

bool travel(int n, vector<int> t, vector<int> x, vector<int> y){
    rep(i,n){
        if(t[i+1]-t[i]<(x[i+1]-x[i]+y[i+1]-y[i])){
            return false;
            break;
        }
        if(((t[i+1]-t[i])%2 == 0 && (x[i+1]-x[i]+y[i+1]-y[i]) % 2 !=0) || ((t[i+1]-t[i])%2 != 0 && (x[i+1]-x[i]+y[i+1]-y[i]) % 2 ==0)){
            return false;
            break;
        }
    }
    return true;
}

int main() {
    int n; cin >> n;
    vector<int> t;
    vector<int> x;
    vector<int> y;
    t.push_back(0);
    x.push_back(0);
    y.push_back(0);
    rep(i,n){
        int a,b,c;
        cin >> a; t.push_back(a);
        cin >> b; x.push_back(b);
        cin >> c; y.push_back(c);
    }
    if(travel(n, t, x, y)) cout << "Yes";
    else cout << "No";
    
}

Measured memory_bytes: 2796
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  -- 1 <= n <= 300, 1 <= k <= 10^5
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  -- 1 <= a1 < a2 < ... < an <= k
  let vec = U.constructN (k + 1) $
        \vec -> let !i = U.length vec
                in not $ U.and $ U.map (\x -> vec U.! (i - x)) $ U.takeWhile (<= i) xs
  putStrLn (if U.last vec then "First" else "Second")


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

struct shop {
	int id;
	string name;
	int point;

	bool operator<(const shop & rhs) {
		if (this->name == rhs.name) {
			return this->point > rhs.point;
		}
		return this->name < rhs.name;
	}

};

int main() {

	int n;
	cin >> n;
	vector<shop> test = vector<shop>(n);
	
	for (size_t i = 0; i < n; i++) {
		test[i].id = i + 1;
		cin >> test[i].name >> test[i].point;
	}

	sort(test.begin(), test.end());
	for (size_t i = 0; i < n; i++) {
		cout << test[i].id << endl;
	}

	return 0;
}


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

int main()
{
	unsigned long long L = 0, R = 0;

	std::cin >> L >> R;

	unsigned long long ans = 2019;

	unsigned long long A = 0, B = 0, C = 0;
	
	if (R - L + 1 >= 2019)
	{
		ans = 0;
		std::cout << ans << std::endl;
		return 0;
	}

	for (A = L; A < R; A++)
	{
		for (B = A + 1; B <= R; B++)
		{
			C = (A *B) % 2019;
			ans = std::min(ans, C);
			if (ans == 0)break;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

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

int main()
{
    int N,K;
    cin >> N >> K;
    string s;
    cin >> s;
    int total = 0;
    for(int i = 0; i < N-1; i++){
        if(s[i] == s[i+1]) total++;
    }
    cout << min(N-1,total+(2*K)) << "\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
vector<pair<string,long>> solve(long N){
  if(N==1)return vector<pair<string,long>>(1,pair<string,long>("a",1));
  vector<pair<string,long>>v=solve(N-1);
  vector<pair<string,long>>ans;
  for(auto p:v){
    for(long i=0;i<p.second+1;i++)
      ans.push_back(pair<string,long>(p.first+(char)('a'+i),p.second+(i==p.second)));
  }
  return ans;
}
int main(){
  long N;cin>>N;
  vector<pair<string,long>>L=solve(N);
  sort(L.begin(),L.end());
  for(auto s:L)cout<<s.first<<endl;
}



Measured memory_bytes: 10080
from fractions import gcd

N, X = map(int, input().split()) # 横に2個
A = list(map(int, input().split()))
A.append(X)

A.sort()

D = [A[i+1]-A[i] for i in range(N)]

ans = D[0]
for d in D:
    ans = gcd(ans, d)

print(ans)

Measured memory_bytes: 16284
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int N;
	cin >> N;

	vector<int>a(N);

	REP(i, N)cin >> a[i];

	if (N == 1 && a[0] == 1) {
		cout << 0 << endl;
		return 0;
	}

	int cnt = 1;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (a[i] == cnt) {
			ans++;
			cnt++;
		}
	}

	if(ans>0)cout << N - ans << endl;
	else cout << -1 << endl;

	return 0;

}

Measured memory_bytes: 1024
while 1:
    before_convert = input().split()

    era = before_convert[0]
    
    if era == "#":
        exit()
    
    heisei_year = int(before_convert[1])
    month = int(before_convert[2])
    day = before_convert[3]

    if heisei_year <= 30:
        era = "HEISEI"
        year = heisei_year
    elif heisei_year == 31:
        if month < 5:
            era = "HEISEI"
            year = heisei_year
        else:
            era = "?"
            year = 1
    else:
        era = "?"
        year = heisei_year - 30

    print("{0} {1} {2} {3}".format(era, year, month, day))




Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int a, b, c;
	int x = 0, y = 0;
	
	cin>>a>>b>>c;
	
	x = c - (a + b);
	
	y = a * b;
	
	for(int i = 1; i * i <= y; i++){
		if(i * i == y) {
			y = i;
			break;
		}
	}
	
	// cout<<y<<" "<<a*b<<endl;
	
	if(2 * y == x) cout<<"No"<<endl;
	else {
		long double A, B, C;
		A = sqrt((long double)a);
		B = sqrt((long double)b);
		C = sqrt((long double)c);
		
		if(A+B<C) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    long long n, m;
    cin >> n >> m;

    long long cnt = 0;
    if (n > m)
        swap(n, m);

    if (n == 1) {
        if(m == 1){
            cnt = 1;
        }
        else{
            cnt = m - 2;
        }
    }
    else if(n == 2){
        cnt = 0;
    }
    else{
        cnt = (n-2) * (m-2);
    }

    cout << cnt << endl;



    return 0;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int N, vector<int>& xs)
{
    sort(xs.begin(), xs.end());

    int ans = 0;

    for (int i = 0; i < N; ++i)
        for (int j = i + 1; j < N; ++j)
            for (int k = j + 1; k < N; ++k)
                if (xs[i] != xs[j] and xs[i] != xs[k] and xs[j] != xs[k] and xs[i] + xs[j] > xs[k])
                    ++ans;

    return ans;
}

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

    int N;
    cin >> N;

    vector<int> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    auto ans = solve(N, xs);

    cout << ans << '\n';

    return 0;
}


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

#define ll long long

ll dp[101][100005];
ll n, k, arr[101];
// 0 - winner is taro
// 1 - winner is jiro

void solve()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	//memset (dp, -1, sizeof dp);
	for (ll stones = 0; stones <= k; stones++) {
		for (int turn = 0; turn < 2; turn++) {
			if (turn == 0) {
				dp[turn][stones] = 1;
			}
			else {
				dp[turn][stones] = 0;
			}
			for (int i = 0; i < n; i++) {
				if (stones - arr[i] < 0) {
					//dp[turn][stones] = !turn;
					continue;
				}
				if (turn == 0) {
					ll ans = dp[!turn][stones - arr[i]];
					if (ans == 0) {
						dp[turn][stones] = 0;
					}
				}
				else {
					dp[turn][stones] = dp[turn][stones] || dp[!turn][stones - arr[i]];
				}
			}

			//cout << "turn = " << turn  << " stones = " << stones << "val = " << dp[turn][stones] << "\n";
		}
	}

	ll ans = dp[0][k];
	if (ans == 0) {
		cout << "First";
	}
	else {
		cout << "Second";
	}


}

int32_t main()
{
	solve();
	return 0;
}


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

int main ()
{
	int a,b,c;
	int n;
	scanf ("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf ("%d%d%d",&a,&b,&c);
		if (a==0||b==0||c==0)
		printf ("NO\n"); 
		else
		{
			if (((pow(a,2)+pow(b,2))==pow(c,2))||((pow(a,2)+pow(c,2))==pow(b,2))||((pow(c,2)+pow(b,2))==pow(a,2)))
		    printf ("YES\n");
		    else
		    printf ("NO\n"); 
		}
	}
	return 0;
}

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

string s;
int dp[303][303][303];

int solve(int a, int b, int k) {
	if(dp[a][b][k] < 0) {
		dp[a][b][k] = 0;
		if(a > 0) {
			dp[a][b][k] = max(dp[a][b][k], solve(a - 1, b, k));
		}
		if(b > 0) {
			dp[a][b][k] = max(dp[a][b][k], solve(a, b - 1, k));
		}
		if(a > 0 && b > 0) {
			if(s[a - 1] == s[s.size() - b]) {
				dp[a][b][k] = max(dp[a][b][k], solve(a - 1, b - 1, k) + 1);
			}
			if(k > 0) {
				dp[a][b][k] = max(dp[a][b][k], solve(a - 1, b - 1, k - 1) + 1);
			}
		}
	}
	return dp[a][b][k];
}

signed main() {
	cin >> s;
	int k;
	cin >> k;
	rep(i, s.size() + 2) {
		rep(j, s.size() + 2) {
			rep(k, s.size() + 2) {
				dp[i][j][k] = -1;
			}
		}
	}
	int ans = 1;
	rep(i, s.size()) {
		ans = max(ans, solve(i, s.size() - i, k) * 2);
	}
	rep(i, s.size() - 1) {
		ans = max(ans, solve(i, s.size() - i - 1, k) * 2 + 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 108928
N = int(input())
sintyo_list = list(map(int,input().split()))
ans = 0

for i in range(N-1):
    if sintyo_list[i+1] < sintyo_list[i]:
        ans += sintyo_list[i] - sintyo_list[i+1]
        sintyo_list[i+1] = sintyo_list[i]
print(ans)


Measured memory_bytes: 105156
x,y=gets.split.map(&:to_i)
xx=x.abs
yy=y.abs
if(y>0)
  if(x>0)
    if(yy>=xx)
      puts y-x+(x.zero?? -1 : 0)
    else
      puts x-y+2+(x.zero?? -1 : 0)
    end
  else
    if(yy>=xx)
      puts y+x+1+(x.zero?? -1 : 0)
    else
      puts -x-y+1+(x.zero?? -1 : 0)
    end
  end
else
  if(x>0)
    if (yy>xx)
      puts -x-y+1+(x.zero?? -1 : 0)
    else
      puts x+y+1+(x.zero?? -1 : 0)
    end
  else
    if(yy>xx)
      puts -y+x+2+(x.zero?? -1 : 0)
    else
      puts -x+y+(x.zero?? -1 : 0)
    end
  end
end


Measured memory_bytes: 1788
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto& it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[i])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007
#define bitc __builtin_popcountll


#ifdef ROBOT
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (double)(clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n";

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define end_routine()
#define trace(...) 
#endif

void splitx(string s, char c, vector<string> &v){
    int i=0, j;
    while(i<sz(s)){
        j=i; string temp;
        while(j<sz(s) && s[j]!=c){temp+=s[j]; j++;}
        v.pb(temp); i=j+1;
    }
}

/*################################ ¯\_(ツ)_/¯ ################################*/

int n, m;
vvi adj(MAXN);
vi vis(MAXN, 0);
vi len(MAXN, 0);

void dfs(int s){
	vis[s]=1;
	len[s]=1;
	int val=0;
	trav(adj[s]){
		if(vis[it]==0) dfs(it);
		val = max(val, len[it]);
	}
	len[s]+=val;
	trace(s, val, len[s]);
}

signed main(){
    fast
    #ifdef ROBOT
        freopen("/home/yell0wfl4sh/Competitive/input.txt", "r", stdin);
        freopen("/home/yell0wfl4sh/Competitive/output.txt", "w", stdout);
    #endif
    
    cin>>n>>m;
    int a, b;
    For(i, 0, m){
    	cin>>a>>b;
    	adj[a].pb(b);
    }
    For(i, 1, n+1){
    	if(!vis[i]) dfs(i);
    }
    int ans = 0;
    For(i, 1, n+1){
    	ans = max(ans, len[i]);
    	// cout<<len[i]<<endl;
    }
    ans--;
    cout<<ans<<endl;


    end_routine()
    return 0;
}



Measured memory_bytes: 17792
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<bitset>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define INF 0X3F3F3F3F
#define N 100010
#define M 2000005
#define LL long long
#define FF(i,a,b) for(int i=a;i<=b;++i)
#define RR(i,a,b) for(int i=a;i>=b;--i)
#define FJ(i,a,b) for(int i=a;i<b;++i)
#define SC(x) scanf("%d",&x)
#define SCC(x,y) scanf("%d%d",&x,&y)
#define SCCC(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define SS(x) scanf("%s",x)
#define PR(x) printf("%d\n",x)
#define CL(a, x) memset(a, x, sizeof(a))
#define _q fd[rt]
#define _l fd[rt << 1]
#define _r fd[rt << 1 | 1]
#define MID int mid=((l+r)>>1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define zero(x) (((x)>0?(x):-(x))<EPS)
#define PB push_back
#define SZ size
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define MP make_pair
#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
using namespace std;
LL a[N];
LL b[N];
int n;
int main(){
    //IN;
    SC(n);
    FF(i, 1, n){
        scanf("%lld", &a[i]);
        //a[i] += a[i - 1];
    }
    sort(a + 1, a + 1 + n);

    FF(i, 1, n){
        b[i] = b[i - 1] + a[i];
    }
    bool ha = 0;
    for(int i = n - 1; i >= 1; --i){
        if(b[i] * 2 < a[i + 1]){
            printf("%d\n", n - i);
            ha = 1;
            break;
        }
    }
    if(!ha)printf("%d\n", n);
return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>l(N);
  for(int i=0;i<N;i++){
    cin>>l[i];
  }
  sort(l.begin(),l.end());
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int two=l[i]+l[j];
      int left=lower_bound(l.begin(),l.end(),two)-l.begin();
      int right=j+1;
      ans+=left-right;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, M;
  cin>>N>>M;
  vector<ll> yaku;
  for(ll i=1;i*i<=M;++i) {
    if(M%i==0) {
      yaku.push_back(i);
      if(i!=M/i) yaku.push_back(M/i);
    }
  }
  ll ans = 1;
  for(int i=0;i<yaku.size();++i) {
    if(M>=N*yaku[i]) ans = max(ans, yaku[i]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int a,b,c,d;cin>>a>>b>>c>>d;
    if(abs(a-c)<=d) cout<<"Yes"<<endl;
    else if(abs(a-b)<=d && abs(b-c)<=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
vector<int> g[200100];

bool reach[200100];

bool solve() {
    for (int i = 0; i < g[1].size(); i++)
        reach[g[1][i]] = true;

    for (int i = 0; i < g[n].size(); i++) {
        if (reach[g[n][i]])
            return true;
    }
    return false;
}

void input() {
    cin >> n >> m;
    int a, b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"POSSIBLE":"IMPOSSIBLE") << endl;
}


Measured memory_bytes: 12144