akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

int n;
int A[100005],B[100005];
struct uf{
  static const int MAXN=100005;
  int par[MAXN];
  lint dp[MAXN],size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,n){
      dp[i]=A[i];
      size[i]=B[i];
    }
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int v,set<int> S){

    for(auto u:S) chmin(dp[v],max(dp[u],A[v]-size[u]));
    for(auto u:S){
      size[v]+=size[u];
      assert(par[u]==-1);
      par[u]=v;
    }
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};

uf u;

const lint INF=1e18;
int m;
vector<int> g[100005];

int perm[100005];
int main(){
  cin>>n>>m;
  REP(i,n){
    scanf("%d%d",&A[i],&B[i]);
    A[i]=max(0,A[i]-B[i]);
  }
  debug(A,A+n);
  u.init();
  REP(i,m){
    int a,b;scanf("%d%d",&a,&b);
    --a;--b;
    g[a].pb(b);
    g[b].pb(a);
  }
  REP(i,n) perm[i]=i;
  sort(perm,perm+n,[&](int a,int b) {
      return mp(A[a],a)<mp(A[b],b);
      });
  REP(i,n){
    int v=perm[i];
    dump(v);
    set<int> S;
    for(auto to:g[v]) if(mp(A[v],v)>mp(A[to],to) && !u.same(v,to)){
      S.insert(u.root(to));
    }
    u.unite(v,S);
  }
  int r=u.root(0);
  REP(i,n) assert(u.same(i,0));
  dump(u.dp[r]);
  lint res=u.dp[r]+accumulate(B,B+n,0ll);
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 12156
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	String S = sc.next();
	String T = sc.next();
	int A = sc.nextInt();
	int B = sc.nextInt();
	String U = sc.next();
	if(U.equals(S)) System.out.print((A-1) +" "+ B);
	else System.out.print(A +" "+ (B-1));
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  
  int a[n+5];
  int sum = 0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i]-1;
  }
 
  cout<<sum<<'\n';
 	
  return 0;
}

Measured memory_bytes: 256
// 幅優先探索版
package main

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

type intQueue []int

func (queue *intQueue) enqueue(i int) {
	*queue = append(*queue, i)
}

func (queue *intQueue) dequeue() int {
	result := (*queue)[0]
	*queue = (*queue)[1:]
	return result
}

func createGroups(n int, links [][]int) []int {
	groups := make([]int, n)
	for i := 0; i < n; i++ {
		groups[i] = i
	}
	var queue intQueue = make([]int, 0)
	for i := 0; i < n; i++ {
		if groups[i] != i {
			continue
		}
		queue.enqueue(i)
		for len(queue) != 0 {
			j := queue.dequeue()
			for _, k := range links[j] {
				if groups[k] != i {
					groups[k] = i
					queue.enqueue(k)
				}
			}
		}
	}
	return groups
}

func readLinks(n, k int) [][]int {
	links := make([][]int, n)
	for i := 0; i < k; i++ {
		p := readInt()
		q := readInt()
		links[p-1] = append(links[p-1], q-1)
		links[q-1] = append(links[q-1], p-1)
	}
	return links
}

func main() {
	n := readInt()
	k := readInt()
	l := readInt()

	roadLinks := readLinks(n, k)
	railLinks := readLinks(n, l)

	roadGroups := createGroups(n, roadLinks)
	railGroups := createGroups(n, railLinks)

	d := map[int]int{}
	for i := 0; i < n; i++ {
		d[2000001*roadGroups[i]+railGroups[i]]++
	}

	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = d[2000001*roadGroups[i]+railGroups[i]]
	}
	printIntln(result...)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func printIntln(v ...int) {
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}


Measured memory_bytes: 35456
// kartikay26
#include <bits/stdc++.h>
using namespace std;
#define debug(x...) 
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
typedef long long int ll; typedef double db; typedef vector<ll> vi; typedef pair<ll, ll> pii;
#define int ll
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
void print(){cout << endl;} void prints(){}
template<typename T> void get(T* x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T> void get(T& x, int n){for (int i = 0; i < n; ++i) { cin >> x[i]; }}
template<typename T, typename... A> void print(T x,A... r){cout << x << " ";print(r...);}
template<typename T, typename... A> void prints(T x,A... r){cout << x << " ";prints(r...);}

const int mod = 1e9+7;
const int N = 1e6+1;

int32_t main(){
	fast_io();

	int n; cin >> n;
	int ans = n - 1;
	for (int i = 1; i < 1e6+1; ++i) {
		int j = n / i;
		int z = n % i;
		if(z == 0){
			ans = min(ans, i + j - 2);
		}
	}
	print(ans);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> A(n+1,0);
    rep(i,m){
        int tmp;
        cin >> tmp;
        A[tmp] = 1;
    }
    vector<ll> dp(n+1);
    dp[0]=1;
    if(A[1]==1)dp[1]=0;
    else dp[1]=1;
    for(int i=2; i<=n; i++){
        if(A[i]==1){
            dp[i]=0;
        }
        else{
            dp[i] = (dp[i-1]+dp[i-2])%1000000007;
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long int lli;
const lli inf = 1e18;
const lli mod = 1e9 +7;
typedef pair<lli, lli> pll;

int main(){
	int n,r;
	cin >> n >> r;
	vector<int> p(n);
	for(int i=0; i<n; i++){
		cin >> p[i];
		p[i]--;
	}
	map<int, int> numsmap;
	vector<bool> used(n, false);
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		used[i] = true;
		int curr = p[i];
		int num = 1;
		while(curr != i){
			used[curr] = true;
			curr = p[curr];
			num++;
		}
		numsmap[num]++;
	}

	vector<int> nums;
	for(auto p: numsmap){
		int key = p.first;
		int value = p.second;
		int power2 = 1;
		while(power2 <= value){
			nums.push_back(key*power2);
			value -= power2;
			power2 *= 2;
		}
		nums.push_back(key*value);
	}

	vector<bool> dp(n+1, false);
	dp[0] = true;
	for(int i: nums){
		for(int j=n; j>=0; j--){
			if(dp[j]) dp[j+i] = true;
		}
	}
	if(dp[r]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl; 
	}
	return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

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

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string s;
    cin >> s;

    int ans = 0;
    rep(i, s.size()){
        rep(j, s.size() - i + 2){
            string tmp = "";
            repi(k, i, i + j){
                tmp += s[k];
            }
            if(count(all(tmp), 'A') + count(all(tmp), 'T') + count(all(tmp), 'G') + count(all(tmp), 'C') == tmp.size()){
                ans = max(ans, (int)tmp.size());
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  int a[3];
  int k;
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  cin >> k;

  sort(a, a + 3);

  int max = a[2];
  for (int i = 0; i < k; i++) {
    max *= 2;
  }

  cout << a[0] + a[1] + max << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char s[128];
    scanf("%s",s);

	int l = strlen(s);
	for ( int i = 0 ; i < l/2 ; i++ ) {
		if ( s[i] != s[l-i-1] ) {
			printf("No");
			exit(0);
		}
	}
	for ( int i = 0 ; i < (l/2)/2 ; i++ ) {
		if ( s[i] != s[l/2-i-1] ) {
			printf("No");
			exit(0);
		}
		if ( s[l-i-1] != s[l-1-(l/2-i-1)] ) {
			printf("No");
			exit(0);
		}
	}

	printf("Yes");
}


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

int main(){
	string s;
	getline(cin, s);
	int i = 0;
	while(s[i] != '\0'){
		if('a' <= s[i] && s[i] <= 'z'){
			s[i] += 'A' - 'a';
		}
		i++;
	}
	cout << s << endl;
}


Measured memory_bytes: 3072
s = input()


def func(s):
    for i in range(len(s)):
        if(i % 2 != 0 and s[i] == 'R'):
            print('No')
            return
        if(i % 2 != 1 and s[i] == 'L'):
            print("No")
            return
    print("Yes")
    return


func(s)

Measured memory_bytes: 38384
// =====================================================================================
// 
//       Filename:  B.cpp
//        Created:  2017년 06월 10일 21시 01분 25초
//       Compiler:  g++ -O2 -std=c++14
//         Author:  baactree ,  bsj0206@naver.com
//        Company:  Chonnam National University
// 
// =====================================================================================

#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100];
int main(){
	scanf("%d", &n);
	for(int i=0;i<n;i++)
		scanf("%d", &arr[i]);
	sort(arr, arr+n);
	printf("%d\n", arr[n-1]-arr[0]);
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll n;
cin>>n;
pair<pair<string,ll>,ll>data[n];
string s;
ll p;
for(int i=0;i<n;i++){
    cin>>s>>p;
    p*=-1;
    data[i]=make_pair(make_pair(s,p),i);
}
sort(data,data+n);
for(int i=0;i<n;i++){
    cout<<data[i].second+1<<endl;
}

}











Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int mod=1000000007 ;

void solve(){
	
	int a ;
	cin>>a ;
	cout<<a+pow(a,2)+pow(a,3) ;

}

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 4100
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i<(n);++i)


bool check_bit(int mask, int pos)
{
    /*
     - check_bit(2(0010), 1) -> true
     - check_bit(1(0001), 1) -> false
     - check_bit(1(0001), 0) -> true
     */
    return ((mask & (1 << pos)) != 0) ? true : false;
}


int main()
{
    // input
    int d, g;
    cin >> d >> g;

    vector<pair<int,int>> ps;
    rep(i, d) {
        int p, c;
        cin >> p >> c;
        ps.push_back(make_pair(p, c));
    }

    // main
    int ans = 10 * 100;
    int mask_size = (1 << d);
    for (int mask=0; mask<mask_size; ++mask) {
        ll point = 0L;
        int cnt = 0;

        // all green mask
        for (int j=0; j<d; ++j) {
            if (check_bit(mask, j)) {
                point += (ps[j].first * (j + 1) * 100) + ps[j].second;
                cnt += ps[j].first;
            }
        }
        if (point >= g) {
            ans = min(ans, cnt);
            continue;
        }

        // greedy
        for (int j=d-1; j>=0; --j) {
            if (!check_bit(mask, j)) {
                int num_prob = ps[j].first;
                ll bonus_pt = ps[j].second;
                if (g - point <= num_prob * (j + 1) * 100) {
                    int greedy_cnt = (g - point) / ((j+1) * 100);
                    greedy_cnt += (((g - point) % ((j+1) * 100) > 0) ? 1 : 0);
                    cnt += greedy_cnt;
                    point += (greedy_cnt * (j+1) * 100);
                    if (greedy_cnt == num_prob) point += bonus_pt;
                } else {
                    // All
                    cnt += num_prob;
                    point += (num_prob * (j+1) * 100) + bonus_pt;
                }
            }
            if (point >= g) break;
        }

        if (point >= g)
            ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
#define ll long long

using namespace std;


#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

const ll inf =1000000007;
typedef pair<ll,ll> Pair;


typedef vector<ll> vl;

void solve(){
    ll n;
    cin >>n;
    vl vec;
    rep(i,n){
        ll a;
        cin >>a;
        vec.pb(a);
    }
    isort(vec);
    map<ll,Pair> mp;
    ll m=vec.back();
    ll count=0;
    for(ll i=0;i<n;i++){
        if(mp.find(vec[i])!=mp.end()){
            if(mp[vec[i]].second==1){
                count--;
                mp[vec[i]]=make(1,0);
            }
        }
        else {
            ll t=vec[i];
            mp[t]=make(1,1);
            count++;
            for (ll j = 2;t*j<=m;j++){
                mp[t*j]=make(1,0);
            }
        }
    }
    kaku(count);
}

int main(){
    solve();
}

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

int main() {
  int n;
  cin >> n;
  set<int> stn;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    stn.insert(tmp);
  }
  int m;
  cin >> m;
  set<int> stm;
  for (int i = 0; i < m; i++) {
    int tmp;
    cin >> tmp;
    stm.insert(tmp);
  }

  if (includes(stn.begin(), stn.end(), stm.begin(), stm.end()))
  cout << 1 << endl;
  else
  cout << 0 << endl;
}


Measured memory_bytes: 21824
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int N = 1e5+10;
int a[N];
int main(){
	int n;
	scanf("%d",&n);
	int maxx=0,minn=n;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		maxx=max(maxx,a[i]);
		minn=min(minn,a[i]);
	} 
	if(maxx-minn>=2)return 0*printf("No\n");//不存在相差大于2的答案 
	bool flag=true;
	for(int i=1;i<n;i++)if(a[i]!=a[0])flag=false;
	if(flag==false)
	{
		int cnt = 0;
		for(int i=0;i<n;i++)if(a[i]==maxx-1)cnt++; 
		if(cnt<maxx&&2*(maxx-cnt)<=n-cnt)return 0*printf("Yes\n");
		return 0*printf("No\n");
	}else{
		if(a[0]==n-1)return 0*printf("Yes\n");
		else if(2*a[0]<=n)return 0*printf("Yes\n");
		else return 0*printf("No\n");
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

template <ull M> struct modular {
  using m = modular;
  ull v;
  modular() : v(0) {}
  template <typename T> modular(T a) : v((a %= M) < 0 ? a + M : a) {}
  m operator-() const { return m() -= *this; }
  template <typename T> m& operator+=(T r) { if ((v += m(r).v) >= M) v -= M; return *this; }
  template <typename T> m& operator-=(T r) { if (v < m(r).v) v += M; v -= m(r).v; return *this; }
  template <typename T> m& operator*=(T r) { v = (v * m(r).v) % M; return *this; }
  template <typename T> m& operator/=(T r) { return *this *= power(m(r), M - 2); }
  template <typename T> m operator+(T r) { m l = *this; return l += r; }
  template <typename T> m operator-(T r) { m l = *this; return l -= r; }
  template <typename T> m operator*(T r) { m l = *this; return l *= r; }
  template <typename T> m operator/(T r) { m l = *this; return l /= r; }
  template <typename T> bool operator==(T r) { return v == m(r).v; }
  friend ostream& operator<<(ostream& os, m r) { os << r.v; return os; }
  static m power(m b, ll e) {
    if (e == 0) { return 1; }
    m x = power(b * b, e / 2);
    return (e % 2) ? b * x : x;
  }
};

constexpr ull MOD = 1000000007LL;

using mint = modular<MOD>;

mint choose(int n, int k) {
  if (k == 0) { return 1; }
  return choose(n, k - 1) * mint(n - k + 1) / mint(k);
}

int main() {
  ll N, A, B; cin >> N >> A >> B;
  cout << mint::power(2, N) - choose(N, A) - choose(N, B) - 1 << endl;
  return 0;
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string S, T; cin >> S >> T;
  ll cnt = 0;
  for (ll i = 0; i < (ll)S.size(); i++) {
    if (S.at(i) != T.at(i)) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



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

using namespace std;

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vector<int> arr(n);
  long long sum = 0;
  for(int i = 0; i <n ;++i) {
    cin >>arr[i];
    sum += arr[i];
  }

  long long mn = numeric_limits<long long>::max();
  long long a = 0, b = sum;
  for(int i = 1; i < n; ++i) {
    a += arr[i - 1];
    b -= arr[i - 1];
    mn = min(mn, abs(a - b));
  }

  cout << mn;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
	int max, dur, min;
	int temp;

	scanf("%d %d %d", &max, &dur, &min);

	if (min > dur){
		temp = min;
		min = dur;
		dur = temp;
	}
	if (dur > max){
		temp = max;
		max = dur;
		dur = temp;
	}
	if (min > dur){
		temp = min;
		min = dur;
		dur = temp;
	}


	printf("%d %d %d", min, dur, max);

	putchar('\n');

	return 0;

}

Measured memory_bytes: 600
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        if(N*2>M) System.out.println(M/2);
        else System.out.println((N*2+M)/4);
    }
}


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

typedef long long ll;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;

void show(){
  if (TEST){cout << endl;}
}

void show(string x){
  if (TEST){cout << x;}
}

void show(string x,bool enter){
  if (TEST){
    if (enter) cout << "<#> " << x << endl;
    else cout << x;
  }
}

void show(ll x){
  if (TEST){cout << x;}
}

void show(ll x,bool enter){
  if (TEST){
    if (enter) cout << "<#> " << x << endl;
    else cout << x;
  }
}


void show(p_ll p){
  if (TEST){
    cout << "{ ";
    show(p.first);
    cout << " ";
    show(p.second);
    cout << " }";
  }
}

void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << " ";
    }cout <<"<end>"<< endl;
  }
}

void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
    }
  }
}

void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
    }
  }
}
#include<queue>

ll N,M;
v_ll C;
vv_ll G;
vector<bool> noseek;
v_ll ans;
queue<ll> que;
int main(){
  //TEST=true;
  cin >> N;
  C.assign(N+10,0);
  G.assign(N+10,v_ll());
  ans.assign(N+10,0);
  noseek.assign(N+10,true);
  for(ll i=1;i<=N-1;i++){
    ll a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for(ll i=1;i<=N;i++){
    cin >> C[i];
  }
  sort (C.begin()+1,C.begin()+N+1);
  que.push(1);
  ll idx=N;
  while (!que.empty()){
    ll f=que.front();
    que.pop();
    noseek[f]=false;
    ans[f]=C[idx];
    idx--;
    for (ll i=0;i<G[f].size();i++){
      if (noseek[G[f][i]]){
        que.push(G[f][i]);
      }
    }
  }
  M=0;

  for(ll i=1;i<=N-1;i++){
    M+=C[i];
  }
  show(M,true);
  show(ans);
  cout << M << endl;
  for (ll i=1;i<=N;i++){
    if (i>1) cout << " ";
    cout << ans[i];
  }cout << endl;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}



Measured memory_bytes: 21768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#define INF 10000000000000
using namespace std;
using ll = long long;
ll n,w;
ll grid[510][510]={};
bool flag[510][510];
ll xm[4] = {-1,0,1,0};
ll ym[4] = {0,-1,0,1};
ll kuro;
ll siro;
stack<int> s; 
ll dfs(int x,int y){
    siro=0;
    kuro=0;
    s.push(x);
    s.push(y);
    while(s.size()>0){
        int y = s.top();
        s.pop();
        int x = s.top();
        s.pop();
        
        if(grid[x][y]==1){
            kuro++;
        }else{
            siro++;
        }
        for(int i=0;i<4;i++){
            if(x+xm[i]<0) continue;
            if(y+ym[i]<0) continue;    
            if(grid[x+xm[i]][y+ym[i]]==0&&flag[x+xm[i]][y+ym[i]]==false&&grid[x][y]==1){
               flag[x+xm[i]][y+ym[i]]=true;
               s.push(x+xm[i]);
               s.push(y+ym[i]);
            }else if(grid[x+xm[i]][y+ym[i]]==1&&flag[x+xm[i]][y+ym[i]]==false&&grid[x][y]==0){
               flag[x+xm[i]][y+ym[i]]=true;
               s.push(x+xm[i]);
               s.push(y+ym[i]);
            }
        }
    }
    return siro*kuro;
}


int main() {
    cin >> n >> w;
    ll ans = 0;
    memset(grid,-1,sizeof(grid));
    memset(flag,0,sizeof(flag));
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(int j=0;j<w;j++){
            if(s[j] == '#'){
                grid[i][j] = 1; 
            }else{
                grid[i][j] = 0;
            }
            flag[i][j] = false;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<w;j++){
            if(grid[i][j]==1&&flag[i][j]==false){
                flag[i][j]=true;
                ans+=dfs(i,j);
            }
        }
    }
    cout << ans << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

signed main(){
    int l;
    cin >> l;

    int x = l, n = 0;
    while(x > 1){
        n++;
        x /= 2;
    }

    set<tuple<int,int,int>> st;
    REP(i, n){
        st.insert(make_tuple(i, i+1, 0));
        st.insert(make_tuple(i, i+1, 1 << i));
    }

    int m = (1 << n);
    int v = n;

    while(v >= 0){
        if(m + (1 << v) - 1 < l){
            st.insert(make_tuple(v, n, m));
            m += (1 << v);
        }
        v--;
    }

    cout << n+1 << " " << st.size() << endl;

    for(const auto& e : st){
        cout << get<0>(e) + 1 << " " << get<1>(e) + 1 << " " << get<2>(e) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int N,X[100100],C[1<<16],D[1<<16];

int main()
{
	scanf ("%d",&N);
	for (int i=1;i<N;i++){
		int x,y,c; scanf ("%d %d %d",&x,&y,&c);
		X[x] ^= c;
		X[y] ^= c;
	}

	for (int i=0;i<N;i++) C[1<<X[i]]++;
	C[1] = 0;

	int ans = 16;
	for (int i=1;i<16;i++){
		int &c = C[1<<i];
		ans += c / 2;
		c = c % 2 * i;
	}

	for (int i=1;i<(1<<16);i++){
		int x = i & (-i);
		C[i] = C[i-x] ^ C[x];

		D[i] = -99999;
		for (int j=i;j;j=(j-1)&i) if (C[j] == 0){
			if (D[i] < D[i-j] + 1)
				D[i] = D[i-j] + 1;
		}
	}
	ans -= D[(1<<16)-1];

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

	return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = []
for i in range(n):
    h.append(list(map(int,input().split())))
dp = [[0]*3 for i in range(n)]


dp[0][0] = h[0][0]
dp[0][1] = h[0][1]
dp[0][2] = h[0][2]
for i in range(1,n):
    for j in range(3):
        if j == 0:
            dp[i][j] = max(dp[i-1][1]+h[i][j],dp[i-1][2]+h[i][j])
        elif j == 1:
            dp[i][j] = max(dp[i-1][0]+h[i][j],dp[i-1][2]+h[i][j])
        elif j == 2:
            dp[i][j] = max(dp[i-1][0]+h[i][j],dp[i-1][1]+h[i][j])
print(max(dp[-1]))

Measured memory_bytes: 74328
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  string A[1000];
  queue<pair<int,pair<int,int>>> que; //(y,(x,count))
  for(int i=0;i<H;i++){
    cin>>A[i];
    for(int j=0;j<W;j++){
      if(A[i][j]=='#'){
        que.push(make_pair(i,make_pair(j,0)));
      }
    }
  }
  int count=0;
  int dy[4]={-1,1,0,0};
  int dx[4]={0,0,-1,1};
  while(!que.empty()){
    int y=que.front().first;
    int x=que.front().second.first;
    int z=que.front().second.second;
    que.pop();
    for(int i=0;i<4;i++){
      if(y+dy[i]>=0&&x+dx[i]>=0&&y+dy[i]<H&&x+dx[i]<W){
        if(A[y+dy[i]][x+dx[i]]=='.'){
          count++;
          A[y+dy[i]][x+dx[i]]='#';
          que.push(make_pair(y+dy[i],make_pair(x+dx[i],z+1)));
          count=z+1;
        }
      }
    }
  }
  cout<<count<<endl;
  
  return 0;
}

Measured memory_bytes: 13456
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<string> &a){sort(a.begin(),a.end()) ;}
void myrev(vll &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n,m ;
	cin >> n >> m ;
	string r ; cin >> r ;
	vll ans ;
	string f ;
	for(int i=0;i<m;i++) f += '1' ;
	f += r ;
	r = f ;
	ll pos = n+m ;
	while(pos!=m){
		bool ok = false ;
		for(int i=m;i>0;i--){
			if(r.at(pos-i)=='0'){
				pos -= i ;
				ans.push_back(i) ;
				ok = true ;
				break ;
			}
		}
		if(!ok){
			cout << -1 << endl ;
			return 0 ;
		}
	}
	myrev(ans) ;
	for(int i=0;i<ans.size();i++){
		cout << ans.at(i) ;
		if(i==ans.size()-1) cout << endl ;
		else cout << " " ;
	}
}


Measured memory_bytes: 1652
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int a[100000];

signed main() {
	int n; scanf("%lld", &n);
	map<int, ll>mp, ans;
	set<int>s;
	rep(i, n)scanf("%lld", &a[i]), mp[a[i]]++, s.insert(a[i]);
	ll sum = 0;
	for (auto it = mp.rbegin(); it != mp.rend(); it++) {
		auto p = *it;
		sum += p.second;
		if (it == --mp.rend()) {
			ans[p.first] = sum*p.first;
		}
		else {
			auto np = *++it; it--;
			ans[p.first] = sum*(p.first - np.first);
		}
	}
	rep(i, n) {
		int cnt = 0;
		auto it = s.begin();
		for (; it != s.end(); it++) {
			if (*it > a[i])break;
			cnt += ans[*it];
		}
		printf("%lld\n", cnt);
		s.erase(s.begin(), it);
	}
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

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

    int D;
    cin >> D;
    ll c[26], a[D][26];
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26) cin >> a[i][j];
    }

    int N = 500;
    pii pre[D+1][N];
    vector<int> state[D+1][N];
    ll sum[D+1][N];
    fill(sum[0], sum[D+1], -INF);
    sum[0][0] = 0;
    state[0][0].assign(26, -1);

    rep(i, D){
        vector<pair<ll, pii>> next;
        rep(j, N){
            if(sum[i][j] == -INF) break;
            ll pena = 0;
            rep(k, 26){
                pena += c[k]*(i-state[i][j][k]);
            }
            rep(k, 26){
                ll tmp = sum[i][j]+a[i][k]-pena;
                tmp += c[k]*(i-state[i][j][k]);
                next.eb(tmp, pii(j, k));
            }
        }
        sort(all(next), greater<pair<ll, pii>>());
        rep(j, min(N, sz(next))){
            sum[i+1][j] = next[j].first;
            pre[i+1][j] = next[j].second;
            state[i+1][j] = state[i][pre[i+1][j].first];
            state[i+1][j][pre[i+1][j].second] = i;
        }
    }

    ll M = -INF;
    int ptr = 0;
    rep(i, N){
        if(chmax(M, sum[D][i])) ptr = i;
    }

    vector<int> ans(D);
    rep3(i, D, 1){
        ans[i-1] = pre[i][ptr].second;
        ptr = pre[i][ptr].first;
    }
    
    for(auto &e: ans) cout << e+1 << endl;
}

Measured memory_bytes: 30908
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		boolean isoddcount = false;
		long ans = 0;
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			if (a[i] < 0) {
				isoddcount = (!isoddcount);
				a[i] = -a[i];
			}
			ans += (long)a[i];
		}
		Arrays.sort(a);
		sc.close();
		if(isoddcount){
			ans -= 2 * (long)a[0];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 51476
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int alpha = (n-1) / 2 - 1;
  int beta = (n+3) / 2 - 1;
  string sub = s.substr(0, alpha+1);
  string ss = s.substr(beta, n - beta);
  string revs = s;
  reverse(revs.begin(), revs.end());
  string revsub = sub;
  reverse(revsub.begin(), revsub.end());
  string revss = ss;
  reverse(revss.begin(), revss.end());
  if(s == revs && sub == revsub && ss == revss) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += Math.Min(
                x[i] * 2,
                Math.Abs(k - x[i]) * 2);
        }

        Console.WriteLine(ans);
    }
}


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

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

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

    ll a,b;
    cin >> a >> b;
    if(a < b)
    {
		cout <<  min(b - a, a);
	}
	else
	{
		a = a - (a/b)*b;
		cout <<  min(b-a,a);
	}
	


    return 0;
}

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

int main(){
    Int N; cin >> N;
    if(N == 0) {
        cout << 0 << endl; return 0;
    }

    Int pow2 = -2, cur = 0; string ans = "";
    while(cur != N){
        if((N-cur) % abs(pow2) == 0){
            ans += '0';
        } else {
            ans += '1'; cur += -pow2/2;
        }
        pow2 *= -2;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll p[100];
int main(){
    ll n,ans = 0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>p[i],ans += p[i];
    sort(p,p+n);
    cout<<ans - p[n-1]/2<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    S = INPUT()
    T = INPUT()

    ans = INF
    for i in range(len(S)-len(T)+1):
        cnt = 0
        for j in range(len(T)):
            if S[i:i+len(T)][j] == T[j]:
                cnt += 1
        ans = min(ans, len(T) - cnt)

    print(ans)



if __name__ == '__main__':
    main()


Measured memory_bytes: 9912
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif

ll t;
ll a;

cin>>t;
cin>>a;

if (t*500<a)
{
	cout<<"No"<<endl;
}

else
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
// 選択ソート
#include<iostream>
#include<algorithm>

using namespace std;

typedef struct card
{
    char suit;
    char value;
}Card;

// バブルソートを実施する関数
void bubbleSort(Card A[], int n)
{
    Card tmp;

    int count = 0, j = 0;
    bool flag = true;

    while( flag )
    {
        flag = false;

        for(int i = n - 1; i > j; i--)
        {

            if( A[i - 1].value > A[i].value )
            {
                // 値の入れ替え
                tmp = A[i];
                A[i] = A[i - 1];
                A[i - 1] = tmp;

                flag = true;

                // 交換回数の保存
                count++;
            }
        }

        j++;
    }

    return;
}

// 選択ソートを実施する関数
void selectionSort(Card A[], int n)
{

    int count = 0;

    // 最小値の存在する配列の要素No.
    int min_pos;

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

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

            if( A[j].value < A[min_pos].value )
            {
                // 最小値の存在する位置を保存する
                min_pos = j;
            }
        }

        if( i != min_pos )
        {
            // 最小値を交換する
            swap(A[i], A[min_pos]);

            count++;
        }
    }

    return;
}

// 安定なソートかの判定
void check_stable( Card C1[], Card C2[], int n )
{
	bool ret = true;

	for(int i = 0; i < n; i++)
    {
        if( C1[i].suit != C2[i].suit )
        {
            ret = false;
        }
    }

	if(ret == true)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	return;
}

// 結果表示用
void print_method(Card A[], int n)
{

    for(int i = 0; i < n; i++)
    {
       if( i )
       {
           cout << ' ';
       }

       cout << A[i].suit << A[i].value;

    }

    cout << endl;

}

int main(void)
{
    int N;
    Card C1[100], C2[100];

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i = 0; i < N; i++)
    {
        C2[i] = C1[i];
    }

    bubbleSort(C1, N);
    // 結果を表示する
    print_method(C1, N);
    cout << "Stable" << endl;

    selectionSort(C2, N);
    print_method(C2, N);
    check_stable(C1, C2, N);

    return 0;
}



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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 100;
int a[N];
int n;

int main() {
  int i, j, k;
  scanf("%d ", &n);
  for (i=0; i<n; i++)
    scanf("%d ", a+i);

  for (i=0; i<n; i++)
    printf("%d%c", a[i], (i == n-1) ? '\n' : ' ');

  for (i=1; i<n; i++) {
    int key = a[i]; 
    j = i - 1;
    while (j>=0 && a[j]>key) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = key;

    for (k=0; k<n; k++)
      printf("%d%c", a[k], (k == n-1) ? '\n' : ' ');
  }

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main()
{
   int count=0;
   string S;
   cin>>S;
   if((S.find("R")==2)||(S.find("R")==0)||(S.find("R")==1)){
       count++;
   }
   for(int i=S.find("R");i<2;i++){
       
       if(S[i]==S[i+1])
       {
           count++;
       }
       else{
           break;
       }
   }
   cout<<count<<endl;
   
   return 0;
}

Measured memory_bytes: 3604
N = int(input())
S, T = [], []
for _ in range(N):
    s, t = input().split()
    S.append(s)
    T.append(int(t))
X = input()
ans = sum(T)
partial_sum = 0
for s, t in zip(S, T):
    partial_sum += t
    if s == X:
        break
print(ans - partial_sum)


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

int main(){
  string S;
  cin >> S;
  long long N = S.size();
  
  vector<int> sa = suffix_array(S);
  vector<int> la = lcp_array(S,sa);
  
  long long ans = N*(N+1)/2;
  for(int i=0;i<N-1;i++) ans -= la[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15640