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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

ll coef[26];
int from[26];
string in[15];

inline int cut(int i,int j){
	int cur=i;
	rep(loop,j) cur/=10;
	return cur%10;
}

int main(void){
	int n;
	while(cin >> n,n){
		int ans=0;
		rep(i,n) cin >> in[i];

		clr(coef,0);
		clr(from,-1);

		rep(i,n)rep(j,in[i].size()){
			int m=in[i].size();
			int cur=in[i][j]-'A';
			from[cur]=max(from[cur],(m>1&&j==0)?1:0);
			if(i<n-1)
				coef[cur]+=pow(10,m-1-j);
			else
				coef[cur]-=pow(10,m-1-j);
		}
		vi index;
		rep(i,26) if(from[i]!=-1) index.pb(i);

		int num=index.size();

		rep(mask,1<<10){
			if(__builtin_popcount(mask)!=num) continue;
			vi number;
			rep(j,10) if(mask&(1<<j)) number.pb(j);
			do{
				bool check=true;
				rep(j,num) if(number[j]<from[index[j]]) check=false;
				if(!check) continue;
				int csum=0;
				rep(j,num) csum+=number[j]*coef[index[j]];
				if(csum==0) ans++;
			}while(next_permutation(number.begin(),number.end()));
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1272
main(){
  int a[1000003]={},b[999999]={},n,i,x=0,c;
  for(i=2;i<1000000;i++)
    a[i]=i;
  for(i=0;i<1000000;i++)
    if(a[i]!=0)
      {
	b[x]=i;
	x++;
	for(c=i;c<1000000;c+=i)
	  a[c]=0;
      }
  while(scanf("%d",&n)!=-1){
    c=0;
    while(b[c]<=n && b[c]!=0){c++;}
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m, k := nextInt(), nextInt(), nextInt()

	uf := newUnionFind(n)

	friends := make([]int, n)
	for i := 0; i < m; i++ {
		a, b := nextInt()-1, nextInt()-1
		uf.unite(a, b)
		friends[a]++
		friends[b]++
	}

	blocks := make([]int, n)
	for i := 0; i < k; i++ {
		c, d := nextInt()-1, nextInt()-1
		if uf.same(c, d) {
			blocks[c]++
			blocks[d]++
		}
	}

	for i := 0; i < n; i++ {
		cnt := uf.size(i) - friends[i] - blocks[i] - 1
		fmt.Printf("%d ", cnt)
	}
	fmt.Println()
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

// UnionFind .
type UnionFind struct {
	par   []int
	rank  []int
	sizes []int
}

func newUnionFind(n int) UnionFind {
	u := UnionFind{}
	u.par = make([]int, n)
	u.rank = make([]int, n)
	u.sizes = make([]int, n)
	for i := 0; i < n; i++ {
		u.par[i] = i
		u.rank[i] = 0
		u.sizes[i] = 1
	}
	return u
}

func (u UnionFind) unite(x, y int) {
	x = u.root(x)
	y = u.root(y)
	if x == y {
		return
	}

	if u.rank[x] < u.rank[y] {
		u.par[x] = y
		u.sizes[y] += u.sizes[x]
	} else {
		u.par[y] = x
		u.sizes[x] += u.sizes[y]
		if u.rank[x] == u.rank[y] {
			u.rank[x]++
		}
	}
}

func (u UnionFind) root(x int) int {
	if u.par[x] == x {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}

func (u UnionFind) same(x, y int) bool {
	return u.root(x) == u.root(y)
}

func (u UnionFind) size(x int) int {
	return u.sizes[u.root(x)]
}


Measured memory_bytes: 7424
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

a=int(input())
b=int(input())
c=int(input())

amount = int(input())

count = 0
for i in range(a+1):
    for j in range(b+1):
        temp = amount - (500*i + 100*j)
        
        if temp < 0:
            continue
        elif temp%50!=0:
            continue
        elif c < temp//50:
            continue
        # print(temp)
        count+=1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;

static const int MAX=100;
static const long long INFTY=(1LL<<32);

long long d[MAX][MAX];
int n;

void warshallFloyd(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(d[i][k]==INFTY) continue;
            for(int j=0;j<n;j++){
                if(d[k][j]==INFTY) continue;
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    int a,b,c,e;
    cin >> n >> a;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=((i==j)?0:INFTY);
        }
    }
    for(int i=0;i<a;i++){
        cin >> b >> c >> e;
        d[b][c]=e;
    }
    
    warshallFloyd();
    bool negative=false;
    for(int i=0;i<n;i++){
        if(d[i][i]<0) negative=true;
    }
    
    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }else{
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j) cout << " ";
                if(d[i][j]==INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3200
from collections import deque 
N = int(input())
L = deque()
"""
def searchnode(x):
    idx = -1
    for i in range(len(L)):
        if L[i]==x:
            idx = i
    return idx
"""

for i in range(N):
    command = input()
    if command == "deleteFirst":
        L.popleft()
    elif command == "deleteLast":
        L.pop()
    else:
        com , x = command.split()
        x =int(x)
        if com == "insert":
            L.appendleft(x)
        elif com == "delete":
            if x in L:
                L.remove(x)
    #print(L)
            
print(" ".join(map(str,L)))


Measured memory_bytes: 45948
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from collections import deque
import sys
def main(N, M, G, I, root):
    P = [-1] * N
    q = deque()
    q.append(root)
    while q:
        v = q.popleft()
        for to in G[v]:
            I[to] -= 1
            if I[to] == 0:
                P[to] = v
                q.append(to)
    for p in P:
        print(p + 1)

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    I = [0] * N
    for _ in range(N - 1 + M):
        a, b = map(int, input().split())
        a, b = a - 1, b - 1
        G[a].append(b)
        I[b] += 1
    main(N, M, G, I, I.index(0))


Measured memory_bytes: 88384
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int i=1,x;
		while(true){
			x=sc.nextInt();
			if(x==0){
				break;
			}
			System.out.println("Case "+i+": "+x);
			i++;
		}
		sc.close();
	}
}



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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009
#define pi 3.141592653589793238

typedef pair<int, int> P;
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int a, b; cin>>a>>b;
    vector<int> p(n);
    REP(i,n) cin>>p[i];
    int one = 0, two = 0, three = 0;
    REP(i,n){
        if(p[i]<=a) one++;
        else if (p[i]>a&&p[i]<=b)
        {
            two++;
        } else {
            three++;
        }
    }
    int ans = min(min(one,two),three);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

template<class... Args>
auto input(Args&&... args) {
    return InputType2(std::forward<Args>(args)...);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

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

auto gcd(size_t l, size_t r) {
    if (r == 0)
        return l;
    return gcd(r, l % r);
}

auto gcd(size_t a, size_t b, size_t c) {
    return gcd(a, gcd(b, c));
}

int main() {
    size_t n = input();
    map<string, size_t> m{};
    for (size_t i = 0; i < n; ++i) {
        string s = input();
        ++m[move(s)];
    }
    cout << m.size() << endl;
    return 0;
}


Measured memory_bytes: 19272
s=str(input())
n=len(s)

for i in range(0,n):
 if s[i]!=s[-i-1]:
    print("No")
    exit()

new_n1=int((n-1)/2)
new_s1=s[:new_n1]

new_n2=int((n+3)/2)
new_s2=s[new_n2-1:]
for i in range(0,len(new_s1)):
 if new_s1[i]!=new_s1[-i-1]:
    print("No")
    exit()
else:
  pass
for i in range(0,len(new_s2)):
 if new_s2[i]!=new_s2[-i-1]:
    print("No")
    exit()
else:
  print("Yes") 

Measured memory_bytes: 9088
// SeeAlso: https://atcoder.jp/contests/abc143/tasks/abc143_a

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(ll i = 1; i <= n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

const long double PI = acos(-1);

int main() {
    int a,b;
    cin >> a >> b;

    print((a-b*2)>0?(a-2*b):0);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,n,A[500005],B[500005],fix[500005],l,r,l1,r1,l2,r2,l3,r3;
int main() {
    cin>>n;
    for(long long i=1;i<=n;i++) {
        cin>>A[i];
        fix[A[i]]++;
    }
    for(long long i=1;i<=n;i++) {
        cin>>B[i];
        fix[B[i]]++;
        if(fix[B[i]]>n) { a=1; }
    }
    if(a==1) { cout<<"No"; return 0; }
    cout<<"Yes"<<endl;
    reverse(B+1,B+1+n);
    for(long long i=1;i<=n;i++) {
        if(A[i]==B[i]) b=A[i];
    }
    if(b==0) {
        for(long long i=1;i<=n;i++) {
            cout<<B[i]<<" ";
        }
        return 0;
    }
    //cout<<b<<endl;
    
    for(long long i=1;i<=n;i++) {
        if(b==A[i] && l==0) l=i;
        if(b==A[i]) r=i;
    }
    for(long long i=1;i<=n;i++) {
        if(b==B[i] && l1==0) l1=i;
        if(b==B[i]) r1=i;
    }
    l2=max(l,l1);
    r2=min(r,r1);
    l3=min(l,l1);
    r3=max(r,r1);
    while(l2<=r2) {
        if(l3!=1) {
            l3--;
            swap(B[l3],B[l2]);
        }
        else {
            r3++;
            swap(B[r3],B[l2]);
        }
        l2++;
    }
    for(long long i=1;i<=n;i++) {
        cout<<B[i]<<" ";
    }
}

Measured memory_bytes: 8252
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	ll a = fetch<ll>();
	ll b = fetch<ll>();
	ll c = fetch<ll>();

	cout << (a & b & c & 1 ? min({a * b, a * c, b * c}) : 0) << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

int main(void) {
    int N, K;
    cin >> N >> K;
    if (K > ((N - 1) * (N - 2)) / 2) {
        printf("-1\n");
        return 0;
    }
    vector< pair< int, int > > e;
    for (int i = 0; i < N - 1; ++i) {
        e.push_back(make_pair(1, i + 2));
    }
    int r = (((N - 1) * (N - 2)) / 2) - K;
    int start = 2, s_e = 0;
    for (int i = 0; i < r; ++i) {
        if (start + s_e + 1 > N) {
            ++start;
            s_e = 0;
        }
        e.push_back(make_pair(start, start + s_e + 1));
        ++s_e;
    }
    int M = e.size();
    printf("%d\n", M);
    for (int i = 0; i < M; ++i) {
        printf("%d %d\n", e[i].first, e[i].second);
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
  ll A;
  double B;
  cin >> A >> B;
  ll ans = A * (ll)(B * 100 + 0.1);
  cout << ans / 100 << endl;
  return 0;
}

Measured memory_bytes: 3728
#define KAKUSUKO
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000-1;
int N;
ll A[MAX_N];

ll ans[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> A[i];

  rep(i, N) {
    ans[0] += (i%2 == 0 ? A[i] : -A[i]);
  }

  for (int i = 1; i < N; ++i) {
    ans[i] = 2*A[i-1] - ans[i-1];
  }

  rep(i, N) {
    cout << ans[i] << (i+1 == N ? '\n' : ' ');
  }

  return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> S(2 * N - 1);

    rep(i, N) {
        S.at(i) = K - N + (i + 1);
        S.at(2 * N - 2 - i) = K + N - (i + 1);
    }

    for(int n : S) cout << n << " ";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int n;
char s[1000010];
/*
int f(){
	int aa[10];
	rep(i,0,n)aa[i]=s[i]-'1';
	rep(k,0,n-1){
		rep(i,0,n-1-k)aa[i]=abs(aa[i]-aa[i+1]);
	}
	return aa[0];
}
*/
int solve(){
	int flag2=0;
	rep(i,0,n)flag2|=s[i]=='2';

	int ans;
	if(flag2){
		int mod2=0;
		rep(i,0,n){
			int odd=((n-1)&i)==i;
			mod2^=(s[i]&odd);
		}
		ans=mod2;
	}else{
		int mod2=0;
		rep(i,0,n){
			int odd=((n-1)&i)==i;
			mod2^=(s[i]&(odd*2));
		}
		ans=mod2;
	}
	
	return ans;
}
/*
int dfs(int k){
	if(k==n){
		if(solve()!=f()){
			printf("%d %d ",solve(),f());puts(s);
		}
	}else{
		rep(i,0,3){
			s[k]=i+'1';
			dfs(k+1);
		}
	}
}
*/

int main(){
	scanf("%d %s",&n,s);
	printf("%d",solve());
}

Measured memory_bytes: 1152
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

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

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long w = in.nextLong();
			long a = in.nextLong(), b = in.nextLong();
			if (a > b) {
				long t = a;
				a = b;
				b = t;
			}
			out.println(max(b-(a+w),0));

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21460
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

MOD = 10 ** 9 + 7

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N+100)
power_inv = [1] * (N+100)
for i in range(1,N+100):
    power[i] = power[i-1] * 2 % MOD
    power_inv[i] = power_inv[i-1] * x % MOD

# 部分木の大きさ
answer = 0
size = [1] * (N+1)
for v in order[::-1]:
    p = parent[v]
    size[p] += size[v]
    A = [size[w] for w in graph[v] if w != p] # 部分木のサイズ集合
    if v != root:
        A.append(N - 1 - sum(A))
    if len(A) == 1:
        continue
    prod = 1
    coef = 1
    for x in A:
        prod *= power_inv[x]
        prod %= MOD
        coef += (power[x] - 1)
    E = 1 - prod * coef % MOD
    answer += E

answer *= power_inv[1]
answer %= MOD
print(answer)

Measured memory_bytes: 67344
#include "bits/stdc++.h"
using namespace std;
struct ${$(){ios_base::sync_with_stdio(0);cin.tie(0);}}$;

const int N = 200005;

int ans;
int main() {
   long long x, y;
   cin >> x >> y;
   while(x <= y) {
      ans += 1;
      x *= 2;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define INF 2147483647
#define fi first
#define se second
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b[1000000];
  cin>>a;
  for(int i=0;i<a;i++) cin>>b[i];
  sort(b,b+a);
  cout<<b[a-1]-b[0]<<"\n";
}
    
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define db long double 
#define ull unsigned long long int
// #define mp make_pair
#define F first
#define S second
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define Nmax 1000005
// #define INF 10000000000000
#define MOD 1000000007
#define MAXN 200005
 
using namespace std;

ll mod=998244353;
 
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

const ll M=3000006;
ll f[M],inv[M];

void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2,mod);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

ll bit[400005];
ll n;

void update(ll pos,ll val)
{
	for(ll i=pos;i<=n;i+=i & (-i))
		{bit[i]+=(val+mod)%mod;bit[i]%=mod;}
}

ll  query(ll pos)
{
	ll res=0;
	for(ll i=pos;i>0;i-=i & (-i))
		{res+=bit[i];res%=mod;}
	return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // compute();
    int tests=1;
    // cin>>tests;    
    while(tests--)
    {
    	ll i,l,j,k;
    	cin>>n>>k;
    	vector<pair<ll,ll>>v;
    	rep(i,1,k)
    	{
    		cin>>l>>j;
    		v.pb({l,j});
    	}
    	sort(all(v));

    	ll dp[n+1];
    	dp[1]=1;
    	update(1,1);
    	update(2,-1);
    	rep(i,1,n-1)
    	{
    		dp[i]=query(i);
    		rep(j,0,k-1)
    		{
    			ll r=v[j].S;
    			l=v[j].F;
    			update(i+l,dp[i]);
    			update(i+r+1,-dp[i]);
    		}
    	}

    	cout<<query(n);

    }

    return 0;
}
    

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n, m, k;
	cin >> n >> m >> k;
	vector<int> A(n), B(m);
	REP(i, n) cin >> A[i];
	REP(i, m) cin >> B[i];

	vector<ll> a(n + 1, 0);
	REP(i, n) a[i + 1] = a[i] + A[i];
	vector<ll> b(m + 1, 0);
	REP(i, m) b[i + 1] = b[i] + B[i];

	ll res = 0;
	int j = m;
	REP(i, n + 1) {
		if (a[i] > k) break ;
		while (b[j] > k - a[i])
			j -= 1;
		res = max(res, (ll)(i + j));
	}

	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 7932
n,l=map(int,input().split())
list_x=[l+x-1 for x in range(1,n+1)]
applepai=sum(list_x)
list_dif=[]
list_sum=[]
for i in range(len(list_x)):
    tmp=list_x.pop(i)
    list_dif.append(abs(applepai-sum(list_x)))
    list_sum.append(sum(list_x))
    list_x.insert(i,tmp)
indx=list_dif.index(min(list_dif))
ans=list_sum[indx]
print(ans)

Measured memory_bytes: 9208
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>

using namespace std;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,j,k) for(int i=j;i<(k);i++)
#define foreach(T,c,i) for(T::iterator i=c.begin();i!=c.end();i++)
typedef vector<int> Array;
typedef vector<Array> Mat;
const int INF = 99999999;
int N;
string str;
int dx[] = {1,0,1};
int dy[] = {0,1,1};
int solve(Mat &dp)
{
	int ans = 0;
	rep(i,N){
		rep(j,N){
			if(dp[i+1][j+1]==INF){
				dp[i+1][j+1] = min(dp[i][j],min(dp[i][j+1],dp[i+1][j]))+1;
				ans = max(dp[i+1][j+1],ans);
			}
		}
	}
	return ans;
}


int main(){
	while(1){
		cin >> N;
		if(N==0) return 0;
		vector<string> map;
		rep(i,N){
			cin >> str;
			map.pb(str);
		}
		Mat dp(N+1,vector<int>(N+1,INF));
		rep(i,N+1) dp[0][i] = 0;
		rep(i,N){
			dp[i+1][0] = 0;
			rep(j,N){
				if(map[i][j]=='*') dp[i+1][j+1] = 0;
			}
		}
		cout << solve(dp) << endl;
	}
	
	return 0;	
}

Measured memory_bytes: 0
num=input().split()
num=[int(a) for a in num]
numab=[abs(a) for a in num]
x=min(numab[0],numab[1])
y=min(numab[2],numab[3])


#+,+ and -,-
if (num[1]>=0 and num[3]>=0) or (num[0]<0 and num[2]<0):
  print(max(num[1]*num[3],num[0]*num[2]))
#+,- or-,+
else:
  print(-1*x*y)

Measured memory_bytes: 9208
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {

    string s; cin >> s;
    int n = s.length()-1;
    ll sum = 0,d = 10;
    if(s.length() == 1) {
        cout << (int)(s[0]-'0');
        return 0;
    }

    for (int bit = 0; bit < (1 << n); ++bit) {
        sum += (int)(s[n]-'0');
        d = 10;
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)){
                sum += (int)(s[n-(i+1)]-'0');
                d = 10;
            }else{
                sum += (int)(s[n-(i+1)]-'0')*d;
                d *= 10;
            }
        }
    }

    cout << sum;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <queue>
using namespace std;
int main(){
   int n, y;
   cin >> n >> y;
   for(int i = 0; i <= n; i++){
       for(int j = 0; j <= n; j++){
           int k = n-i-j;
           if(10000*i + 5000*j +1000*k == y and k >= 0){
               cout << i << " " << j << " " << k << endl;
               return 0;
           }
       }
   }

   cout << -1 << " " << -1 << " " << -1 << endl;
   return 0;
}


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

int main() {
    int n;
    cin >> n;
    string target;
    for (int i = 0; i < n; i++) {
        target.push_back(i + 'a');
    }
    set<string> res;
    res.insert("a");
    for (int i = 2; i <= n; i++) {
        set<string> temp = res;
        res.clear();
        for (string s : temp) {
            set<char> st(s.begin(), s.end());
            int k = st.size() + 1;
            for (int j = 0; j < k; j++) {
                string t = s;
                t.push_back(j + 'a');
                res.insert(t);
            }
        }
    }
    for (string r : res) {
        cout << r << "\n";
    }
    return 0;
}

Measured memory_bytes: 16512
program zero_one_unbalanced
  implicit none
  character(1000000) :: s = ''
  integer :: n, i
  integer, dimension(0:1000000) :: a = 0, x = 0
  read(*,'(a)') s
  n = len_trim(s)
  do i = 1, n
    a(i) = a(i - 1) + merge(1, -1, s(i:i) == '1')
  end do
  x(n) = a(n)
  do i = n - 1, 0, -1
    x(i) = max(x(i + 1), a(i))
  end do
  write(*,'(i0)') min(x(0) - f(x(0)), x(0) + 1 - f(x(0) + 1))
contains
  integer function f(m) result(res)
    integer, intent(in) :: m
    integer :: p, i
    p = 0
    do i = 1, n
      if (s(i:i) == '?') then
        if (x(i) + 2 * (p + 1) <= m) then
          a(i) = a(i - 1) + 1
          p = p + 1
        else
          a(i) = a(i - 1) - 1
        end if
      else
        a(i) = a(i - 1) + merge(1, -1, s(i:i) == '1')
      end if
    end do
    res = minval(a(0:n))
  end
end program zero_one_unbalanced

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

bool A[222222];
bool B[222222];

int main() {
   int N, M;
   cin >> N >> M;

   map<int, int> mp;
   for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      if (a == 1) A[b] = true;
      if (b == N) B[a] = true;
   }

   for (int i = 0; i <= N; i++) {
      if (A[i] && B[i]) {
         puts("POSSIBLE");
         return 0;
      }
   }

   puts("IMPOSSIBLE");

   return 0;
}

Measured memory_bytes: 640
N,M=map(x->parse(Int,x),split(readline()))
S=chomp(readline())
T=chomp(readline())
n=div(N,gcd(N,M))
m=div(M,gcd(N,M))
for i=1:gcd(N,M)
	if S[i*n-n+1]!=T[i*m-m+1]
		println(-1)
		exit()
	end
end
println(N*m)


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

int main(){
  string S;
  cin >> S;
  if(S.size()%2==0){
    int N=S.size()/2;
    vector<char> A(N),B(N);
    for(int i=0;i<N;i++){
      A.at(i)=S.at(i);
      B.at(i)=S.at(i+N);
    }
    int count=0;
    reverse(B.begin(),B.end());
    for(int i=0;i<N;i++){
      if(A.at(i)!=B.at(i)){
        count++;
      }
    }
    cout << count << endl;
  }else{
    int N=(S.size()-1)/2;
     vector<char> A(N),B(N);
    for(int i=0;i<N;i++){
      A.at(i)=S.at(i);
      B.at(i)=S.at(i+N+1);
    }
    int count=0;
    reverse(B.begin(),B.end());
    for(int i=0;i<N;i++){
      if(A.at(i)!=B.at(i)){
        count++;
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A, B, C, D, N, ans=0, left, right;
    vector<int> V(3);
    char tmp, tmp2;
    string S, S2;
    bool flag=true;
    
    cin >> A>>B>>C>>D;
    left = A+B;
    right = C+D;
    
    // cout << ans << endl;

    if(left <right )
    	cout << "Right" <<endl;
    else if(left > right)
    	cout << "Left" <<endl;
    else
	cout << "Balanced" <<endl;


    // string S;
    // cin >>S;
    // cout << S + "pp"<<endl;
    // if(A+B==C || B+C==A || C+A==B)
    // 	puts("Yes");
    // else
    // 	puts("No");
}


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int make_next(int x, int l)
{
  char s[8];
  int maxi, mini;
  sprintf(s, "%0*d", l, x);
  sort(s, s + l);
  mini = atoi(s);
  reverse(s, s + l);
  maxi = atoi(s);
  return maxi - mini;
}

int main()
{
  int n, l;
  while (n = in(), l = in()){
    map<int, int> vis;
    int turn = 0;
    do {
      vis.insert(make_pair(n, turn));
      n = make_next(n, l);
      turn++;
    } while (vis.find(n) == vis.end());
    printf("%d %d %d\n", vis[n], n, turn - vis[n]);
  }
  return 0;
}

Measured memory_bytes: 1232
def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return list(map(int, ss_raw()))


def ceil(num):
    if int(str(num)[-1]) == 0:
        return num
    return num + 10 - int(str(num)[-1])


total = 0
minus = 0
times = []
for i in xrange(5):
    times.append(int_raw())

for time in times:
    if int(str(time)[-1]) == 0:
        local_minus = 0
    else:
        local_minus = 10 - int(str(time)[-1])
    minus = max(minus, local_minus)
    total += ceil(time)

total -= minus

print(total)


Measured memory_bytes: 2692
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// 素因数分解
vector<pair<long long, int>> factorize(long long N)
{
  vector<pair<long long, int>> res;
  for (long long i = 2; i * i <= N; i++)
  {
    if (N % i != 0)
      continue;
    res.emplace_back(i, 0);
    while (N % i == 0)
    {
      N /= i;
      res.back().second++;
    }
  }
  if (N != 1)
    res.emplace_back(N, 1);
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<int> cnt(101);
  for (int i = 2; i <= N; i++)
  {
    vector<pair<ll, int>> factor = factorize(i);
    for (auto &it : factor)
    {
      if (it.first >= 2)
      {
        cnt[it.first] += it.second;
      }
    }
  }
  int n3 = 0, n5 = 0, n15 = 0, n25 = 0, n75 = 0;
  for (int i = 2; i <= 100; i++)
  {
    if (cnt[i] >= 74)
      n75++;
    if (cnt[i] >= 24)
      n25++;
    if (cnt[i] >= 14)
      n15++;
    if (cnt[i] >= 4)
      n5++;
    if (cnt[i] >= 2)
      n3++;
  }
  if (n5 < 2)
    cout << 0 << endl;
  else
  {
    int ans = 0;
    ans += n5 * (n5 - 1) / 2 * (n3 - 2);
    ans += n15 * (n5 - 1);
    ans += n25 * (n3 - 1);
    ans += n75;
    cout << ans << endl;
  }
  return 0;
}

// 1から100まで約数を数えていく．まず約数の数が奇数であるから2乗出来る数　


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int height[10];
    int i,j,damy;
    for(i=0;i<10;i++){
        scanf("%d",&height[i]);
    }
    for(i=0;i<10;i++){
        for(j=i+1;j<10;j++){
            if(height[i]>height[j]){
                damy=height[j];
                height[j]=height[i];
                height[i]=damy;
            }
        }
    }
    printf("%d\n%d\n%d\n",height[9],height[8],height[7]);
    return 0;
}
                

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

bool cnv(ll num){
  s = "";
  while(num > 0){
    s += num % 10;
    num /= 10;
  }
  rep(i,0,s.sz/2){
    if(s[i] != s[s.sz-1-i])return false;
  }
  return true;
}

int main(){
  cin >> n >> m;
  lep(i,n,m){
    if(cnv(i))l++;
  }
  print(l);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main ()
{
    int a,b;
    int x=0,y=0,z=0;
    int max=-100;

    cin>>a>>b;
    x = a+b;
    y = a-b;
    z = a*b;

  
    if(max<x)
    {
        max=x;
    }
    if(max<y)
    {
        max=y;
    }
    if(max<z)
    {
        max=z;
    }
    cout<<max;

    cout<<endl;
}

Measured memory_bytes: 256
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    temp1=input()
    temp2=input()
    temp3=input()
    


    print(temp1[0]+temp2[1]+temp3[2])
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}

int dp[3010][3010];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int n = (int)s.size();
    int m = (int)t.size();
    REP(i,n){
        REP(j,m){
            if(s[i]==t[j]) chmax(dp[i+1][j+1],dp[i][j]+1);
            chmax(dp[i+1][j+1],dp[i+1][j]);
            chmax(dp[i+1][j+1],dp[i][j+1]);
        }
    }

    string ans = "";
    while(n > 0 && m > 0){
        if(dp[n-1][m]==dp[n][m]) --n;
        else if(dp[n][m-1]==dp[n][m]) --m;
        else {
            ans = s[n-1] + ans;
            --n; --m;
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void input(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

void solveTest(){
	
}

int main(){
	fastio();
	//input();

	/*int t;
	cin>>t;
	while(t--){
		solveTest();
	}*/

	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,ans;
  ans = 0;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k)){
          if(vec.at(k)-vec.at(i) < vec.at(j) && vec.at(j) < vec.at(k)+vec.at(i))
            ans++;
        }
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 3624
n=gets.chomp.split(' ')
x=n[0].to_i
y=n[1].to_i
z=n[2].to_i

cn=1
maxc=0

while true
    if y*cn+z*(cn+1)>x
        break
    else
        maxc=cn
    end
    cn+=1
end

puts maxc


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007

typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, ma, mb;

li a[100];
li b[100];
li c[100];



li dp[404][404];

int main() {
    cin >> n >> ma >> mb;
    rin{
        cin >> a[i] >> b[i] >> c[i];
    }

    for (li aa = 400; aa >= 0; aa--) {
        for (li bb = 400; bb >= 0; bb--) {
            dp[aa][bb] = INF;
        }
    }
    dp[0][0] = 0;
    rin{
        for (li aa = 400; aa >= 0; aa--) {
            for (li bb = 400; bb >= 0; bb--) {
                if (aa >= a[i] && bb >= b[i]) {
                    dp[aa][bb] = min(dp[aa][bb], dp[aa - a[i]][bb - b[i]] + c[i]);
                }
            }
        }
    }
    li res = INF;
    repp(i, 1, 4000) {
        li aa = i * ma;
        li bb = i * mb;
        if (max(aa, bb) > 400) {
            break;
        }
        res = min(res, dp[aa][bb]);
    }
    cout << (res == INF ? -1 : res) << endl;


    return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <bitset>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

#define ALL(g) (g).begin(), (g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair

typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

const int INF = INT_MAX;

int main(void) {
    int v, e, s, t, d;
    scanf("%d %d", &v, &e);

    int g[v][v];
    rep(i, v) rep(j, v) g[i][j] = INF;
    rep(i, v) g[i][i] = 0;

    rep(i, e) {
        scanf("%d %d %d", &s, &t, &d);
        g[s][t] = d;
    }
    
    rep(k, v) {
        rep(i, v) {
            if (g[i][k] == INF) continue;
            rep(j, v) {
                if (g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    int flag = 1;
    rep(i, v) {
        if (g[i][i] < 0) {
            flag = 0;
            break;
        }
    }

    if (flag) {
        rep(i, v) {
            rep(j, v) {
                if (j) printf(" ");
                if (g[i][j] == INF) printf("INF");
                else printf("%d", g[i][j]);
            }
            printf("\n");
        }
    }
    else printf("NEGATIVE CYCLE\n");

    return 0;
}

Measured memory_bytes: 1232
#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 n;
    cin >> n;
    vector<int> a(n);
    vector<int> l(n);
    vector<int> r(n);
    rep(i, n) cin >> a.at(i);
    int lg = a.at(0);
    int rg = a.at(n-1);
    rep(i, n){
        lg = __gcd(lg, a.at(i));
        l.at(i) = lg;
    }
    for(int i=n-1; i>=0; i--){
        rg = __gcd(rg, a.at(i));
        r.at(i) = rg;
    }
    int m = 0;
    int ans = 0;
    rep(i, n){
        if(i == 0){
            m = r.at(1);
        }else if(i == n-1){
            m = l.at(n-2);
        }else{
            m = __gcd(l.at(i-1), r.at(i+1));
        }
        if(m > ans) ans = m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()

using LL = long long;
int vis[100005];
int n,m;
vector <int> ans;

#define mp(x,y) make_pair(x,y)

using P = pair<int,int> ;
vector<pair<int,int> > g[100005];
int a[100005];
bool b[100005];
vector <int> lsh;
void dfs(int x)
{
	vis[x]=1;
	for(auto u:g[x])
	{
		if(vis[u.first]) continue;
		dfs(u.first);
		if(b[u.first])
		{
			ans.push_back(u.second);
			b[u.first]^=1;
			b[x]^=1;
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
	cin>>n>>m;
	vector <pair<int,int> > psort;
//	psort.reserve(n);
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
		psort.push_back(mp(a[i],b[i]));
		lsh.push_back(a[i]);
	}
	sort(all(psort));
	for(int i=0;i<n;i++)
	{
		a[i]=psort[i].first;
		b[i]=psort[i].second;
	}
	for(int i=n;i>=0;i--)
	{
		b[i]^=(i?b[i-1]:0);
	}
	sort(all(lsh));
    for (int i = 0; i < m; ++i) {
    	int l,r;
		cin>>l>>r;
		l=lower_bound(all(lsh),l)-lsh.begin();
		r=upper_bound(all(lsh),r)-lsh.begin();
		g[l].push_back(make_pair(r,i));
		g[r].push_back(make_pair(l,i));
    }
	for(int i=0;i<=n;i++)
	{
		if(vis[i]) continue;
		dfs(i);
		if(b[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	sort(all(ans));
	cout<<ans.size()<<endl;
	for(auto x:ans)
	{
		cout<<x+1<<' ';
	}
	cout<<endl;
    return 0;
}


Measured memory_bytes: 15092