akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
using namespace std;

void show(int arr[], int N){
	for(int i=0; i<N; i++)
		if(i<N-1)
			cout<<arr[i]<<' '<<flush;
		else
			cout<<arr[i]<<flush;
	cout<<endl;
}

int ShellSort(int*, int);
int InsertionSort_r(int*, int, int);

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

	int* arr=new int[N];

	for( int i=0; i<N; i++)
		cin>>arr[i];
	
	int cnt=ShellSort(arr, N);

	cout<<cnt<<endl;

	for( int i=0; i<N; i++)
		cout<<arr[i]<<endl;

	delete[] arr;
}


int ShellSort(int arr[], int N)
{
	vector<int> range;

	for( int g=1; g <= N;){
		range.push_back(g);
		g=g*3+1;
	}

	cout<<range.size()<<endl;
	for( int i=range.size() -1; i>=0; i--) 
		cout<<range[i]<<' '<<flush;
	cout<<endl;


	int count;
	for( int i=range.size() -1; i>=0; i-- )
		count=InsertionSort_r(arr, N, range[i]);

	return count;
}


int InsertionSort_r(int arr[], int N, int r)
{
	static int cnt=0;
	bool changed=false;
	for( int compindex=r; compindex<N; compindex++) {

		int comp= arr[compindex];

		int j=compindex - r;

		for( ; j>=0; j-=r ) {
			if(arr[j] > comp){
				arr[ j+r ]=arr[j];
				cnt++;
				changed=true;
			}
			else
				break;
		}

		arr[ j+r ] =comp;


		changed=false;
	}
	return cnt;
}
				




	
	


	

Measured memory_bytes: 4900
import sys

def enum_div(n):
    ir=int(n**(0.5))+1
    ret=[]
    for i in range(1,ir):
        if n%i == 0:
            ret.append(i)
            if (i!= 1) & (i*i != n):
                ret.append(n//i)
    return ret

from collections import deque    
#    q = deque(l)
#    q.append(4) # 後ろから4を挿入, l=deque([0,1,2,3,4])
#    q.appendleft(5)#前から5を挿入, l=deque([5,0,1,2,3,4])
#    x = q.pop() #後ろの要素を取り出す, x=4, l=deque([5,0,1,2,3])
#    y = q.popleft() # 前の要素を取り出す, y=5, l = deque([0,1,2,3])

def get_primenumber(number):#エラトステネスの篩
    prime_list = []
#    search_list = deque(list(range(2,number+1)))
    search_list = list(range(2,number+1))
    #search_listの先頭の値が√nの値を超えたら終了
#    while search_list[0] <= math.sqrt(number):
    while search_list[0]**2 <= number:
      #search_listの先頭の値が√nの値を超えたら終了
      #search_listの先頭をprime_listに入れて、先頭をリストに追加して削除
#        head_num = search_list.popleft()
        head_num = search_list.pop(0)
        prime_list.append(head_num)
        #head_numの倍数を除去
#        search_list =deque( [num for num in search_list if num % head_num != 0])
        search_list =[num for num in search_list if num % head_num != 0]
    #prime_listにsearch_listを結合
    prime_list.extend(search_list)
    return prime_list

n=int(input())
ap=list(map(int,input().split()))
amin=min(ap)
amax=max(ap)

if amax==1:
    print("pairwise coprime")
    sys.exit()

if amin!=1:
    bp=enum_div(amin)+[amin]
    bp.sort()
    bp=bp[1:]
    for bpi in bp:
        yn=""
        for ai in ap:
            if ai%bpi!=0:
                yn="coprime"
                break
        if yn=="":
            print("not coprime")
            sys.exit()

if n>=78500 :
    print("setwise coprime")
    sys.exit()

aa=[0]*(amax+1)
for ai in ap:
    aa[ai]+=1

#p=get_primenumber(amax)

#for pp in p:
for pp in range(2,amax+1):
    psum=sum(aa[pp: :pp])
#    print("pp:",pp,psum)
    if psum>=2:
            print("setwise coprime")
            sys.exit()
## max_13.txt ... max_16.txt : "setwise coprime"
print("pairwise coprime")
   


Measured memory_bytes: 183912
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();
    let b = 10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10*10;
    let mut f = false;

    let mut ans: u64 = 1;
    for ai in &a {
        if *ai == 0 {
            f = false;
            ans = 0;
            break
        }
        if ans > b / *ai || f {
            f = true;
        } else {
            ans *= *ai;
        }
        
    }

    if f {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 2792
package main

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

func main() {
	var n, m int
	fmt.Scan(&n)
	fmt.Scan(&m)

	p := make(map[int]map[int]int)
	for i := 1; i <= n; i++ {
		p[i] = make(map[int]int)
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= m; i++ {
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		y, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		z, _ := strconv.Atoi(scanner.Text())
		p[x][y] = z
		p[y][x] = z

	}

	searched := make(map[int]bool)
	var search func(pos int)
	search = func(pos int) {
		if searched[pos] {
			return
		}
		searched[pos] = true

		for k := range p[pos] {
			search(k)
		}
	}

	var ret int
	for i := 1; i <= n; i++ {
		if !searched[i] {
			ret++
			search(i)
		}
	}

	fmt.Println(ret)
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, y, lmn, lmx;
    cin >> x >> y;
    if (y % 2 != 0)
    {
        cout << "No" << endl;
    }
    else
    {
        lmx = y / 2;
        lmn = y / 4;
        lmn += (y - lmn * 4) / 2;
        if (lmn <= x and x <= lmx)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

// 2+2+2+2+2 +4=14, 6, 7, 4

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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
#define case(i) "Case #" << i << ": "

template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
    out << '(' << p.first << ", " << p.second << ')';
    return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++) out << v[i] << ' ';
    if (l > 0) out << v[l - 1];
    return out;
}

double rtd(double x) {
    return x * 180 / M_PI;
}

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

    double a, b, x;
    cin >> a >> b >> x;

    x /= a;
    double area = a * b;

    double h = x / a;

    cout << fixed << setprecision(10);
    
    if(area >= 2 * x) {
        double theta = atan((2 * a * h)/(b * b));
        cout << 90 - rtd(theta) << endl;
    }
    else {
        double theta = atan(a / (2.f * (b - h)));
        cout << 90 - rtd(theta) << endl;
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = int(1e9) + 7;

LL n;
int p3[61];

map<pair<LL, int>, int> save;

int solve(LL n, int pos) {
    pair<LL, int> p = mp(n, pos);
    auto it = save.find(p);
    if (it != save.end()) {
        return it->second;
    }
    if (pos == 0) {
        return save[p] = n + 1;
    }
    LL sum = 0;
    forn(i, pos) {
        sum += 2ll << i;
    }
    int ans = 0;
    for (int i = 0; i <= 2; ++i) {
        LL nn = n - ((LL)i << pos);
        if (nn >= sum) {
            ans += p3[pos];
            if (ans >= MOD) {
                ans -= MOD;
            }
        } else if (nn >= 0) {
            ans += solve(nn, pos - 1);
            if (ans >= MOD) {
                ans -= MOD;
            }
        }
    }
    return save[p] = ans;
}

int main() {
    //freopen("input.txt", "r", stdin);
    p3[0] = 1;
    for (int i = 1; i <= 60; ++i) {
        p3[i] = 3ll * p3[i - 1] % MOD;
    }
    cin >> n;
    cout << solve(n, 60) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	string s;
	cin >> s;
	cout << (s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good") << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int W,a,b;cin>>W>>a>>b;
  int ans;
  if(b-a-W>0)ans=b-a-W;
  else if(a-b-W>0)ans=a-b-W;
  else ans=0;
  cout<<ans<<endl;
}

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

#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define pb2 pop_back
#define pf2 pop_front
#define line printf("\n")
#define pq priority_queue
#define rep(k,i,j) for(int k = (int)i;k<(int)j;k++)
#define repd(k,i,j) for(int k = (int)i;k>=(int)j;k--)
#define ll long long

using namespace std;

double EPS = 1e-9;
int INF = 1e9+7;;
long long INFLL = 1e17;
double pi = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

inline void OPEN (string s) {
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
}

//end of template

int a[] = {1,3,5,7,8,10,12};
int b[] = {4,6,9,11};
int c[] = {2};

int id[100];
int main(){
	rep(k,0,7)id[a[k]] = 0;
	rep(k,0,4)id[b[k]] = 1;
	rep(k,0,1)id[c[k]] = 2;
	int x,y;
	scanf("%d%d",&x,&y);
	
	printf("%s\n",(id[x]==id[y])?"Yes":"No");
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN   
#define linf LLONG_MAX
#define lninf LLONG_MIN   
const ll mod=1e9+7;
const int N=2504;

int main()
{
	int n,avg; scn(n); scn(avg);

	int a[n]; rep(i,0,n)scn(a[i]);

	//dp[ind][sum][cnt]
	ll dp[n+1][N][n+1]; memset(dp,0,sizeof(dp));

	dp[0][0][0] = 1;

	rep(ind,0,n)
	{
		rep(sum,0,N)
		{
			rep(cnt,0,ind+1)
			{
				dp[ind+1][sum][cnt] += dp[ind][sum][cnt];

				if(sum+a[ind] < N)
				dp[ind+1][sum+a[ind]][cnt+1] += dp[ind][sum][cnt];
			}
		}
	}

	ll ans=0;

	rep(sum,1,N)
	{
		rep(cnt,1,n+1)
		if(sum%cnt==0 and sum/cnt == avg)
		ans += dp[n][sum][cnt];
	}

	lpri(ans);

	return 0;
}


Measured memory_bytes: 54604
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;

int N;
vector<ll> x;
ll X;
int main(){
    cin>>N>>X;
    x.resize(N);
    rep(i,N) cin>>x[i];
    reverse(all(x));
    vector<ll> acc(N+1);
    rep(i,N) acc[i+1] = acc[i] + x[i];

    ll ans = 1e18;

    rep1(t,N){
        ll sm = X*t;
        for(int k=0;;k++){
            int l = k*t;
            int r = min(N,l+t);
            ll c = (k==0 ? 5 : k*2+3);
            sm += c*(acc[r]-acc[l]);
            if(sm>ans) break;
            if(r==N) break;
        }
        chmin(ans,sm);
    }
    cout<<ans+X*N<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = (int)1e9 + 7;

int pwr(int a, int b){
  if(b == 0)
    return 1;
  int x = pwr(a,b/2);
  x = (x * 1ll * x) % MOD;
  if(b & 1) x = (x * 1ll * a) % MOD;
  return x;
}

const int N = (int)2e5 + 100;
int fac[N];

int nck(int n, int k){  
  if(n < k) return 0;
  int ans = fac[n];
  ans = (ans * 1ll * pwr(fac[k], MOD - 2)) % MOD;
  ans = (ans * 1ll * pwr(fac[n - k], MOD - 2)) % MOD;
  return ans;
}

int aa[N];
int bb[N];

int main(){
  fastIO;
  fac[0]=1;
  for(int i = 1; i < N ; i ++ )
    fac[i]=(fac[i-1]*1ll*i)%MOD;
  int b, w;
  cin >> b >> w;
  int ds;
  int ans;
  for(int i = 0 ; i < b + w; i ++ ){
    if(i < b){
      aa[i]=0;
    }
    else{
      aa[i]=aa[i-1];
      ds=nck(i - 1, b - 1);
      ds = (ds * 1ll * pwr(pwr(2,i),MOD-2)) % MOD;
      aa[i]=(aa[i]+ds) % MOD;
    }
    if(i < w){
      bb[i]=0;
    }
    else{
      bb[i]=bb[i-1];
      ds=nck(i-1,w-1);
      ds=(ds*1ll*pwr(pwr(2,i),MOD-2))%MOD;
      bb[i]=(bb[i]+ds)%MOD;
    }
    ans=(1-aa[i]+bb[i]+MOD)%MOD;
    ans=(ans*1ll*pwr(2,MOD-2))%MOD;
    cout << ans << "\n";
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
ll knapsack(ll a[],ll b[],ll n,ll w){
    ll i,j;
    ll k[n+1][w+1];
    for(ll i=0;i<=n;i++){
        for(j=0;j<=w;j++){
            if(i==0||j==0)
            k[i][j]=0;
            else if(b[i-1]<=j)
                k[i][j]=max(a[i-1]+k[i-1][j-b[i-1]],k[i-1][j]);
            else
            k[i][j]=k[i-1][j];
        }
    }
    return k[n][w];
}

int main(){
    ll n,w;
    cin>>n>>w;
    ll a[n],b[n];
    for(ll i=0;i<n;i++)
        cin>>b[i]>>a[i];
    cout<<knapsack(a,b,n,w);
    return 0;
}


Measured memory_bytes: 79104
import java.util.Arrays;
import java.util.Scanner;
 
class Main {
	int n;
	int l;
	String[] s;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		l = sc.nextInt();
		s = new String[n];
		for(int i=0;i<n;i++){
			s[i] = sc.next();
		}
	}
	void solve(){
		Arrays.sort(s);
		for(int i=0;i<n;i++){
			System.out.print(s[i]);
		}
	}
}

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

int main() {
    std::string S;
    std::cin >> S;

    const int f = std::stoi(S.substr(0, 2));
    const int s = std::stoi(S.substr(2, 4));


    if (f >= 1 && f <= 12) {
        if (s >= 1 && s <= 12) {
            std::cout << "AMBIGUOUS\n";
        } else {
            std::cout << "MMYY\n";
        }
    } else if (s >= 1 && s <= 12) {
        std::cout << "YYMM\n";
    } else {
        std::cout << "NA\n";
    }

    return 0;
}


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

int main()
{
  
  
  long N,ans = 0;
  
  scanf("%ld",&N);
  
  
  for(long i = sqrt(N); i > 0; --i)
  {
    if(N % i == 0)
    {
      ans = N / i + i -2;
      break;
    }
  }
  
  printf("%ld",ans);
}

Measured memory_bytes: 128
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 2e5 + 20 ;
int n , X , x[N] , d[N] ;
ll part[N] ;

inline ll get (int k) {
	ll ans = 1ll * n * X + 1ll * k * X ;

	for (int i = 1 , p = n ; p > 0 ; i ++ , p -= k)
		ans += (part[p] - part[max(0 , p - k)]) * d[i] , ans = min((ll)1e18 , ans) ; 
	
	return ans ;
}

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

	cin >> n >> X ;

	for (int i = 0 ; i < n ; i ++) cin >> x[i] ;

	sort(x , x + n) ;

	for (int i = 0 ; i < n ; i ++) part[i + 1] = part[i] + x[i] ;

	d[1] = 5 ;
	for (int i = 2 ; i <= n ; i ++) d[i] = 2 * i + 1 ;

	ll ans = get(1) ;
	for (int i = 2 ; i <= n ; i ++) ans = min(ans , get(i)) ; 

	cout << ans << '\n' ;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=(a+b)*(c/2);
		System.out.println(d);

	}
}


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

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

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

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

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

void solve(void)
{
  int N; cin >> N;
  vector<int> P(N);
  for(auto& p : P) cin >> p;

  int m = P[0];
  int ans{1};
  for (int i = 1; i < N; ++i) {
    if (m >= P[i]) {
      ++ans;
    }
    chmin(m, P[i]);
  }

  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <vector>

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

using namespace std;

int main(void) {
	int n, x, m, min=INT_MAX;
	int i;
	scanf("%d %d", &n, &x);
	REP(i, n) {
		scanf("%d", &m);
		if(x<m)break;
		x-=m;
		if (min > m) min=m;
	}
	printf("%d\n", i+(x/min));
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8

using namespace std;

ll f(ll a)
{
	if(!a)
		return 0;
	ll ret=0;
	if((a&3)==1||(a&3)==2)
		ret=1;
	for(ll i=2;i<=a;i<<=1)
	{
		ll tmp=a&((i<<1)-1);
		tmp-=i-1;
		if(tmp>0&&(tmp&1))
			ret|=i;
	}
	return ret;
}

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	ll a,b;
	cin>>a>>b;
	a=max(a-1,0ll);
	cout<<(f(b)^f(a))<<'\n';
	return 0;
} 

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

int main() {
  long n,a,b,anstyoka=0,ansika=1000000000;
  cin >> n >> a >> b;
  vector<long> h(n);
  for(long i=0;i<n;i++) cin >> h[i];
  
  while(anstyoka+1!=ansika) {
    long test=anstyoka+(1+ansika-anstyoka)/2;
    long sum=0;
    for(long i=0;i<n;i++) if(b*test<h[i]) sum+=(h[i]-b*test+(a-b-1))/(a-b);
    if(sum>test) anstyoka=test;
    else ansika=test;
  }
  cout << ansika << endl;
}

Measured memory_bytes: 4012
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val d = readLine()?.split(" ")?.map(String::toInt) ?: return
    var total = 0L
    0.until(n - 1).forEach { i ->
        i.until(n).forEach { j ->
            if (i != j) {
                total += d[i] * d[j]
            }
        }
    }
    println(total.toString())
}

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

int main()
{
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    vector<vector<char>>a(h + 1,vector<char>(w + 1));
    rep(i,h){
        rep(j,w){
            cin >> a[i + 1][j + 1];
        } 
    }
    rep(H,1<<h){
        rep(W,1<<w){
            int black = 0;
            vector<vector<char>>b(h + 1,vector<char>(w + 1));
            rep(i,h){
                rep(j,w) b[i + 1][j + 1] = a[i + 1][j + 1]; 
            }
            rep(i,h){
                if(H>>i&1){ 
                    rep(l,w) b[i + 1][l + 1] = 'r';
                }
                rep(j,w){
                    if(W>>j&1){
                        rep(m,h) b[m + 1][j + 1] = 'r';
                    }
                }
            }
            rep(i,h){
                rep(j,w) if(b[i + 1][j + 1] == '#') black++;
            }
            if(black == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
ll dp[2005][2005][2];

ll mod_pow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}


int main(void){
	scanf("%d%d",&n,&k);
	dp[n][0][0]=1;
	for(int i=n;i>=1;i--){
		for(int j=n;j>=0;j--){
			dp[i-1][j][0]+=(dp[i][j][0]+dp[i][j][1])%MOD;
			dp[i-1][j][0]%=MOD;
			dp[i-1][j+1][1]+=(dp[i][j][0]+dp[i][j][1])%MOD;
			dp[i-1][j+1][1]%=MOD;
			if(j>0){
				dp[i][j-1][0]+=dp[i][j][0];
				dp[i][j-1][0]%=MOD;
			}
		}
	}
	ll res=(dp[1][n-k][0]+dp[1][n-k][1])%MOD;
	res=res*mod_pow(2,n-k-1)%MOD;
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 62976
// B. 

#include <iostream>
#include <sstream>

using namespace std;
typedef long long LL;
typedef pair<LL, LL> LLLL;

int main(int argc, char *argv[])
{
	int N, P[20000], A[20000], B[20000];
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> P[i];
	}
	for (int i = 0; i < N; ++i) {
		A[i] = (i + 1) * 30000;
		B[i] = (N - i) * 30000;
	}
	for (int i = 0; i < N; ++i) {
		A[P[i] - 1] += i;
	}
	string delim = "";
	for (int i = 0; i < N; ++i) {
		cout << delim << A[i];
		delim = " ";
	}
	cout << endl;
	delim = "";
	for (int i = 0; i < N; ++i) {
		cout << delim << B[i];
		delim = " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;
public class Main
{
	static int W,H;
	static int map[][];
	static int C,xg,yg,judge;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			W=in.nextInt();
			H=in.nextInt();
			if((W|H)==0)
				return;
			map=new int[H+1][W+1];
			int xs=in.nextInt(),ys=in.nextInt();
			xg=in.nextInt();yg=in.nextInt();
			int n=in.nextInt();
			for(int i=0;i<n;i++)
			{
				int c=in.nextInt(),d=in.nextInt();
				int x=in.nextInt(),y=in.nextInt();
				if(d==0)
				{
					for(int h=y;h<y+2;h++)
						for(int w=x;w<x+4;w++)
							map[h][w]=c;
				}
				else
				{
					for(int h=y;h<y+4;h++)
						for(int w=x;w<x+2;w++)
							map[h][w]=c;
				}
			}
			C=map[ys][xs];
			judge=0;
			if(solve(ys,xs)==1)
				System.out.println("OK");
			else
				System.out.println("NG");
		}
	}

	public static int solve(int h, int w)
	{
		if(h==yg&&w==xg)
		{
			judge=1;
			return judge;
		}
		map[h][w]=6;
		if(h-1>=1&&map[h-1][w]==C)
			solve(h-1,w);
		if(w-1>=1&&map[h][w-1]==C)
			solve(h,w-1);
		if(h+1<=H&&map[h+1][w]==C)
			solve(h+1,w);
		if(w+1<=W&&map[h][w+1]==C)
			solve(h,w+1);
		return judge;
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include<math.h>
int main(void){
	int n,i,j,sosu=0,not_sosu=0;
	int N[10000];
	
	//最初の行読み込み
	scanf("%d",&n);
	
	//続くn個の読み込み
	for(i=1; i<=n; i++){
		scanf("%d",&N[i]);
	}
	//素数判定
	
	for(i=1; i<=n; i++){
		for(j=2; j<=(int)(sqrt(N[i])); j++){
			not_sosu = 0;
			if(N[i]%j==0){	
				not_sosu=1;
				break;
			}
		}
		if(not_sosu==0)	sosu++;
	}
		
	printf("%d\n", sosu);
	return 0;

}


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

int main()
{
  ll n,r;
  cin >> n >> r;
  if ( n < 10 )
  {
    cout << r + 100 * ( 10 - n ) << endl;
  } else {
    cout << r << endl;
  }
  return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    cnt += s.substr(i, 3) == "ABC";
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    if value>=2:
        ans+=combinations(value,2)
print(ans)

Measured memory_bytes: 19760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)

//変数
ll N;
vector<ll> vec;

//解法
void solve() {

	ll ans = 0;
	rep(i, N) {

		while (1) {
			if (vec[i] % 2 == 0) {
				vec[i] /= 2;
				ans++;
			}
			else {
				break;
			}
		}

	}

	cout << ans;

	return;
}

int main() {
	//入力
	cin >> N;
	vec.resize(N);
	rep(i, N) cin >> vec[i];
	solve();
	cout << endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int x = a[0] + k - a[n-1];
    for (int i = 1; i < n; ++i) {
        chmax(x, a[i] - a[i-1]);
    }
    cout << k - x << endl;
}

Measured memory_bytes: 4048
import bisect
X,N = map(int, input().split())


if N == 0:
    print(X)
    exit()


p = list(map(int,input().split()))

p.sort()
gen = list(range(-5,120))

for i in p:
    gen.remove(i)

index = bisect.bisect(gen,X)

ans = 100000
ans2 = 100000

a = [gen[index-1],gen[index],gen[index+1]]

for i in range(3):
    check = abs(a[i]-X)
    if ans > check:
        ans = check
        ans2 = a[i]
    
print(ans2)

        
    
    

Measured memory_bytes: 61948
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7



S = str(input())
used = []
for i in range(len(S)):
    if S[i] in used:
        print("no")
        exit()
    else:
        used.append(S[i])
print("yes")


Measured memory_bytes: 6600
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e5+100;
vector <pii> g[N];
ll n;
ll t[N];
ll ans=0;
vector <int> cen;
ll dfs(ll v,ll p){
    ll p1=0;
    t[v]=1;
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i].F;
        ll w=g[v][i].S;

        if (u!=p){
            dfs(u,v);
            t[v]+=t[u];
            ans+=min(t[u],n-t[u])*w*2;
            if (t[u]>n/2){
                p1=1;
            }
        }

    }
    if (n-t[v]>n/2){
        p1=1;
    }
    if (!p1){
        cen.pb(v);
    }
}
int32_t main(){
    sync;
    /// avalin code ke centroid zadam :)
    cin >> n;
    for (int i=0;i<n-1;i++){
        ll u,v,c;
        cin >> u >> v >> c;
        g[u].pb({v,c});
        g[v].pb({u,c});
    }
    dfs(1,1);
    if (cen.size()==2){
        ll v=cen[0],u=cen[1];
        for (int i=0;i<g[v].size();i++){
            ll z=g[v][i].F;
            if (z==u){
                ans-=g[v][i].S;
            }
        }
    }
    else{
        ll mi=1e9+100;
        ll v=cen[0];
        for (int i=0;i<g[v].size();i++){
            ll u=g[v][i].S;
            mi=min(mi,u);
        }
        ans-=mi;
    }
    cout << ans;
}


Measured memory_bytes: 18048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++)	cin>>a[i];
	int mount[n];
	ll low =0, high =a[0];
	while(low<=high){
		memset(mount,-1,sizeof(mount));
		ll mid = (low+high)/2;
		ll left = mid,right;
		mount[0] = left;
		mount[1] = a[0]-left;
		int flag=0;
		for(int i=1;i<n;i++){
			left = mount[i];
			right = a[i]-left;
			ll y = i+1;
			y=y%n; 
			if(y!=0)	mount[y] = right;
			if(y==0){
			if(mount[0]==right){
				flag=1;
				break;	
			}
		}
		}
		if(flag==1)	break;
		if(mount[0]<right)	low = mid+1;
		else high =mid-1;
	}
	for(int i=0;i<n;i++)	cout<<2*mount[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long lli;

main(){
  lli n, h[501];
  cin >> n;
  h[0] = 0;
  for(int i=1;i<=n;i++) cin >> h[i];
  sort(h, h+n);
  lli ans = 0, pre = 0;
  for(int i=1;i<=n;i++){
    if(h[i] == h[i-1]) continue;
    lli rem = n - i + 1;
    lli id = min(rem / 4, h[i]);
    lli a = rem * (h[i] - h[i-1]);
    lli b = max(0LL, rem * id - rem * pre) - max(0LL, (id * (id + 1) * 2 - pre * (pre + 1) * 2));
    /*cout << rem * id << ' ' << rem * pre << ' ' << id*(id+1)*2 << ' ' << pre*(pre+1)*2 << endl;
    cout << rem << ' ' << id << ' ' << a << ' ' << b << endl;
    cout << endl;*/
    //if(h[i] >= 125) b = 0;
    ans += a - b; 
    pre = id;
  }
  cout << ans + 1 << endl;
}

Measured memory_bytes: 1176
K, N = map(int, input().split())
A = []
A = list(map(int, input().split()))
#print(A)
dis = [0 for _ in range(N)]
dis[0] = A[N-1]-A[0]
for i in range(1,N):
    dis[i] = K - A[i] + A[i-1]

print(min(dis))


Measured memory_bytes: 87500
import java.util.*;

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

        int n = sc.nextInt();
        int[] A = new int[n];

        for(int i = 0;i < n;i++){
            A[i] = sc.nextInt();
        }

        int flag = 1,count = 0,tmp;
        while(flag == 1){
            flag = 0;
            for(int i = n - 1;i > 0;i--){
                if(A[i - 1] > A[i]){
                    tmp = A[i - 1];
                    A[i - 1] = A[i];
                    A[i] = tmp;
                    count++;
                    flag = 1;
                }
            }
        }

        for(int i = 0;i < n;i++){
            if(i != 0)  System.out.print(" ");
            System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(count);
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0
#define all(v) begin(v),end(v)
#define inf 1LL<<55



signed main(){

	string str;
	cin>>str;

	lli ansX,ansY;
	cin>>ansX>>ansY;

	/*F向いてる方向に進む*/
	/*T向きを90度変える*/

	/*FのところでX軸方向に進むか、y軸方向に進むかは変えられる*/

	lli fcnt=0;
	vector<lli> xCnt;
	vector<lli> yCnt;
	lli now = 0;
	lli flag=0;

	REP(i,str.size()){
		if(str.at(i)=='F'){
			if(i==0)flag=1;
			now++;
		}
		else{
			if(now==0){}
			else if(fcnt%2==0)xCnt.push_back(now);
			else yCnt.push_back(now);
			now=0;
			fcnt++;
		}
	}
	if(now!=0){
		if(fcnt%2==0)xCnt.push_back(now);
		else yCnt.push_back(now);
	}


	/*できる数列の和と差引でその数字が作れるか？*/

	set<lli> x,y;
	x.insert(0);
	y.insert(0);
	if(DEBUG){
		REP(i,xCnt.size()){
			cout<<"i="<<i<<" xCnt="<<xCnt[i]<<endl;
		}

		REP(i,yCnt.size()){
			cout<<"i="<<i<<" yCnt="<<yCnt[i]<<endl;
		}
	}
	REP(i,xCnt.size()){
		vector<lli> pushX;
		set<lli> nextX;
		for(auto e:x){
			if(DEBUG)cout<<"i="<<i<<"e="<<e<<"xCnt="<<xCnt[i]<<endl;
			nextX.insert(e+xCnt[i]);
			if(flag==1 && i==0)continue;
			nextX.insert(e-xCnt[i]);
		}
		x = nextX;
	}
	REP(i,yCnt.size()){
		vector<lli> pushY;
		set<lli> nextY;
		for(auto e:y){
			if(DEBUG)cout<<"i="<<i<<"e="<<e<<endl;
			nextY.insert(e+yCnt[i]);
			nextY.insert(e-yCnt[i]);
		}
		y = nextY;
	}

	if(x.find(ansX)!=x.end() && y.find(ansY) != y.end()){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
	char s[100];
	int count=0;
	scanf("%s",s);
	
	for(int i=0;i<3;i++){
		
		if(s[i]=='1'){
			
			count++;
		
		}
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

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

  if(A > B) train = B;
  else train = A;

  if(C > D) bus = D;
  else bus = C;

  cout << bus + train << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int l = scan.nextInt();
        String[] s = new String[n];
        for(int i = 0; i < n; i++){
            s[i] = scan.next();
        }
        Arrays.sort(s);
        for(int i = 0; i < n; i++){
            System.out.print(s[i]);
        }
    }
}


Measured memory_bytes: 23252
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int d=max(a,b);
  if(c%d==0)
  cout<<c/d<<endl;
  else
    cout<<c/d+1<<endl;
}

Measured memory_bytes: 256
mod = 10**9+7
n, m = map(int, input().split())
if abs(n-m) >= 2:
    print(0)
    exit()
x, y = 1, 1
for i in range(1, n+1):
    x *= i
    x %= mod
for i in range(1, m+1):
    y *= i
    y %= mod
if n == m:
    print((2*x*y)%mod)
else:
    print((x*y)%mod)

Measured memory_bytes: 9196
n = gets.to_i
ps = gets.split.map(&:to_i)
qs = gets.split.map(&:to_i)

sorted = ps.permutation(n).to_a.sort
p_num = 0
q_num = 0

sorted.each_with_index do |s, i|
  if s == ps
    p_num = i
    break
  end
end

sorted.each_with_index do |s, i|
  if s == qs
    q_num = i
    break
  end
end

puts (p_num - q_num).abs


Measured memory_bytes: 7416
#include<iostream>
#include<algorithm>
using namespace std;
int n,a,ans=1e9,cnt;
main()
{
	cin>>n;
	for(;n--;)
	{
		cin>>a;
		cnt=0;
		while(a%2==0)cnt++,a/=2;
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
}


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

long long e, x, y, z, m;

int main (){
	x = 0;
	while (cin >> e && e > 0){
		m = 1000;
		for (z = 0; z * z * z <= e; z++){
			for (y = 0; y * y + z * z * z <= e; y++){
			       	x = e - y * y - z * z * z;
				m = min (m, x + y + z);
			}
		}
		cout << m << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
package main

import (
        "fmt"
)

func solution(n, k int, a []int) int {
        visit := make([]int, 0)
        hop := make([]int, n+1)
        for i := range hop {
                hop[i] = -1
        }

        cur := 1
        c := 1
        l := 0
        for hop[cur] == -1 {
                hop[cur] = len(visit)
                visit = append(visit, cur)
                cur = a[cur-1]
        }

        c = len(visit) - hop[cur]
        l = hop[cur]
        ans := 0
        if k < l {
                ans = visit[k]
        } else {
                k -= l
                k %= c
                ans = visit[l+k]
        }
        return ans
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                tmp := 0
                fmt.Scan(&tmp)
                a = append(a, tmp)
        }
        fmt.Println(solution(n, k, a))
}

Measured memory_bytes: 12784
#include <cstring>
#include <iostream>
#include <regex>
using namespace std;

int main() {
    std::string S;
    bool i;

    cin >> S;

    i = std::regex_match(S, std::regex("(hi)+"));
    if (i) {
        cout << "Yes";
    } else {
        cout << "No";
    }

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import os
import sys

class Main(object):

    def __init__(self):
        pass

    def some_method(self):
        n = int(input())
        ts = list(map(int, input().split()))
        s = sum(ts)
        m = int(input())
        for i in range(m):
            p, x = map(int, input().split())
            print(s + (x - ts[p-1]))
        
        return None

if __name__ == '__main__':
    m = Main()
    m.some_method()


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
int main(void)
{
	int room=0;
	int cur=0;
	scanf("%d %d",&room,&cur);
	if(cur*2>=room)
	{
		printf("0");
	} 
	else
	{
		printf("%d",room-2*cur);
	}
	return 0;
} 


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

int main()
{
  // input_from_file;
  ll n,k,sum=0;;
  cin>>n>>k;
  vector<ll> wt(n+1,0),cost(n+1,0),dp(k+1,0);ll ans=0;
  for(ll i=1;i<=n;i++)  {cin>>wt[i]>>cost[i];sum+=cost[i];}
  for(ll i=1;i<=n;i++){
    for(ll j=k;j>=1;j--){
      if(wt[i]>j)   continue;
      dp[j]=max(dp[j],dp[j-wt[i]]+cost[i]);
      ans=max(ans,dp[j]);
    }
  }
  // for(ll i=0;i<=k;i++) cout<<dp[i]<<" ";cout<<endl;
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1024
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N = int(input())
    S = list(input())
    left_index = [[-1] * (N + 1) for _ in range(10)]
    for i, x in enumerate(S, 1):
        for j in range(10):
            left_index[j][i] = left_index[j][i - 1]
        left_index[ord(x) - ord("0")][i] = i
    answer = 0
    for i in range(1000):
        a = i // 100
        b = (i % 100) // 10
        c = i % 10
        j = N
        bl = True
        for x in [c, b, a]:
            j = left_index[x][j] - 1
            if j < -1:
                bl = False
                break
        if bl:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6640
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {

	string S;
	cin >> S;
	ll ans = 0;
	rep(i, 6) ans += S[i] - '0';
	cout << ans;
	

	system("PAUSE");
}


Measured memory_bytes: 504
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)
	fmt.Println(A[len(A)-1] - A[0])
}

Measured memory_bytes: 512
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(solve(s[0], s[1], a));
    }
    static int solve(int n, int k, int[] a) {
        int[] list = new int[n];
        for (int i = 0; i < n; i ++) list[a[i]-1] ++;
        Array.Sort(list);
        int count = list.Where((x,y) => y < n-k).Sum();
        return count;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int ddx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1};

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

int extgcd(int a, int b, int& x, int&y) {
    int d = a;
    if(b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }else {
        x = 1;
        y = 0;
    }
    return d;
}

int inv(int a) {
    int x, y;
    extgcd(a, MOD, x, y);
    return (x + MOD) % MOD;
}

struct UniTree {
    int *par, *rank, *sz;

    UniTree(int n) {
        par = new int[n];
        rank = new int[n];
        sz = new int[n];
        for(int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }

    int root(int x) {
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        }else {
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            sz[x] += sz[y];
        }
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int siz(int x) {
        return sz[root(x)];
    }
};

double bin(double left, double right) {
    return 0;
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    char before = '#';
    rep(i, n) {
        if(s[i] != before) {
            ans++;
            before = s[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>

#define all(c) (c).begin(),(c).end()

using namespace std;

int count(int bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits =(((bits >> 4) + bits) & 0x0f0f0f0f);
  bits += bits >> 8;
  return (bits + (bits >> 16)) & 0xff;
}

int dp[(1<<10)][1002];

int main(void){

  dp[0][0]=1;
  for(int S=0;S<(1<<10);S++){
    for(int i=0;i<10;i++){
      if(!(S>>i&1)){
        for(int s=0;s<1000;s++){
          if((count(S)+1)*i+s<1000)
          dp[S|(1<<i)][(count(S)+1)*i+s]+=dp[S][s];
        }
      }
    }
  }

  int n,s;

  while(cin >> n >> s){

    if(s>=1000){
      cout << 0 << endl;
      continue;
    }

    int ans=0;
    for(int i=0;i<(1<<10);i++)
      if(count(i)==n)ans+=dp[i][s];

    cout << ans << endl;
  }


  return 0;
}

Measured memory_bytes: 5168
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int n;
    cin >> n;
    set<string>c;
    string s="";
    rep(i, 0, n) {
        string in;
        cin >> in;
        if(c.count(in) || (s!="" && s.back()!=in[0])){
            cout << "No" << endl;
            return 0;
        }
        c.insert(in);
        s=in;
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001

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

    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    int v;
    int x = 0, y = 0, z = 0;
    vector <int> vec, gr;
    for (int i = 0; i < n; i++) {
        cin >> v;
        if (v >= b + 1) {
            z++;
        }
        else if (v <= a) {
            x++;
        }
        else {
            y++;
        }
    }
    int ans = min(min(x, y), z);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    double a, b, c, h, deg, rad, area, pi;
    cin >> a >> b >> deg;
    
    pi = acos(-1);
    rad = deg * pi / 180;
    area =  0.5*a*b*sin(rad);
    c = sqrt(a*a + b*b - 2*a*b*cos(rad));
    h = area * 2 / a;

    cout << fixed << setprecision(6);
    cout << area << endl;
    cout << a + b + c << endl;
    cout << h << endl;
}


Measured memory_bytes: 3464
n=int(input())
cnt=0
flag=False
for i in range(n):
    d1,d2=map(int,input().split())
    if d1==d2 and cnt==2:
        print('Yes')
        flag=True
        break
    elif d1==d2:
        cnt+=1
    else:
        cnt=0
if not flag:
    print('No')


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	int ans=0;
	int x=min(a,d);
	ans+=x;
	a-=x;
	d-=x;
	if(d){
		int y=min(b,d);
		b-=y;
		d-=y;
	}
	if(d){
		ans-=d;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3648