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

int main()
{
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    double dp[n+1][n+1];
    dp[0][0]=1;
    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j==0)dp[i][j]=dp[i-1][j]*(1.0-a[i-1]);
            else if(j==i)dp[i][j]=dp[i-1][j-1]*a[i-1];
            else
            {
                dp[i][j]=dp[i-1][j]*(1.0-a[i-1])+dp[i-1][j-1]*(a[i-1]);
            }
            
            //cout<<dp[i][j]<<"   ";
        }
        //cout<<endl;
    }
    double s=0;
    for(int i=(n)/2+1;i<=n;i++)
    {
        s+=dp[n][i];
    }
    cout<<setprecision(10)<<s;
}

Measured memory_bytes: 70400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A,B;
    cin >> A >> B;
    int num=0;
    for(int i=A; i <= B; i++){
        string s = to_string(i);
        if (s[0] == s[4] && s[1] ==s[3] ) num++;
    }

    cout << num << endl;


}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);

  ll ans[3];
  ans[--A] = 1;
  ans[--B] = 1;

  rep(i, 0, 3) {
    if (ans[i] == 1) continue;
    put(i + 1);
    return 0;
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

int main()
{
    int n, rank, s[14], h[14], c[14], d[14];
    char suit;
    for(int i=1;i<14;i++)
    {
        s[i]=0;
        h[i]=0;
        c[i]=0;
        d[i]=0;
    }
    cin >> n;
    
    for(int i=0;i<n;i++)
    {
        cin >> suit >> rank;
        switch(suit)
        {
            case 'S':
                s[rank] = 1;
                break;
            case 'H':
                h[rank] = 1;
                break;
            case 'C':
                c[rank] = 1;
                break;
            case 'D':
                d[rank] = 1;
                break;
        }
    }
    
    for(int i=1;i<14;i++)
    {
        if(s[i] == 0){
            cout << "S " << i << endl;
        }
    }
    for(int i=1;i<14;i++)
    {
        if(h[i] == 0){
            cout << "H " << i << endl;
        }
    }
    for(int i=1;i<14;i++)
    {
        if(c[i] == 0){
            cout << "C " << i << endl;
        }
    }
    for(int i=1;i<14;i++)
    {
        if(d[i] == 0){
            cout << "D " << i << endl;
        }
    }    
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

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

	int N;
	cin >> N;
	int L[200];
	for(int i = 0; i < 2 * N; i++) {
		cin >> L[i];
	}
	sort(L, L + 2 * N);

	int ans = 0;
	for(int i = 0; i < N; i++) {
		ans += L[2 * i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N, K, *A = $stdin.read.split.map(&:to_i)
A.sort!

B = Array.new(N, 0)

i = 0
prev_a = A[0]
A.each do |a|
  if a != prev_a
    prev_a = a
    i += 1
  end
  B[i] += 1
end

B.sort!.reverse!

n = B[K...N].inject(:+)
if n == nil
  n = 0
end
puts n


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

#define Fi first
#define Se second
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<(n);i++)
typedef tuple<int, int, int> t3;

int N;
char buf[330];
int A[330];

vector <int> Get(vector <int> X) {
	if(szz(X) == 1) return {X[0]};
	else {
		int t = X.back();
		X.pop_back();
		auto w = Get(X);
		vector <int> res;
		res.pb(t);
		res.insert(res.end(), all(w));
		res.pb(-t);
		reverse(all(w));
		for(int e : w) res.pb(-e);
		return res;
	}
}

int main() {
	scanf("%d", &N);
	scanf("%s", buf);
	for(int i=0;i<1<<N;i++) A[i] = buf[i] - '0';
	int B = 1<<N;
	rep(i, B) rep(j, B) if((i&j) == j) {
		if(A[i] && A[j] == 0) {
			puts("Impossible");
			return 0;
		}
	}
	vector <int> w;
	rep(i, B) if(A[i] == 0) {
		int ok = 1;
		rep(j, i) if((i&j) == j && A[j] == 0) ok = 0;
		if(ok) w.pb(i);
	}
	vector <int> R;
	for(int e : w) {
		vector <int> t;
		rep(i, N) if(1<<i & e) t.pb(i + 1);
		auto v2 = Get(t);
		R.insert(R.end(), all(v2));
	}
	vector <pii> ans;
	int now = 0;
	ans.pb({0, 0});
	auto Move = [&](int x) {
		while(now < x) ans.pb({++now, 0});
		while(now > x) ans.pb({--now, 0});
	};
	for(int e : R) {
		int st, en;
		if(e > 0) st = e - 1, en = e;
		else st = -e, en = -e - 1;
		Move(st);
		ans.pb({st, 1});
		ans.pb({en, 1});
		ans.pb({en, 0});
		now = en;
	}
	Move(0);
	puts("Possible");
	printf("%d\n", szz(ans) - 1);
	for(pii e : ans) printf("%d %d\n", e.Fi, e.Se);
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;
 


int main()
{
   
  
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    if (n <= a) {
        cout << n << endl;

    }
    else if (n <= b) {
        cout << a << endl;
    }
    else {
        ll x = (n / (a + b)) * a;
        x += min((n % (a + b)) , (a ));
        cout << x<< endl;
    }


    return 0;

}

Measured memory_bytes: 3644
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        System.out.println(800 * n - (n/15 *200));
    
        }        
    }



Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int L = scanner.nextInt();
    int R = scanner.nextInt();
    int l = L % 2019;
    int r = R % 2019;
    if (l >= r || R - L > 2019) {
      System.out.println(0);
      return;
    }

    int min = l * r % 2019;
    for (int i = l; i < r; i++) {
      for (int j = i + 1; j <= r; j++) {
        min = Math.min(min, i * j % 2019);
      }
    }
    System.out.println(min);
  }
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto X = RD;
	auto A = RDR.ARR;
	long ans1, ans2;
	foreach (i; 0..M)
	{
		if (A[i] < X)
		{
			++ans1;
		}
		else
		{
			++ans2;
		}
	}

	writeln(min(ans1, ans2));
	stdout.flush();
	debug readln();
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    b.at(i)=a.at(i);
  }
  sort(a.begin(),a.end());
  
  for(int i=0;i<n;i++){
    if(b.at(i)==a.at(n-1)) cout<<a.at(n-2)<<endl;
    else cout<<a.at(n-1)<<endl;
  }
}


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

typedef long long ll;
typedef long double ld;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

bool palindromeornot(string s)
{
    for (int i = 0; i < s.size() / 2; i++)
    {
        if (s[i] != s[s.size() - 1 - i])
            return 0;
    }
    return 1;
}

string reversedstring(string str)
{
    string s = str;
    reverse(s.begin(), s.end());
    return s;
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        ll n, m, i, j, k;
        cin>>i>>j>>k;
        if((i==j&& i!=k)||(j==k && i!=j) || (i==k && i!=j)){
            cout<<"Yes\n";
        }else cout<<"No\n";
        
    }
    return 0;
}

Measured memory_bytes: 256
equation_list = list(map(str, input().split(' ')))
stack = []

for elem in equation_list:
    if elem.isnumeric():
        stack.append(int(elem))
    else:
        number2 = stack.pop()
        number1 = stack.pop()
        answer = eval('number1' + elem + 'number2')
        stack.append(answer)

print(f'{stack[0]}')


Measured memory_bytes: 5612
N,K = map(int,input().split())
*V, = map(int,input().split())
ans = 0
for l in range(min(N,K+1)):
    for r in range(min(N-l+1,K-l+1)):
        h = V[:l]+V[N-r:]
        h.sort(reverse=True)
        for _ in [0]*(K-(l+r)):
            if h and h[-1]<0:h.pop()
        ans = max(ans,sum(h))
print(ans)

Measured memory_bytes: 3064
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	q := sc.ReadInt()
	abcds := make([]ABCD, q)
	for i := 0; i < q; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		c := sc.ReadInt()
		d := sc.ReadInt()
		abcds[i] = ABCD{a, b, c, d}
	}

	maxScore := 0
	update := func(combi SeqA) {
		score := computeScore(abcds, combi)
		if score > maxScore {
			maxScore = score
		}
	}

	cur := make(SeqA, n)
	eachCombination(update, 1, m, n, 0, cur)

	fmt.Println(maxScore)
}

func eachCombination(callback func(SeqA), min, max, n, pos int, cur SeqA) {
	if pos == n {
		callback(cur)
		return
	}

	for i := min; i <= max; i++ {
		cur[pos] = i
		eachCombination(callback, i, max, n, pos+1, cur)
	}
}

func computeScore(abcds []ABCD, seqA SeqA) int {
	totalD := 0
	for _, abcd := range abcds {
		if seqA[abcd.B-1]-seqA[abcd.A-1] == abcd.C {
			totalD += abcd.D
		}
	}
	return totalD
}

type SeqA []int

type ABCD struct {
	A int
	B int
	C int
	D int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1768
def make_bit(n):
    bit = []
    for i in range(2**n):
        bit.append(bin(i)[2::])
    i = 0
    while i < len(bit):
        while len(bit[i]) < len(bin(2**n-1)[2::]):
            bit[i] = "0" + bit[i]
        i += 1

    return bit

n = int(input())
a = []
xy_list = []
for i in range(n):
    a.append(int(input()))
    xy = [list(map(int, input().split())) for _ in range(a[i])]
    xy_list.append(xy)

# print(xy_list)

bit = make_bit(n)
ans = 0
for i in bit:
    tmp = [0 for _ in range(n)]
    NO = 0
    cnt = 0
    for j in range(n):
        if i[j] == "1":
            cnt += 1
            for x, y in xy_list[j]:
                if y and i[x-1] == "0":
                    NO = 1
                    break
                if not y and i[x-1] == "1":
                    NO = 1
                    break
        if NO:
            break

    if not NO:
        # print(i, tmp)
        ans = max(ans, cnt)
print(ans)


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

int main(){
    int N;
    cin>>N;
    vector<int> A(N);

    bool con = true;
    rep(i,N){
        cin>>A[i];
        if(A[i]%2==1){
            con = false;
        }
    }
    
    int res = 1e9+7;
    for(int i=0;i<N;i++){
        int tmp = A[i];
        int cnt=0;
        while(tmp%2==0){
            tmp /= 2;
            cnt++;
        }
        res = min(res,cnt);
    }

    if(con){
        cout<<res;
    }else{
        cout<<"0";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define MX INT_MAX
using namespace std;
#define int long long

int32_t main()
{
    int w, h, x, y;
    bool t;
    cin >> w >> h >> x >> y;
    if (w == 2 * x && h == 2 * y)
        t = 1;
    else
        t = 0;

    printf("%f %d\n", double((0.5) * h * w), t);
    return 0;
}


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

using namespace std;

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

	int* arr = new int[10];

	for (int i = 0; i < 10; i++) {
		arr[i] = 0;
	}

	int* n = new int[3];
	cin >> n[0] >> n[1] >> n[2];

	for (int i = 0; i < 3; i++) {
		arr[n[i]]++;
	}

	bool isYes = false;

	for (int i = 0; i < 10; i++) {
		if (arr[i] == 2) {
			isYes = true;
			break;
		}
	}

	if (isYes) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>
long double pi = boost::math::constants::pi<long double>();
using namespace std;
typedef long long ll;
int N, M;
int A[1010], B[1010], C[1010], D[1010], E[1010], F[1010];
vector<int> x, y;
bool mpx[6020][6020], mpy[6020][6020];
bool mp[6020][6020];
queue<pair<int, int>> que;
int main() {
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> A[i] >> B[i] >> C[i];
        x.push_back(A[i]);
        x.push_back(B[i]);
        y.push_back(C[i]);
    }
    for (int i = 1; i <= M; i++) {
        cin >> D[i] >> E[i] >> F[i];
        x.push_back(D[i]);
        y.push_back(E[i]);
        y.push_back(F[i]);
    }
    x.push_back(0);
    y.push_back(0);
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for (int i = 1; i <= N; i++) {
        A[i] = lower_bound(x.begin(), x.end(), A[i])-x.begin();
        B[i] = lower_bound(x.begin(), x.end(), B[i])-x.begin();
        C[i] = lower_bound(y.begin(), y.end(), C[i])-y.begin();
        for (int a = A[i]*2; a <= B[i]*2; a++) {
            mpy[a][C[i]*2] = 1;
        }
    }
    for (int i = 1; i <= M; i++) {
        D[i] = lower_bound(x.begin(), x.end(), D[i])-x.begin();
        E[i] = lower_bound(y.begin(), y.end(), E[i])-y.begin();
        F[i] = lower_bound(y.begin(), y.end(), F[i])-y.begin();
        for (int a = E[i]*2; a <= F[i]*2; a++) {
            mpx[D[i]*2][a] = 1;
        }
    }
    int s = lower_bound(x.begin(), x.end(), 0)-x.begin();
    int t = lower_bound(y.begin(), y.end(), 0)-y.begin();
    mp[s*2][t*2] = 1;
    que.push(make_pair(s*2,t*2));
    while (que.size()) {
        int x = que.front().first, y = que.front().second;
        que.pop();
        int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
        for (int i = 0; i < 4; i++) {
            int nx = dx[i]+x, ny = dy[i]+y;
            if (nx >= 0 && nx < 6020 && ny >= 0 && ny < 6020) {
                if (!mpx[nx][ny] && !mpy[nx][ny] && mp[nx][ny] != 1) {
                    mp[nx][ny] = 1;
                    que.push(make_pair(nx, ny));
                }
            }
            else {
                puts("INF");
                return 0;
            }
        }
    }
    ll ans = 0;
    for (int i = 1, xl = x.size(); (i+1)/2 < xl; i+=2) {
        for (int j = 1, yl = y.size(); (j+1)/2 < yl; j+=2) {
            if (mp[i][j]) {
                ans += ((ll)x[(i+1)/2]-x[(i-1)/2])*((ll)y[(j+1)/2]-y[(j-1)/2]);
            }
        }
    }
    cout << ans << endl;
}

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

typedef long long ll;
const int maxn = 200005;
int n, q, res;
int a[maxn], b[maxn];
 vector<int> vec[maxn];

void dfs(int u, int fa) {
    b[u] = res;
    for (int i = 0; i < vec[u].size(); i++) {
        int v = vec[u][i];
        if (v == fa) continue;
        res += a[v];
        dfs(v, u);
        res -= a[v];
    }
}

int main() {
    cin >> n >> q;
    int u, v;
    for (int i = 1; i <= n - 1; i++) {
        cin >> u >> v;
        vec[u].push_back(v);
        vec[v].push_back(u);
    }
    int p, x;
    for (int i = 1; i <= q; i++) {
        cin >> p >> x;
        a[p] += x;
    }
    res = a[1];
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        cout << b[i] << " ";
}

Measured memory_bytes: 27264
N = int(input())
A = [i for i in map(int,input().split())]

ans = 10 ** 20 + 1
for j in range(2):
    cnt= 0
    ruiseki = [0] * N
    ruiseki[0] = A[0]
    if j == 0:
        if A[0] <= 0:
            ruiseki[0] = 1
            cnt += 1 - A[0]
        #print(j,ruiseki[0],cnt)
    else:
        if A[0] >= 0:
            ruiseki[0] = -1
            cnt += 1 + A[0]
        #print(j,ruiseki[0],cnt)
    for i in range(1,N):
        ruiseki[i] = ruiseki[i-1]+A[i]
        totalp = 0
        if ruiseki[i] * ruiseki[i-1] >0:
            totalp= (int(ruiseki[i])>0)*(-1)*(1 + ruiseki[i]) +  (int(ruiseki[i])<0) * (1 - ruiseki[i])

        elif ruiseki[i] == 0:
            if ruiseki[i-1] > 0:
                totalp = -1
            else:
                totalp = 1
        ruiseki[i] += totalp 
        cnt += abs(totalp)
        #print(ruiseki,totalp,cnt)
    ans = min(ans,cnt)
        
print(ans)
        
        
        

Measured memory_bytes: 14464
s = list(input())
sl = list(map(int,s))

l1 = []
l2 = []
for i in range(len(sl)):
  l1.append(i%2)
  l2.append((i+1)%2)

d1 = 0
d2 = 0
for i in range(len(sl)):
  if sl[i] != l1[i]:
    d1 += 1
  if sl[i] != l2[i]:
    d2 += 1

print(min(d1,d2))

Measured memory_bytes: 6316
#include <bits/stdc++.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

ll K;
ll d[100001];

int main(){
    cin>>K;
    d[1]=1;
    queue<int> Q;
    Q.push(1);

    while(!Q.empty()){
        int x=Q.front();
        int y=d[x];
        Q.pop();
        int A=x;
        while(true){
            A=(A*10)%K;
            if(d[A]!=0 && d[A]<=d[x]) break;
            d[A]=y;
            Q.push(A);
        }
        int B=(x+1)%K;
        if(d[B]==0) {Q.push(B); d[B]=y+1;}
    }
    //for(int i=0;i<K;i++) cout<<i<<' '<<d[i]<<endl;
    cout<<d[0]<<endl;

}

Measured memory_bytes: 1408
X=input()
def split(w):
    return [all for all in w]
before=split(X[0:int(len(X)/2)])
after=split(X[int(len(X)/2):])
c=0
ans=0
reverse=-1
if len(X)%2==1:
    after=after[1:]
for i in after:
    if after[c]!=before[reverse]:
        ans+=1
    c+=1
    reverse-=1
print(ans)

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

const int MAXN = 21;
int N;
string word[MAXN];
string line;
vector<string> V;
vector<int> F;
map<char, char> ans;

bool ok(const string &x, const string &w, map<char, char> m) {
  if(x.size() != w.size()) return false;
  for(int i = 0; i < x.size(); ++i) {
    if(m.count(x[i]) && m[x[i]] != w[i]) return false;
    if(m.count(w[i]) && m[w[i]] != x[i]) return false;
    m[x[i]] = w[i];
    m[w[i]] = x[i];
  }
  return true;
}

void reg(const string &x, const string &w, map<char, char> &m) {
  for(int i = 0; i < x.size(); ++i) {
    m[x[i]] = w[i];
    m[w[i]] = x[i];
  }
}

bool update(int k, map<char, char> m) {
  F = vector<int>(V.size());
  for(int i = k; i < V.size(); ++i) {
    for(int j = 0; j < N; ++j) {
      if(ok(V[i], word[j], m)) {
        F[i] |= 1 << j;
      }
    }
    if(!F[i]) return false;
  }
  return true;
}

void rec(int k, map<char, char> m) {
  if(k == V.size()) {
    if(ans.size()) throw 0;
    ans = m;
    return;
  }
  for(int i = 0; i < N; ++i) {
    if(F[k] >> i & 1); else continue;
    map<char, char> nm = m;
    reg(V[k], word[i], nm);
    vector<int> undo = F;
    if(update(k+1, nm)) {
      rec(k+1, nm);
    }
    F = undo;
  }
}

int main() {
  while(cin >> N && N) {
    for(int i = 0; i < N; ++i) {
      cin >> word[i];
    }
    cin.ignore();
    getline(cin, line);
    stringstream ss(line.substr(0, line.size()-1));
    set<string> ws;
    for(string s; ss >> s; ) ws.insert(s);
    V.clear();
    for(set<string>::iterator it = ws.begin();
        it != ws.end(); ++it) {
      V.push_back(*it);
    }
    update(0, map<char, char>());
    ans = map<char, char>();
    try {
      rec(0, map<char, char>());
      if(ans.empty()) throw 0;
      for(int i = 0; i < line.size(); ++i) {
        if(isalpha(line[i])) cout << ans[line[i]];
        else cout << line[i];
      }
      cout << endl;
    } catch(...) {
      cout << "-." << endl;
    }
  }
  return 0;
}

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

using namespace std;

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

int main()
{
    string s, t;
    cin >> s >> t;
    rep(i, 3) {
        if (s[i] != t[2-i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1) {}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

int main() {
	init();

	int N, M, K; cin >> N >> M >> K;
	UnionFind uf(N);
	vector<int>fr(N, 0);
	vector<int>bl(N, 0);
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		--a; --b;
		uf.unite(a, b);
		fr[a]++; fr[b]++;
	}
	rep(i, 0, K) {
		int a, b; cin >> a >> b;
		--a; --b;
		if (uf.same(a, b)) {
			bl[a]++;
			bl[b]++;
		}
	}
	rep(i, 0, N) {
		cout << uf.size(i) - fr[i] - bl[i] - 1;
		if (i != N - 1)cout << " ";
		else cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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 double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int L;
	cin >> L;
	int pow2[22];
	pow2[0] = 1;
	for(int i=1;i<=21;i++){
		pow2[i] = pow2[i-1]*2;
	}
	int now = 0;
	while(pow2[now] <= L){
		now++;
	}
	--now;
	vector<pair<P, int>> vec; 
	rep(i,now){
		vec.push_back({P(i+1, i+2), 0});
		vec.push_back({P(i+1, i+2), pow2[now-1-i]});
	}
	L -= pow2[now];
	int num = pow2[now];
	for(int i=now-1;i>=0;i--){
		if(L>=pow2[i]){
			L -= pow2[i];
			vec.push_back({P(1, now+1-i), num});
			num += pow2[i];
		}
	}
	cout << now+1 << " " << vec.size() << endl;
	for(auto e : vec){
		cout << e.first.first << " " << e.first.second << " " << e.second << endl;
	}
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long A, long long B) {
  bool ok = false;
  rep(C,1,4){
    if(A*B*C % 2==1) ok = true;
  }
  yesno(ok);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long A;
  std::cin >> A;
  long long B;
  std::cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 3616
"use strict";

var processData = function processData(lines) {
  var s = lines[0];

  if (s[2] === s[3] && s[4] === s[5]) {
    console.log('Yes');
  } else {
    console.log('No');
  }
};

var i = '';
process.stdin.on('data', function (c) {
  return i += c;
});
process.stdin.on('end', function () {
  var _require = require('os'),
      EOL = _require.EOL;

  var lines = i.split(EOL);
  /*your input text, split by lines*/

  processData(lines);
});


Measured memory_bytes: 22084
n, k, q = map(int, input().split())
A = [0] * (n + 1)
for i in range(q):
    a = int(input())
    A[a] += 1

for i in range(n):
    if k - (q - A[i+1]) <= 0:
        print("No")
    else:
        print("Yes")


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

int main() {
    string s;
    cin >>s;
    int b = -1, e = s.size();
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == 'A') {
            b = i;
            break;
        }
    }
    for (int i = s.size()-1; i > 0; i--) {
        if (s.at(i) == 'Z') {
            e = i;
            break;
        }
    }
    cout << s.substr(b,e-b+1).size() << endl;
    return 0;
}

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

intl ans = 1;
intl res;
int A[1010000];
int n;

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&A[i]);
	for (int i = 2; i <= n; i++) A[i] = min(A[i], A[i - 1] + 2);
	res = 1;
	for (int i = 1; i <= n; i++) {
		ans *= min((res + i - 1) / 2LL + 1LL, (intl) i);
		ans %= 1000000007LL;
		res += ((A[i] - A[i - 1] - 1));	
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    
    if(l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if(r <= H && A[r] > A[largest]) largest = r;
    
    if(largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main() {
    cin >> H;
    for(int i = 1; i <= H; i++) cin >> A[i];
    for(int i = H / 2; i >= 1; i--) maxHeapify(i);
    for(int i = 1; i <= H; i++) {
        cout << " " << A[i];
    }
    cout << endl;
    
    return 0;
}


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

int main() {
  int64_t N, X, countR, countG, countB;
  countR = 0;
  countG = 0;
  countB = 0;
  string A;
  cin >> N >> A;
  for (int i = 0; i < N; i++) {
    if (A.at(i) == 'R') {
      countR++;
    }
    if (A.at(i) == 'G') {
      countG++;
    }
    if (A.at(i) == 'B') {
      countB++;
    }
  }
  X = countR * countG * countB;
  for (int j = 1; j < N - 1; j++) {
    for (int i = 0; i < j; i++) {
      int k = j + (j - i);
      if (k < N) {
        if (A.at(i) == A.at(j)) {
          continue;
        }
        if (A.at(j) == A.at(k)) {
          continue;
        }
        if (A.at(i) == A.at(k)) {
          continue;
        }
          X--;
        }
      else {
        continue;
      }
      }
  }
    cout << X << endl;
}
        
      
  

  
  


Measured memory_bytes: 3628
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


bool compare(pi a, pi b){
  if(a.first == b.first )
    if(a.second < b.second) return true;
  if(a.first > b.first) return true;
  return false;
}

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

    ll n,m;
    cin >> n >> m;

    int l[m],r[m];
    F0R(i,m){
      cin >> l[i] >> r[i];
    }
    sort(l,l+m);
    sort(r,r+m);
    if(r[0] - l[m-1] < 0) cout << 0<<endl;
    else cout << r[0] - l[m-1] + 1 << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect_left
import heapq

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
d = [INT() for _ in range(N)]

print(len(set(d)))


Measured memory_bytes: 5400
#include<bits/stdc++.h>
using namespace std;
string s,an;
int n;
void dfs(int x){
  int t=0;
  for(int i=x,c=0;i<s.size()&&0<=c;i++){
    if(s[i]=='('){
      while(!c&&t>0&&t--&&an.size()<=n)dfs(i+1);
      c++;
    }
    if(s[i]==')')c--;
    if(!c&&'0'<=s[i]&&s[i]<='9')t*=10,t+=s[i]-'0';
    if(!c&&'A'<=s[i]&&s[i]<='Z')an+=s[i];
  }
}

int main(){
  while(cin>>s>>n&&s[0]!='0'){
    an.clear();
    for(int i=0;i<s.size();i++)
      if('0'<=s[i]&&s[i]<='9'&&'A'<=s[i+1]&&s[i+1]<='Z')
    	s=s.substr(0,i+1)+'('+s[i+1]+')'+s.substr(i+2,s.size());
     dfs(0);
    if(an.size()>n)cout<<an[n]<<endl;
    else cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
 
using namespace std;
 
string s;
int t,i;
 
int main(){
    getline(cin,s);
	for(i=0;i<=s.length()-1;i++){
		if(s[i]=='+')t++;
		else t--;
	}
printf("%d",t);
return 0;
}

Measured memory_bytes: 256
program sample
    implicit none
  
    integer(8) :: a,b,c,d,i,j,n,h,w,k,m,x(4)
  
    
  
    ! 整数を読み込む
    read(*,*) w,h,n
    x(1)=0
    x(2)=w
    x(3)=0
    x(4)=h
    do i=1,n
        read(*,*)a,b,k
        if(k==1)then
            if(x(1)<a)then
                x(1)=a
            end if
        elseif(k==2)then
            if(x(2)>a)then
                x(2)=a
            end if

        elseif(k==3)then
            if(x(3)<b)then
                x(3)=b
            end if
        else
            if(x(4)>b)then
                x(4)=b
            end if
        end if
    end do
    if(x(2)<=x(1) .or. x(4)<=x(3))then
        write(*,*)0
    else
    	
        write(*,*)(x(2)-x(1))*(x(4)-x(3))
    end if
                
    
  
    stop
  end program sample
  

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int a, b; cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 100010
#define mid (l+r>>1)
#define LL long long
#define M 1000000007
using namespace std;
int n,m,f[N]; LL A,B,s[N],w[N<<2];
void change(int p,int l,int r,int a,int b){
    if(l==r){ (w[p]+=b)%=M; return; }
    if(a<=mid)change(p*2,l,mid,a,b);
	else change(p*2+1,mid+1,r,a,b);
    w[p]=(w[p*2]+w[p*2+1])%M;
}
int query(int p,int l,int r,int a,int b){
    if (a>b) return 0;
    if (l==a&&r==b) return w[p];
    if (b<=mid) return query(p*2,l,mid,a,b);
    else if (a>mid) return query(p*2+1,mid+1,r,a,b);
    else return (query(p*2,l,mid,a,mid)+query(p*2+1,mid+1,r,mid+1,b))%M;
}
main(){
	scanf("%d%lld%lld",&n,&A,&B);
	if(A<B) swap(A,B); f[0]=1; 
	for(int i=1;i<=n;++i) scanf("%lld",s+i);
	*s=-A; s[n+1]=A+s[n]; int l=0,r=0; change(1,0,n,0,f[0]);
	for(int i=1;i<=n+1;++i){
		while(s[i]-s[r+1]>=A) ++r;
		if(i>=2 && s[i-1]-s[i-2]<B) l=i-2;
		if(s[i]-s[i-1]>=A) f[i]=f[i-1];
		f[i]=(f[i]+query(1,0,n,l,min(r,i-2)))%M;
		if(s[i+1]-s[i-1]>=B) change(1,0,n,i,f[i]);
	}
	printf("%lld\n",(f[n+1]+M)%M);
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int a ; re(a); cout << a*a*3 << endl;
	
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3632
X,K,D = map(int,input().split())

l=0#右に進む回数
r=K

if D*K + X <=0:
    print(abs(D*K+X))
    exit()
if -D*K +X >=0:
    print(abs(-D*K+X))
    exit()

while r-l > 1:
    k = (l+r)//2

    if D*(2*k-K)+X > 0:
        r=(l+r)//2
    else:
        l=(l+r)//2
    
    if D*(2*k-K)+X ==0:
        print(0)
        exit()
k=l
l=abs(D*(2*k-K)+X)
k=r
r=abs(D*(2*k-K)+X)

print(min(r,l))

Measured memory_bytes: 61864
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll D,T,S;
  cin >> D >> T >> S;
  if ((D+S-1)/S > T) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3616
// Mon Aug 24 16:24:09 IST 2020        
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)       for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define scan(any)          for(auto &i:any) cin>>i;
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long   
#define all(x)             (x).begin(),(x).end() 
#define ff                 first
#define ss                 second
#define pppp               pair <int,int> 
#define flushOff           fflush(stdout) 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
using namespace std ;    
// policy based   
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
 
const int MOD1 = 1e9+7;
const int MOD2 = 1e9+9;
const double pi = 3.141592653589793238;
const int INF = 2e9+7; 
const int N = 2e5+7;
struct compare{
    bool operator()(pair <int,int> A, pair <int,int> B){
        if(A.first == B.first)
            return A.second > B.second;
        return A.first > B.first;
    }
}; 
void print(vector <int>v){
    for(int t : v){
        cout << t << ' ';
    }
    cout << '\n';
}
int tests(){  
    string s1,s2;
    cin >> s1 >> s2;
    if(s2.substr(0,(int)s1.size()) == s1)
        return cout << "Yes\n",0;
    cout << "No\n";
    return 0;
}    
int main(){
    I__O ;      
    int cases = 1 ;  
    // cin >> cases ;
    while(cases--)
        tests(); 
    return 0 ; 
}
 

Measured memory_bytes: 3652
N=int(input())
K=int(input())
count=0
Min=0

a=input().strip().split(" ")
a=[int(i) for i in a]

for i in range(N):
    if(abs(a[i]-0)>abs(a[i]-K)):
        count+=abs(a[i]-K)*2
    else:
        count+=abs(a[i]-0)*2

print(count)


Measured memory_bytes: 3060
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;

  for(int i = 1;;i++)
  {
    unsigned long long p = i * i;
    if(p > n )
    {
      cout << (unsigned long long)(i - 1)*(i - 1) << endl;
      return 0;
    }
  }


  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
# define  long          long long
# define  all(vc)       vc.begin(),vc.end()
# define  allr(vc)      vc.rbegin(),vc.rend()
# define  pb            push_back
# define  fi            first 
# define  se            second
# define  pi            pair <long, long>  
# define  lcm(a, b)     (a * b) / __gcd(a, b)  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        using namespace std;
void read(){freopen("input.txt" , "r" , stdin );freopen("output.txt", "w" , stdout );}
void solve(){
	string s;
	cin >> s;
	long ans = 0;
	for (int i = 0; i < s.size(); ++i){
		ans += s[i] - '0';
	}
	if( ans % 9 ) cout << "No";
	else cout << "Yes";
} 
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
        cout << fixed << setprecision(9);
        long T = 1;
        //cin >> T;
        while( T-- ){
            solve();
            cout<<'\n';
        }
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
} 													


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

namespace ABC136
{
    class A
    {
        static void Main(string[] args)
        {
            int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(Math.Max(abc[2] - (abc[0] - abc[1]), 0));
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>
#include <bitset>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  if(s.size() > 9){
    cout << "NO" << endl;
    return 0;
  }
  string t = "AKIHABARA";
  string u = "";
  int si = 0, ti = 0;
  while(si < s.size() && ti < t.size()){
    if(s[si] == t[ti]){
      u += s[si];
      ti++;
      si++;
    }else{
      if(t[ti] == 'A'){
        ti++;
        u += 'A';
      }else{
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  if(u == t || u == "AKIHABAR")cout << "YES" << endl;
  else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  int ans = 6;
  printf("%d\n", ans - a - b);
  return 0;
}


Measured memory_bytes: 128