akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

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

    ll N, Q;
    cin >> N >> Q;
    typedef pair<ll, pll> plll;
    vector<plll> qs;
    REP(i, N){
    	ll S, T, X;
    	cin >> S >> T >> X;
    	qs.push_back({X, {S, T}});
    }
    set<pll> D;
    REP(i, Q){
    	ll d;
    	cin >> d;
    	D.insert({d, i});
    }
    sort(qs.begin(), qs.end());
    vector<ll> res(Q, -1);
    REP(i, N){
    	if(D.empty()) break;
    	ll X = qs[i].first;
    	ll S = qs[i].second.first;
    	ll T = qs[i].second.second;
    	//dump(X)
    	//dump(S-X)
    	//dump(T-1-X)
    	auto itr = D.lower_bound({S-X, -1});
    	if(itr == D.end()) continue;
    	//dump(itr->first)
    	while(1){
    		if(itr == D.end()) break;
    		ll d = itr->first;
    		ll idx = itr->second;
    		if(d > T-1-X) break;
    		//dump(d)
    		//dump(idx)
    		res[idx] = X;
    		auto itr2 = itr;
    		itr++;
    		D.erase(itr2);
    	}
    	//dump("--------------");
    }
    REP(i, Q){
    	cout << res[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 22124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int n = sc.nextInt();
    		if(n==0) break;
    		int [] numbers = new int[2*n+1];
    		for(int i=2;i<=2*n;i++) {
    			numbers[i] = 0;
    		}
    		numbers[0] = 1;
    		numbers[1] = 1;
    		for(int i=2;i<=n;i++) {
    			for(int j=2;j<=(2*n)/i;j++) {
    				numbers[i*j] = 1;
    			}
    		}
    		int count = 0;
    		for(int i=n+1;i<=2*n;i++) {
    			if(numbers[i] == 0) count++;
    		}
    		System.out.println(count);
    	}
    }
}



Measured memory_bytes: 58728
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
  int a,b,c,x,cnt = 0;
  cin >> a >> b >> c >> x;
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      for(int k = 0; k <= c; k++){
        if(500*i + 100 * j + 50 * k == x) cnt ++;
      }
    }
  }
  cout << cnt << endl;

}


Measured memory_bytes: 256
def BellmanFord(start):
    # グラフの初期化 始点を0それ以外をinf
    inf = float("inf")
    dist = [inf] * N
    dist[start] = 0
    
    for i in range(N):
        update = False
        for x, y, z in G:
            if dist[y] > dist[x] + z:
                dist[y] = dist[x] + z
                update = True
                
                # 負の閉路を検出
                if y == N - 1 and i == N - 1:
                    return "inf"

        if update is False:
            break
        
    return -dist[-1]

N, W = map(int, input().split())  # 頂点, 辺
G = []
for _ in range(W):
    x, y, z = map(int, input().split())  # start, end, cost
    x, y, z = x - 1, y - 1, -z
    G.append([x, y, z])
    # G.append([y, x, z]) # 無向グラフのときのみ

d = BellmanFord(0)
print(d)


Measured memory_bytes: 74908
li = list(map(int,input().split()))
check = [1,4,7,9]
dic = {1:0, 4:0, 7:0, 9:0}

for i in range(4):
    if li[i] in check:
        dic[li[i]] += 1
    else:
        print("NO")
        exit()

for j in check:
    if dic[j] != 1:
        print("NO")
        exit()
print("YES")



Measured memory_bytes: 3064
a,b,c = map(int,input().split(" "))
k = int(input())
flag = False
for i in range(k):
  if a < b:
    if b >= c:
      c *= 2
  else:
    b *= 2
  if a < b < c:
    print("Yes")
    flag = True
    break
if flag == False:
  print("No")


Measured memory_bytes: 9124
import java.util.*;

public class Main {
	
	private void doit(){
		
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			
			String s = sc.next();
			System.out.println(s.replaceAll(",", " "));
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


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

using namespace std;

int main(void) {
  int H, W, N;
  cin >> H >> W >> N;

  if (H > W) {
    cout << (N-1)/H + 1 << endl;
  } else {
    cout << (N-1)/W + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;
immutable long INF = 1L << 59;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = readln.chomp.map!(a => a == 'B').array;
    auto G = new int[][](N);
    auto cnt = new int[][](N, 2);
    auto deleted = new bool[](N);

    void dfs(int n) {
        if (deleted[n]) return;
        deleted[n] = true;
        foreach (m; G[n]) {
            if (deleted[m]) continue;
            cnt[m][S[n]] -= 1;
            if (cnt[m][S[n]] == 0) {
                dfs(m);
            }
        }
    }

    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        auto u = s[0] - 1;
        auto v = s[1] - 1;
        G[u] ~= v;
        G[v] ~= u;
        cnt[u][S[v]] += 1;
        cnt[v][S[u]] += 1;
    }

    foreach (i; 0..N) {
        if (!deleted[i] && (cnt[i][0] == 0 || cnt[i][1] == 0)) {
            dfs(i);
        }
    }

    writeln(deleted.all ? "No" : "Yes");
}


Measured memory_bytes: 30332
#include<stdio.h>
int main(){
  long int n,i,r,a,b,k,l;
  scanf("%ld%ld",&n,&k);
  for(i=1;i<n;i++){
    scanf("%ld",&l);
    a=k>l?k:l;b=k>l?l:k;
    for(r=a%b;r;a=b,b=r,r=a%b);
    k*=l/b;
  }
  printf("%ld",k);
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<ll> A(n);
    vector<ll> B(n);
    vector<ll> C(n);
    
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> B[i];
    rep(i,n) cin >> C[i];
    
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    ll ans = 0;
    
    for(int i = 0; i < n; i++){
        ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        ll c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        
        ans += a * c;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 2560
def f():
    return int(raw_input())
def f2():
    return map(int, raw_input().split())

def merge(left, mid, right):
    L = S[left:mid]
    R = S[mid:right]
    lp, rp, xp = 0, 0, 0
    a, b = L[0], R[0]
    c = right - left
    x = [0] * c
    while xp < c:
        while xp < c and a <= b:
            x[xp] = a
            lp += 1
            xp += 1
            try:
                a = L[lp]
            except:
#                print x[xp:c], R[rp:right-mid]
                for e in R[rp:]:
                    x[xp] = e
                    xp += 1
                    rp += 1
                break
        while xp < c and a >= b:
            x[xp] = b
            rp += 1
            xp += 1
            try:
                b = R[rp]
            except:
#                print x[xp:c], L[lp:mid-left]
                for e in L[lp:]:
                    x[xp] = e
                    xp += 1
                    lp += 1
                break
    S[left:right] = x
    return c

def mergesort(left, right):
    c = 0
    if left + 1 < right:
        mid = (left + right)/2
        c += mergesort(left, mid)
        c += mergesort(mid, right)
        c += merge(left, mid, right)
    return c

global S
n = f()
S = f2()

c = mergesort(0, n)
print " ".join(map(str,S))
print c

Measured memory_bytes: 52884
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"
#define PI 3.141592653589793

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


int main(){
    ll N; cin>>N;
    ll v[N]; CINA(v,N);
    
    ll l[N];
    l[0] = v[0];
    ll m = l[0];
    for(int i=1;i<N-1;++i){
        m = min(m,v[i]);
        l[i] = m;
    }
    
    ll r[N];
    r[N-1] = v[N-1];
    m = r[N-1];
    for(int i=N-2;i>=0;--i){
        m = max(m,v[i]);
        r[i] = m;
    }
    
    ll ans = r[1]-l[0];
    for(int i=1;i<N-1;++i){
        ans = max(ans,r[i+1]-l[i]);
    }
    cout << ans <<endl;
}


Measured memory_bytes: 7796
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int h,w; cin >> h >> w;
    vector<vector<int>> tate(w),yoko(h); 
    vector<string> m(h); rep(i,h) cin >> m[i];
    rep(i,h) yoko[i].push_back(-1);
    rep(i,w) tate[i].push_back(-1);
    rep(i,h)rep(j,w){
        if(m[i][j] == '#'){
            tate[j].push_back(i);
            yoko[i].push_back(j);
        }
    }
    rep(i,h) yoko[i].push_back(w);
    rep(i,w) tate[i].push_back(h);
    int ans = 0;
    rep(i,h) rep(j,w){
        if(m[i][j] != '#'){
            int tid = lower_bound(all(tate[j]), i) - tate[j].begin();
            int yid = lower_bound(all(yoko[i]), j) - yoko[i].begin();
            ans = max(ans, (tate[j][tid] - tate[j][tid-1] - 1) + (yoko[i][yid] - yoko[i][yid-1] - 1) - 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 38656
import fractions
C, D, A, B  = map(int,input().split())
num = A * B // fractions.gcd(A, B)
ans = D - C + 1 - D // A + (C - 1) // A - D // B + (C - 1) // B + D // num - (C - 1) // num

print(ans)

Measured memory_bytes: 5048
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  int N,a[1001];
  cin >> N;
  REP(i,N)cin >> a[i];
  sort(a,a+N);
  cout << (a[N-1] - a[0]) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main() {
	long long int i, A, B, o;
	o = 0;
	scanf("%lld%lld", &A, &B);
	for (i=1; A <= B ;i++) {
		A = 2*A;
		o++;
	}
	printf("%lld\n", o);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	int many,nam=0;
	int data[6] = {500,100,50,10,5,1};
	int x,a;
	while(scanf("%d",&many) && many != 0)
	{
		nam = 0;
		many = 1000 - many;
		for(x=0; x<6; x++)
		{
			if(many/data[x] > 0)
			{
				nam += ( a = (many/data[x]));
				many -= (a * data[x]);
			}
		}
		printf("%d\n",nam);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
 #include <math.h>
 using namespace std;
 
 int main(){
    int N, M, X, Y, i;
    int x[120], y[120];
    bool ans = false;

    cin >> N >> M >> X >> Y;

    for (i = 0; i < N; i++){
        cin >> x[i];
        }

    for (i = 0; i < M; i++){
        cin >> y[i];
        }

    sort(x, x + N, greater<int>());
    sort(y, y + M);

    for (i = X+1; i < Y+1; i++){
        if (x[0] < i && i <= y[0]){
            ans = true;
            break;
            }
        }
    if(ans == true)
        cout << "No War" << endl;
    else
        cout << "War" << 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 all(v) v.begin(), v.end()
#define ll int64_t
int main(){
  ll x,a,b;
  cin >> x;
  bool t=false;
  for(a=-1000;a<=1000;a++){
    for(b=-1000;b<=a;b++){
      if((a*a*a*a*a-b*b*b*b*b)==x){
        cout << a <<" "<< b << endl;
        t=true;
        break;
      }
    }
    if(t)
      break;
  }
}
  

Measured memory_bytes: 3604
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	long long int N; cin >> N;
	int ans = 0;
	while (N) {
		N /= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

template<typename T> class LazySegmentTree {
    int n, sz;
    vector<T> dat, Lazy;
    const T INF = (1 << 30) - 1;

    void eval(int k){//ノードkの値を更新して遅延配列を伝播
        dat[k] += Lazy[k];//ココ
        if(Lazy[k]){
            if(k < n - 1) {
                Lazy[2 * k + 1] += Lazy[k];
                Lazy[2 * k + 2] += Lazy[k];
            }
            Lazy[k] = 0;
        }
    }

public:
    LazySegmentTree(const vector<T> &v) : sz((int)v.size()) {
        //nは元配列の要素数以上で最小の二冪
        //datは[n-1, 2n-1]が元の配列に対応　最下段より上段の要素数がn-1
        n = 1;
        while(n < sz)n *= 2;
        dat.resize(2 * n - 1, INF);//ノードを単位元で初期化
        Lazy.resize(2 * n - 1, 0);//遅延配列を0で初期化

        for(int i = 0; i < sz; i++){
            dat[i + n - 1] = v[i];//元配列に対応するノードを初期化
        }
        for(int i = n - 2; i >= 0; i--){
            dat[i] = min(dat[2 * i + 1], dat[2 * i + 2]);//下から上になめて更新
        }
    }

    //[a,b)にxを一様加算
    //今見てるノードのインデックス:k  それに対応する元配列の区間[l,r)
    //ノードの値を更新

    void add(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        eval(k);//ココ
        if(r <= a || b <= l){//更新区間にふくまれない
            return;
        }
        if(a <= l && r <= b){//更新区間に完全に含まれる
            Lazy[k] += x;
            eval(k);
        }
        else {//一部更新区間を含む
            add(a, b, x, 2 * k + 1, l, (l + r) / 2);
            add(a, b, x, 2 * k + 2, (l + r) / 2, r);
            if(k < n - 1){//ココ
                dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
            }
        }
        
    }

    //[a,b)のminを求める
    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0)r = n;
        if(r <= a || b <= l){
            return INF;//目的の区間を含まないので単位元を返す
        }

        eval(k);
        if(a <= l && r <= b){//遅延配列を更新してノードの値を返す
            return dat[k];
        }
        else {//左右に配って帰ってきた二つのminを返す
            T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int main(){
    vector<int> V;
    int N, Q;
    cin >> N >> Q;
    V.resize(N, 0);
    LazySegmentTree<int> seg(V);
    for(int i = 0; i < Q; i++){
        int a, s, t, x;
        cin >> a >> s >> t;
        if(a == 0){
            cin >> x;
            seg.add(s, t + 1, x);
        }
        else {
            cout << seg.query(s, t + 1) << endl;
        }
    }
    

    return 0;
}


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

int main() {
  int m,n;
  cin >> m >> n;
  int r=0;
  if(n==31)r=1;
  if(m==2&&n==28) r=1;
  if((m==4 || m==6 || m==9 || m==11) && n==30) r=1;
  cout << r << endl;
}

Measured memory_bytes: 256
def solve(h, w, a):
    xs = list(range(w))
    v = []
    for y in range(h):
        for x in xs:
            v.append((x, y))
        xs = xs[::-1]
    res = []
    for i in range(len(v) - 1):
        x, y = v[i]
        nx, ny = v[i+1]
        if a[y][x] % 2 != 0:
            a[ny][nx] += 1
            res.append((y+1, x+1, ny+1, nx+1))
    print(len(res))
    for y, x, ny, nx in res:
        print(y, x, ny, nx)

h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
solve(h, w, a)

Measured memory_bytes: 44596
h, w = map(int, input().split())
a = []
for _ in range(h):
    _a = list(input())
    if '#' in _a:
        a += [_a]
    else:
        pass

import numpy as np

a = np.array(a)
ans_col = []

for i in range(w):
    if '#' in a[:,i]:
        ans_col += [i]
    else:
        pass

ans = a[:, ans_col]

for j in range(a.shape[0]):
    print(''.join(map(str, ans[j, :])))


Measured memory_bytes: 12500
s = input()
t = input()


def ok(i):
    for j in range(len(t)):
        if s[i + j] == '?':
            continue
        elif s[i + j] != t[j]:
            return False
    return True


for i in range(len(s) - len(t), -1, -1):
    if ok(i):
        s = s[:i] + t + s[i + len(t) :]
        s = s.replace('?', 'a')
        print(s)
        import sys
        sys.exit()
print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;


int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        int last=0,a,b,c,flag=0;
        for(int i=0;i<n;i++){
            scanf("%d%d%d",&a,&b,&c);
            if(a<b+c) flag=1;
            if((a-b-c)%2==1) flag=1;
        }
        if(flag==1) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0;i<N;i++){
    cin >> a[i];
  }
  set<int> s;
  map<int,int> m;
  for (int i=0;i<N;i++){
    s.insert(a[i]);
    m[a[i]]++;
  }
  int ans=0;
  for (int i=0;i<N;i++){
    if (s.count(a[i])){
      if (m[a[i]]<a[i]){
        ans+=m[a[i]];
      }
      else {
        ans+=m[a[i]]-a[i];
      }
      s.erase(a[i]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll x, y;
    cin>>x>>y;

    if (x * y > 0) {
        ll ans = y - x;
        if (ans < 0) ans = -ans + 2;
        cout<<ans<<endl;
        return 0;
    }
    if (x * y < 0) {
        ll ans = abs(abs(y) - abs(x)) + 1;
        cout<<ans<<endl;
        return 0;
    }
    if (x == 0) cout<<abs(y) + ((y < 0) ? 1 : 0)<<endl;
    else cout<<abs(x) + ((x < 0) ? 0 : 1)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define mod 1000000007
#define ln "\n"
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define f first
#define s second
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main(){
    fio;
    ll s,w;
    cin>>s>>w;
    if(w>=s)
    cout<<"unsafe";
    else
    cout<<"safe";
    return 0;
}


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


double dp[3001][3001];

double solve(double a[],ll i,ll h,ll n)
{
    if(i>=n)
    {
        if(h>n-h)
        {
            return(1.0);
        }
        else
        {
            return(0.0);
        }
    }
    if(dp[i][h]>=0.0)
    {
        return(dp[i][h]);
    }
    double p1=1.0*a[i]*(solve(a,i+1,h+1,n));
    double p2=(1.0-a[i])*(solve(a,i+1,h,n));
    return(dp[i][h]=p1+p2);
}
int main()
{
    ll n,i,j;
    cin>>n;
    double a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n;j++)
        {
            dp[i][j]=-1.0;
        }
    }
    cout<<fixed<<setprecision(10);
    cout<<solve(a,0,0,n)<<"\n";
}

Measured memory_bytes: 74348
#include<stdio.h>
int main()
{
    int n,x;
    float a=0,b=0,c,y[100];
      scanf("%d",&n);
      for(x=1;x<=n;x++)
      {
          scanf("%f",&y[x]);
      }
       for(x=1;x<=n;x++)
      {
          a+=(1/y[x]);
      }
      b=(1/a);
      printf("%f\n",b);
    return 0;
}


Measured memory_bytes: 128
N = int(input())
W = list(map(int, input().split()))

ans = 1e+9
for i in range(N-1):
    S1 = S2 = 0
    for j in range(N):
        if j <= i: S1 += W[j]
        if j >  i: S2 += W[j]
    ans = min(ans, abs(S1-S2))

print(ans)

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N;
    cin >> N;
    ll V[N];
    rep(i,N) cin >> V[i];
    ll out = 0;
    rep(i,N){
        ll C = 0;
        cin >> C;
        if(V[i]>C) out += V[i]-C;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.C
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var count = 0;
            for (int A = 1; A < N; A++)
            {
                for (int B = 1; A * B < N; B++)
                {
                    if (N - A * B > 0)
                    {
                        count++;
                    }
                }
            }
            return count;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 27540
import math

A, B, H, M = map(int, input().split())

x = (H + M / 60) / 12 * 360
y = M / 60 * 360

if x < y:
    x, y = y, x

theta = math.radians(min(x - y, y + 360 - x))
print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(theta)))


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

using namespace std;

int solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    set<int> s1{1, 9, 7, 4};
    set<int> s2;
    s2.insert(a);
    s2.insert(b);
    s2.insert(c);
    s2.insert(d);
    puts(s1 == s2 ? "YES" : "NO");

    return 0;
}

int main() {
#ifdef LOCALHOST
  freopen("input", "r", stdin);
#endif
  while (solve()) {
  }

  return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
char D[1002][1002]={};

int main() {
	int M,N;
	char E[2][2];
	char b[4]={'S','J','O','I'};
	cin>>M>>N;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			cin>>D[i][j];
		}
	}
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			cin>>E[i][j];
		}
	}
	int a=0;
	for(int i=1;i<M;i++){
		for(int j=1;j<N;j++){
			if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1]){
				a+=1;
			}
		}
	}
	int c[4];
	int R=0;
	for(int i=1;i<M+1;i++){
		for(int j=1;j<N+1;j++){
			b[0]=D[i][j];
			for(int k=0;k<4;++k){
				D[i][j]=b[k];
				c[k]=0;
				if(D[i][j]==E[0][0]&&D[i][j+1]==E[0][1]&&D[i+1][j]==E[1][0]&&D[i+1][j+1]==E[1][1])c[k]+=1;
				if(D[i][j-1]==E[0][0]&&D[i][j]==E[0][1]&&D[i+1][j-1]==E[1][0]&&D[i+1][j]==E[1][1])c[k]+=1;
				if(D[i-1][j-1]==E[0][0]&&D[i-1][j]==E[0][1]&&D[i][j-1]==E[1][0]&&D[i][j]==E[1][1])c[k]+=1;
				if(D[i-1][j]==E[0][0]&&D[i-1][j+1]==E[0][1]&&D[i][j]==E[1][0]&&D[i][j+1]==E[1][1])c[k]+=1;
			}
			D[i][j]=b[0];
			R=max(R,a+c[1]-c[0]);
			R=max(R,a+c[2]-c[0]);
			R=max(R,a+c[3]-c[0]);
		}
	}


	cout<<R<<endl;
	return 0;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  vector<int> antennas(5);
  for(int i = 0; i < 5; i++){
    cin >> antennas[i];
  }
  int k;
  cin >> k;
  if(antennas[4] - antennas[0] > k){
    cout << ":(" <<endl;
    return 0;
  }
  cout << "Yay!" <<endl;
}

Measured memory_bytes: 3620
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL;
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
    int n,t;
    cin>>n>>t;
    int ans=10000000;
    rep(i,0,n){
        int a,b;
        cin>>a>>b;
        if(b<=t){
            ans=min(ans,a);
        }
    }
    if(ans!=10000000)cout<<ans<<endl;
    else cout<<"TLE"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	int d=max(max(a,b),c);
	if(d==a){cout<<a*10+b+c<<endl;return 0;};
	if(d==b){cout<<b*10+a+c<<endl;return 0;};
	if(d==c){cout<<c*10+b+a<<endl;return 0;};
}

Measured memory_bytes: 256
(A,B,H,M) = list(map(int,input().split()))
#print(H)
#s = M - (H*30 + M/2)
long = M*6
short = (H*60+M)*360/(12*60)
s = short - long
import math
cos = math.cos(math.radians(s))
l = math.sqrt(A**2 + B**2 - 2*A*B*cos)
print(l)

Measured memory_bytes: 9432
#include <algorithm>
#include <cmath>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

struct Point {
  int x, y, h;
};

int calcH(int x, int y, int h, int cx,  int cy) {
  int dx = std::abs(x - cx);
  int dy = std::abs(y - cy);
  return h  + dx + dy;
}
int calc(int x, int y, int cx, int cy, int H) {
  int dx = std::abs(x - cx);
  int dy = std::abs(y - cy);
  return std::max(H - dx - dy, 0);
}

int main() {
  int N; std::cin >> N;
  std::vector<Point> ps(N);
  for (int i = 0; i < N; i++) {
    std::cin >> ps[i].x >> ps[i].y >> ps[i].h;
  }

  int cx, cy, H;
  for (cx = 0; cx <= 100; ++cx) {
    for (cy = 0; cy <= 100; ++cy) {
      for (const auto& p : ps) {
        if (p.h == 0) continue;
        H = calcH(p.x, p.y, p.h, cx, cy);
        break;
      }
      bool success = true;
      for (const auto& p : ps) {
        int h = calc(p.x, p.y, cx, cy, H);
        if (h != p.h) {
          success = false;
          break;
        }
      }

      if(success) {
        std::cout << cx << " " << cy << " " << H << std::endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using p = pair<int, int>;
 
int main() {
  int board[3][3];

  rep(i, 3) {
    rep(j, 3) {
      cin >> board[i][j];
    }
  }

  int n;
  cin >> n;
  
  rep(i, n) {
    int b;
    cin >> b;

    rep(i, 3) {
      rep(j, 3) {
        if (b == board[i][j]) {
          board[i][j] = -1;
        }
      }
    }
  }

  bool flag = false;

  if (board[0][0] == -1 && board[1][0] == -1 && board[2][0] == -1) {
    flag = true;
  }

  if (board[0][1] == -1 && board[1][1] == -1 && board[2][1] == -1) {
    flag = true;
  }

  if (board[0][2] == -1 && board[1][2] == -1 && board[2][2] == -1) {
    flag = true;
  }

  if (board[0][0] == -1 && board[0][1] == -1 && board[0][2] == -1) {
    flag = true;
  }

  if (board[1][0] == -1 && board[1][1] == -1 && board[1][2] == -1) {
    flag = true;
  }

  if (board[2][0] == -1 && board[2][1] == -1 && board[2][2] == -1) {
    flag = true;
  }

  if (board[0][0] == -1 && board[1][1] == -1 && board[2][2] == -1) {
    flag = true;
  }

  if (board[2][0] == -1 && board[1][1] == -1 && board[0][2] == -1) {
    flag = true;
  }


  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const double EPS=1e-8;

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

template<class T>
double abs(const point<T> &a){ return sqrt(a.x*a.x+a.y*a.y); }

template<class T>
struct circle{
	point<T> c;
	T r;
};

template<class T>
double dist(const point<T> &a,const point<T> &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

bool cover(const circle<double> &C,const point<double> &p){
	return dist(C.c,p)<C.r+EPS;
}

int get_intersect(const circle<double> &C1,const circle<double> &C2,vector< point<double> > &res){
	double r1=C1.r,r2=C2.r;
	point<double> p1=C1.c,p2=C2.c;

	double d=abs(p1-p2);
	if(d<EPS && abs(r1-r2)<EPS){ // C1==C2
		return -1;
	}
	else if(r1+r2<d-EPS || d+EPS<abs(r1-r2)){
		return 0;
	}
	else{
		double a=(r1*r1-r2*r2+d*d)/(2*d);
		double h=sqrt(max(r1*r1-a*a,0.0));
		point<double> tmp1=p1+a/d*(p2-p1);
		point<double> tmp2=h/d*(p2-p1);
		if(abs(tmp2)<EPS){
			res.push_back(tmp1);
			return 1;
		}
		else{
			res.push_back((point<double>){tmp1.x-tmp2.y,tmp1.y+tmp2.x});
			res.push_back((point<double>){tmp1.x+tmp2.y,tmp1.y-tmp2.x});
			return 2;
		}
	}
}

int main(){
	for(int n;scanf("%d",&n),n;){
		circle<double> C[100];
		int v[100];
		rep(i,n) scanf("%lf%lf%d",&C[i].c.x,&C[i].c.y,v+i);

		double lo=0,hi=1e7;
		while(hi-lo>1e-6){
			double mi=(lo+hi)/2;
			rep(i,n) C[i].r=v[i]*mi;

			vector< point<double> > cand;
			rep(i,n) cand.push_back(C[i].c);
			rep(i,n) rep(j,i) get_intersect(C[i],C[j],cand);

			bool ok=false;
			rep(i,cand.size()){
				int j;
				for(j=0;j<n;j++) if(!cover(C[j],cand[i])) break;
				if(j==n){ ok=true; break; }
			}
			if(ok) hi=mi; else lo=mi;
		}

		printf("%.9f\n",(lo+hi)/2);
	}

	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <limits.h>
#define INF INT_MAX

void insert(int *,int);
void extract(int *);
void maxheapify(int *,int);
void heapincreasekey(int *,int,int);
int parent(int);
int left(int);
int right(int);
void swap(int *,int *);
int heap;

int main(){
  int A[2000000];
  int key;
  char command[10];
  while(1){
    
    scanf("%s",command);
    if(command[0]=='i'){
      scanf("%d",&key);
      insert(A,key);
    }
    else if(command[1]=='x') extract(A);
    else if(command[2]=='d'){
      break;
    }
  }

  return 0; 
}

void insert(int *A,int key){
  heap++;
  A[heap]=-INF;
  heapincreasekey(A,heap,key);
}

void extract(int *A){
  printf("%d\n",A[1]);
  swap(&A[1],&A[heap]);
  heap--;
  maxheapify(A,1);
}


void maxheapify(int *A,int i){
  int l,r,largest;
  l=left(i);
  r=right(i);
  if(l<=heap&&A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=heap&&A[r]>A[largest])
    largest=r;

  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxheapify(A,largest);
  }
}

void heapincreasekey(int *A,int i,int key){
  A[i]=key;
  while(i>1&&A[parent(i)]<A[i]){
    swap(&A[i],&A[parent(i)]);
    i=parent(i);
  }
}


int parent(int i){
  return i/2;
}

int left(int i){
  return i*2;
}

int right(int i){
  return i*2+1;
}

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
  return;
}



Measured memory_bytes: 5624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A;
    for (int i = 0; i < N; ++i){
        int a, b;
        cin >> a >> b;
        A.push_back(make_pair(a, b));
    }

    sort(A.begin(), A.end());

    long long cost=0;

    for (auto itr = A.begin(); itr != A.end(); itr++){
        if(M==0){
            break;
        }
        int m = min(M, itr->second);
        cost += (long long) (itr->first) *(long long) (m);
        M = M - m;
    }

    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,t,b[100010][2];
unsigned long long ok[50050];
char ans[100010];
int cnt[50050],to[50050];
int main()
{
	scanf("%d %d %d",&n,&m,&t);
	for(int i=1;i<=m;++i)scanf("%d %d",&b[i][0],&b[i][1]),--b[i][0],--b[i][1];
	if(t==1)
	{
		for(int i=0;i<n;i+=64)
		{
			memset(ok,0,n<<3);
			for(int j=0;j<64&&i+j<n;++j)ok[i+j]|=1ull<<j;
			for(int j=m;j;--j)ok[b[j][0]]=ok[b[j][1]]=ok[b[j][0]]|ok[b[j][1]];
			unsigned long long s=~(0ull);
		//	for(int j=0;j<n;++j)printf("%llu\n",ok[j]);
			for(int j=0;j<n;++j)s&=ok[j];
		//	printf("%llu\n",s);
			if(s)
			{
				int p;
				for(int j=0;j<=63;++j)if(s>>j&1){p=i+j;break;}
				memset(ok,0,n<<3);
				ok[p]=1;
				for(int j=m;j;--j)
				{
					if(ok[b[j][0]])ans[j]='^';
					else ans[j]='v';
					ok[b[j][0]]=ok[b[j][1]]=ok[b[j][0]]|ok[b[j][1]];
				}
				for(int j=1;j<=m;++j)printf("%c",ans[j]);
				return 0;
			}
		}
		printf("-1");
	}
	else
	{
		if(n==2)return printf("-1"),0;
		for(int i=0;i<n;++i)cnt[i]=1,to[i]=i;
		for(int i=m;i;--i)
		{
			if(to[b[i][0]]==to[b[i][1]])ans[i]='v';
			else if(cnt[to[b[i][0]]]>=2)ans[i]='v',--cnt[to[b[i][0]]],++cnt[to[b[i][1]]],to[b[i][0]]=to[b[i][1]];
			else ans[i]='^',--cnt[to[b[i][1]]],++cnt[to[b[i][0]]],to[b[i][1]]=to[b[i][0]];
		}
		for(int i=1;i<=m;++i)printf("%c",ans[i]);
	}
	return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
vector<ll> A(N);
const ll INF = 1e18;

int main()
{
	scanf("%d",&N);
	A.assign(N,0);
	FOR(i,0,N){
		scanf("%lld",&A [i]);
	}

	ll ans = INF;
	ll sumA = 0,sumB = accumulate(A.begin(),A.end(),0ll);
	FOR(i,0,N - 1){
		sumA += A [i];
		sumB -= A [i];
		chmin(ans,abs(sumA - sumB));
	}

	printf("%lld\n",ans);

	return 0;
}


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

int main(){
  int c[3],total;
  double a;
  while(cin >> c[0]){
    cin >> c[1];
    cin >> c[2];
    int cou=0;
    total = c[0] + c[1];
    for(int i=1;i<11;i++){
      if(i != c[0] && i != c[1] && i != c[2]){
	if(total+i <= 20){
	  cou++;
	}
      }
    }
    a=cou/7.0*100;
    if(a >= 50){
      cout << "YES" << endl;
    }
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    string str;

    cin >> n;
    cin >> str;

    string ans;
    for(int i = 0; i < str.length(); i++) {
        if (int(str[i] + n) > int('Z')) { 
            ans.push_back(char(str[i]+n-26));
        } else { 
            ans.push_back(char(str[i]+n));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
x,y=[int(i) for i in input().split()]
if 0<=x and 0<=y:
    if y==0:
        print(x+1)
        sys.exit()
    if x>y:
        print(x-y+2)
        sys.exit()
    else:
        print(y-x)
        sys.exit()

elif 0<=x and y<0:
    print(abs(abs(y)-x)+1)
    sys.exit()

elif x<0 and 0<=y:
    if y==0:
        print(abs(abs(x)-y))
        sys.exit()
    else:
        print(abs(abs(x)-y)+1)
        sys.exit()

elif x<0 and y<0:
    if abs(x)<abs(y):
        print(abs(abs(x)-abs(y))+2)
        sys.exit()
    else:
        print(abs(abs(x)-abs(y)))
        sys.exit()

a=1
a+='a'


Measured memory_bytes: 3064
from collections import deque

H,W=map(int,input().split())
p={}
for i in range(H):    
    for j,c in enumerate(input()):
        p[(i,j)]=c=='.'
d={(i,j):-1 for i in range(H) for j in range(W)}
white=sum(p.values())
q=deque()
s=(0,0)
q.append(s);d[s]=1
while q:
    u=q.popleft()
    ui,uj=u
    for v in [(ui-1,uj),(ui+1,uj),(ui,uj-1),(ui,uj+1)]:
        vi,vj=v
        if 0<=vi<=H-1 and 0<=vj<=W-1 and p[v] and d[v]==-1:
            d[v]=d[u]+1
            q.append(v)
if d[(H-1,W-1)]==-1:
    ans=-1
else:
    ans=white-d[(H-1,W-1)]
print(ans)

Measured memory_bytes: 41456
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 17 21:30:30 JST 2020
 **/

signed main() {
    Int K;
    std::cin >> K;
    std::string s;
    std::cin >> s;
    if (s.size() > K) {
        s = s.substr(0, K) + "...";
    }
    std::cout << s << std::endl;
}


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

int f(int a, int b) {
	return max(a, b);
}
int e() {
	return -1;
};
int lt_v;
bool lt(int v) {
	return v < lt_v;
};

int main() {
	int n, q; cin >> n >> q;
	vector<int> v(n); for(int& i : v) cin >> i;
	segtree<int, f, e> seg(v);
	while(q--) {
		int t, x, y; cin >> t >> x >> y;
		if(t == 1) {
			--x;
			seg.set(x, y);
		}
		if(t == 2) {
			--x;
			cout << seg.prod(x, y) << '\n';
		}
		if(t == 3) {
			--x;
			lt_v = y;
			cout << seg.max_right<lt>(x) + 1 << '\n';
		}
	}
	return 0;
}


Measured memory_bytes: 6188
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 21796
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    N,W=map(int,input().split())
    v,w=[0]*N,[0]*N
    for i in range(N):
        v[i],w[i]=map(int,input().split())
    dp=[[0]*2*10**5 for _ in range(N+1)]
    for i in range(N):
        for weight in range(W+1):
            dp[i+1][weight]=max(dp[i+1][weight],dp[i][weight])
            if weight-w[i]>=0:
                dp[i+1][weight]=max(dp[i+1][weight],dp[i][weight-w[i]]+v[i])
                dp[i+1][weight]=max(dp[i+1][weight],dp[i+1][weight-w[i]]+v[i])
    print(dp[N][W])

if __name__ == '__main__':
    main()



Measured memory_bytes: 165616
#include<iostream>
using namespace std;
#include<cstdio>
#include<algorithm>

struct point{ int x, y, id; };

point init(int pos_x, int pos_y, int index)
{
    point p; 
    p.x = pos_x, p.y = pos_y, p.id = index; 
    return p; 
}

bool cmp_x(const point &P1, const point &P2){ if(P1.x != P2.x){ return P1.x < P2.x; } return P1.y < P2.y; }
bool cmp_y(const point &P1, const point &P2){ if(P1.y != P2.y){ return P1.y < P2.y; } return P1.x < P2.x; }

void kd_tree(point *S, point *T, point *U, int left, int right, int d)
{
    int mid = ((left + right) >> 1);
    int a = left, b = mid + 1;

    if((d & 1) == 0){
        for(int i = left; i < right; i++){
            if(cmp_x(T[i], S[mid])){
                U[a++] = T[i];
            }else if(S[mid].id == T[i].id){
                U[mid] = T[i];
            }else{
                U[b++] = T[i];
            }
        }
        for(int i = left; i < right; i++){ T[i] = U[i]; }

    }else{
        for(int i = left; i < right; i++){
            if(cmp_y(S[i], T[mid])){
                U[a++] = S[i];
            }else if(T[mid].id == S[i].id){
                U[mid] = S[i];
            }else{
                U[b++] = S[i];
            }
        }
        for(int i = left; i < right; i++){ S[i] = U[i]; }
    }
	if(mid - left > 1){ kd_tree(S, T, U, left, mid, d + 1); }
	if(right - mid > 2){ kd_tree(S, T, U, mid + 1, right, d + 1); }
}

int cnt;

void find_pt(int *Q, point *S, int sx, int tx, int sy, int ty, int left, int right, int d)
{
    int mid = ((left + right) >> 1);
    point p = S[mid];
    int a = p.x, b = p.y;

    if(sx <= a && a <= tx && sy <= b && b <= ty){
        Q[cnt++] = p.id;
    }

    if((d & 1) == 0){
        if((left < mid) && (sx < a || (sx == a && sy <= b))){ find_pt(Q, S, sx, tx, sy, ty, left, mid, d + 1); }
        if((mid + 1 < right) && (a < tx || (a == tx && b <= ty))){ find_pt(Q, S, sx, tx, sy, ty, mid + 1, right, d + 1); }
    }else{
        if((left < mid) && (sy < b || (sy == b && sx <= a))){ find_pt(Q, S, sx, tx, sy, ty, left, mid, d + 1); }
        if((mid + 1 < right) && (b < ty || (b == ty && a <= tx))){ find_pt(Q, S, sx, tx, sy, ty, mid + 1, right, d + 1); }
    }
    return;
}

int main()
{
    point *S, *T, *U;
    int Q[100];
    int i, pos_x, pos_y, n;
    scanf("%d", &n);

    S = new point [n], T = new point [n], U = new point [n];

    for(i = 0; i < n; i++){
        scanf("%d %d", &pos_x, &pos_y);
        S[i] = init(pos_x, pos_y, i);
        T[i] = S[i];
    }
    sort(S, S + n, cmp_x);
    sort(T, T + n, cmp_y);

    kd_tree(S, T, U, 0, n, 0);

    int sx, tx, sy, ty, q;
    scanf("%d", &q);
    while(q){
        cnt = 0;
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        find_pt(Q, S, sx, tx, sy, ty, 0, n, 0);
        sort(Q, Q + cnt);
        for(int i = 0; i < cnt; i++){ printf("%d\n", Q[i]); }
        printf("\n");
        q--;
    }

    return 0;
}

Measured memory_bytes: 18324
import math
n, k = map(int,input().split())
dat = list(map(int, input().split()))
i = dat.index(1) + 1 # 1 origin で i 個目に 1 がある
reach = k # 今1で占有した場所
a = math.ceil((n - reach) / (k - 1))
print(1+a)

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int, int> pii;
const int mod = (int)1e9 +7;

int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int a,b;
	cin >> a >>b;
	string s;
	if(a==1 && b==1) s="Draw";
	else if(a==1) s = "Alice";
	else if(b==1) s = "Bob";
	else if(a>b) s = "Alice";
	else if(b>a) s = "Bob";
	else s="Draw";
	cout << s <<endl;
	return 0;

}


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

using namespace std;

int main()
{
    int X, Y, Z;

    cin >> X >> Y >> Z;

    int A, B, C;

    A = X;
    B = Y;
    C = Z;

    A = Y;
    B = X;
    C = Z;

    A = Z;
    C = Y;

    cout << A << " " << B << " " << C << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h,w,n;
    cin>>h>>w>>n;
    h=n/h+(n%h==0?0:1);
    w=n/w+(n%w==0?0:1);
    cout<<min(h,w)<<endl;
    return 0;
}

Measured memory_bytes: 256