akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define MAX_R 10
#define MAX_C 10000
 
int r,c;
bool a[MAX_R][MAX_C];
int ans;
 
void solve(int pos){
    if(pos == r){
	int res = 0;
	for(int i = 0 ; i < c ; i++){
	    int cnt = 0;     
	    for(int j = 0 ; j < r ; j++){
		if(a[j][i]) cnt++;
	    }
	    cnt = max(cnt,r-cnt);
	    res += cnt;
	}
	ans = max(ans,res);
	return;
    }
 
    solve(pos+1);
 
    for(int i = 0 ; i < c ; i++){
	a[pos][i] = !a[pos][i];
    }
 
    solve(pos+1);
}
 
int main(){
    while(cin >> r >> c , (r | c)){
	for(int i = 0 ; i < r ; i++){
	    for(int j = 0 ; j < c ; j++){
		cin >> a[i][j];
	    }
	}
	ans = 0;
	solve(0);
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<iomanip>
#include <iostream>
using namespace std;
    
int main()
{
    int a,b=0;
    cin>>a>>b;
    cout<<a/b<<" "<<a%b<<" ";
    double da,db=0;
    da=(double)a;
    db=(double)b;
    cout<<fixed<<setprecision(5);
    cout<<da/db<<endl;
    return 0;
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll MOD=1000000007;
const ll E=1e18;

const ll MX=1100;
ll dp[MX][MX]={};


int main(){
  ll n;
  while(cin>>n){
    if(n==0){return 0;}
    vector<pair<pll,ll>> A(n);
    for(auto &I:A){cin>>I.F.F>>I.F.S>>I.S;}
    sort(A.begin(),A.end(),[](pair<pll,ll> a,pair<pll,ll> b){return a.F.S==b.F.S?a.F.F<b.F.F:a.F.S<b.F.S;});
    //for(auto &I:A){cout<<I.F.F<<I.F.S<<I.S<<endl;}
    for(int i=0;i<=n;i++){
      for(int t=0;t<=n;t++){
	dp[i][t]=0;
      }
    }
  
    for(int i=0;i<=n;i++){
      for(int t=0;t<=i;t++){
        if(i!=0){dp[i][t]=max(dp[i][t],dp[i-1][t]);}
	if(t!=0){dp[i][t]=max(dp[i][t],dp[i][t-1]);}
	if(i!=0 && t!=0){dp[i][t]=max(dp[i][t],dp[i-1][t-1]);}
	for(int j=i;j<n;j++){
	  auto I=A[j];
	  if(i==0 || I.F.F>A[i-1].F.S){dp[j+1][t]=max(dp[j+1][t],dp[i][t]+I.S);}
	  if(t==0 || I.F.F>A[t-1].F.S){dp[j+1][i]=max(dp[j+1][i],dp[i][t]+I.S);}
	}
	//	cout<<dp[i][t]<<" ";
      }
      //cout<<endl;
    }
    cout<<dp[n][n]<<endl;
  }

  return 0;
}



Measured memory_bytes: 11708
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,m,k,ans,i,c,f
    integer(int64), allocatable:: frac(:), ifrac(:)
    integer(int64),parameter:: md = 998244353

    read*, n,m,k

    allocate(frac(0:n), ifrac(0:n))
    frac(0) = 1
    ifrac(0) = 1
    do i=1,n
        frac(i) = mod(frac(i-1)*i,md)
        ifrac(i) = inv(frac(i),md)
    end do

    do i=0,k
        f = mod(m*factorial(m-1,n-i-1,md),md)
        c = comb(n-1,i,md)
        ans = mod(ans + mod(f*c,md),md)
    end do

    print'(i0)', ans
contains
    function comb(a,b,md) result(ret)
        integer(int64):: a,b,md
        integer(int64):: ret
        ret = mod(mod(frac(a)*ifrac(b),md)*ifrac(a-b),md)
    end function

    function inv(x,md) result(ret)
        integer(int64),intent(in):: x,md
        integer(int64):: ret
        ret = factorial(x,md-2,md)
    end function

    function factorial(a,b,md) result(ret)
        integer(int64):: a,b,md
        integer(int64):: aa,bb,ret
        aa = a
        bb = b
        ret = 1
        do while(bb > 0)
            if (mod(bb,2_8)/=0) ret=mod(ret*aa,md)
            aa=mod(aa*aa,md)
            bb=bb/2
        end do
    end function
end program main

Measured memory_bytes: 6056
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();
    if a + b > n + 1 {
        println!("-1");
        return;
    }

    let mut ans = (1..(n + 1)).collect::<Vec<usize>>();
    for i in 0..((n + b - 1) / b) {
        ans[(i * b)..cmp::min(n, i * b + b)].reverse();
    }

    let mut cur = (n + b - 1) / b;
    if cur > a {
        println!("-1");
        return;
    }
    for i in (0..((n + b - 1) / b)).rev() {
        let from = (i * b);
        let to = cmp::min(n, i * b + b);
        let element = to - from;
        let reversing = cmp::min(element, a - cur + 1);
        ans[from..(reversing + from)].reverse();
        cur += reversing - 1;
        if a == cur {
            break;
        }
    }

    for x in ans.into_iter() {
        print!("{} ", x);
    }
    println!();
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10364
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;

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

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

	bool canExist = true;

	if (n % 2 == 0) {
		if (a[0] != 1 || a[1] != 1) {
			canExist = false;
		}
	}
	else {
		if (n > 1) {
			if (a[0] != 0 || a[1] != 2) {
				canExist = false;
			}
		}else{
			if (a[0] != 0) {
				canExist = false;
}
		}
	}



	for (int i = 2; i < n; i++) {
		if (a[i] != a[i - 2]+2) {
			canExist = false;
		}
	}
	

	ll ans = 1;
	if (!canExist) {
		ans = 0;
	}
	else {
		int num = n / 2;
		for (int i = 0; i < num;i++) {
			ans = (ans * 2) % MOD_CONST;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include "bits/stdc++.h" 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    set<string>ss;
    ll n;
    cin>>n;
    string temp;
    for(ll i=0;i<n;i++){
        cin>>temp;
        ss.in(temp);
    }
    cout<<ss.size()<<"\n";
}

int main(ll argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 19248
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = N * 800;
		int y = (N / 15) * 200;
		int s = x - y;
		System.out.print(s);
	}
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	LL r,d,x;
	cin >> r >> d >> x;
	for (int i = 0; i < 10; i++) {
		x = r*x-d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    int l[110];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i]){
                    continue;
                }
                int vmax=max(max(l[i],l[j]),l[k]);
                int sum=l[i]+l[j]+l[k];
                sum-=vmax;
                if(sum>vmax){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return(0);
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(void)
{
	int i;
	int sum = 0;
	int n;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &n);
		sum+= n;
	}
	
	printf("%d\n", sum);
	
	return (0);
}

Measured memory_bytes: 596
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
int a[500][500]={0};
pii b[250];
int v[4][2]={-1,0,0,1,1,0,0,-1};

int main(){
	int n;
	/*
	rep(i,4){
		cout<<v[i][0]<<" "<<v[i][1]<<endl;
	}
	cout<<endl;
	*/
	while(cin>>n,n){
		rep(i,500) rep(j,500) a[i][j]=0;
		pii t=make_pair(0,0);
		rep(i,250) b[i]=t;
		a[250][250]=1;
		b[0]=make_pair(250,250);
		rep(i,n-1){
			int d,c;
			cin>>c>>d;
			a[b[c].F+v[d][0]][b[c].S+v[d][1]]=1;
			b[i+1]=make_pair(b[c].F+v[d][0],b[c].S+v[d][1]);
			//cout<<b[c].F+v[d][0]<<" "<<b[c].S+v[d][1]<<endl;
		}
		/*
		rep(i,50){
			rep(j,50){
				cout<<a[i+225][j+225]<<" ";
			}
			cout<<endl;
		}
		*/
		//cout<<endl;
		
		rep(i,500){
			bool f=true;
			rep(j,500){
				if(a[i][j]==1){
					f=false;
					break;
				}
			}
			if(f) a[i][0]=-1;
		}
		rep(i,500){
			bool f=true;
			rep(j,500){
				if(a[j][i]==1){
					f=false;
					break;
				}
			}
			if(f) a[0][i]=-1;
		}
		int h=0,w=0;
		rep(i,500){
			if(a[i][0]!=-1){
				reep(j,i,500){
					if(a[j][0]!=-1) h++;
					else break;
				}
				break;
			}
		}
		rep(i,500){
			if(a[0][i]!=-1){
				reep(j,i,500){
					if(a[0][j]!=-1) w++;
					else break;
				}
				break;
			}
		}
		cout<<h<<" "<<w<<endl;
	}
	return 0;
}

Measured memory_bytes: 2136
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long W, H, x, y;
    double cx, cy;

    cin >> W >> H >> x >> y;

    cx = W / 2.0;
    cy = H / 2.0;

    cout << setprecision(20) << (double)W*H/2.0 << endl;

    if(x==cx && y==cy){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

# dp[i][j] : Sのi-1文字目、Tのj-1文字目までの解(文字目は0-index)
dp = [[0 for _ in range(M+1)] for _ in range(N+1)]
#print(dp)
MOD = 10 ** 9 + 7

# なぜこれでよいのかわからない。。。
for i in range(1,N+1):
  for j in range(1,M+1):
    if S[i-1] == T[j-1]:
      # Sのi-1文字目、Tのj-1文字目が一致している場合は、
      # Sのi-2文字目、Tのj-2文字目までの部分列それぞれ
      # Sのi-1文字目、Tのj-1文字目を追加したものと、
      # Sのi-1文字目だけ、Tのj-1文字目だけの部分列パターンが
      # 増えるということだろうか。
      # つまり
      # dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] + (dp[i-1][j-1] + 1)
      #            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      #            ここはS[i-1] != T[j-1]のときと同じ。
      # ということか？
      dp[i][j] = dp[i][j-1] + dp[i-1][j] + 1
    else:
      # dp[i-1][j-1]を引いているのは重複部分の排除？
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
    #print(i,j,dp[i][j],dp[i][j-1],dp[i-1][j],dp[i-1][j-1])
    dp[i][j] %= MOD
print(dp[N][M]+1) #1を足しているのは部分列()の分をカウントするため？


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

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let _: usize = sc.next();
    let s: String = sc.next();

    let mut cnt: usize = 0;
    let mut prev = '$';
    for c in s.chars() {
        if c != prev {
            cnt += 1;
        }
        prev = c;
    }

    println!("{}", cnt);
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}


Measured memory_bytes: 4352
def main():
    N = int(input())
    S = list(input())
    Q = int(input())
    K = tuple(map(int, input().split()))
    d_list = [0] * N
    m_list = [0] * N
    c_list = [0] * N
    M_list = [0] * N
    for index, s in enumerate(S):
        if s == 'D':
            d_list[index] += 1
        elif s == 'M':
            m_list[index] += d_list[index - 1]
            M_list[index] += 1
        elif s == 'C':
            c_list[index] += m_list[index - 1]
        d_list[index] += d_list[index - 1]
        m_list[index] += m_list[index - 1]
        c_list[index] += c_list[index - 1]
        M_list[index] += M_list[index - 1]



    for k in K:
        d = d_list[k - 1]
        m = m_list[k - 1]
        c = c_list[k - 1]
        M = M_list[k - 1]

        for index, x in enumerate(S[k:]):
            if S[index] == 'D':
                m -= M
                d -= 1
            elif S[index] == 'M':
                M -= 1

            if x == 'D':
                d += 1
            elif x == 'M':
                m += d
                M += 1
            elif x == 'C':
                c += m            
        print (c)                


if __name__ == "__main__":
    main()

Measured memory_bytes: 185424
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;

char a[Maxn],b[Maxn];
ll A,B;

int main(){
	cin>>a;
	cin>>b;
	A=strlen(a);
	B=strlen(b);
	if(A>B) printf("GREATER\n");
	if(A<B) printf("LESS\n");
	if(A==B){
		if(strcmp(a,b)>0) printf("GREATER\n");
		if(strcmp(a,b)<0) printf("LESS\n");
		if(strcmp(a,b)==0) printf("EQUAL\n");
	}
}

Measured memory_bytes: 256
import copy
n=int(input())

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

t2 = copy.copy(t1)

t2.sort()

for i in t1:
    if i <= t2[(n//2)-1]:
        print(t2[(n//2)])
    else:
        print(t2[(n//2)-1])

Measured memory_bytes: 93128
#include <bits/stdc++.h>
 
#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif
 
 
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
 
using namespace std;
 
#define INF 1000000000


class Main{
public:
	ll H, W;
	ll h, w;
	Main(){
		cin >> H >> W;
		cin >> h >> w;
		cout << (H-h)*(W-w) << endl;
	}
};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	Main MAIN;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll a, b, c;
int main(void){
    // Your code here!
    cin >> a >> b >> c;
    ll m = max(a, max(b, c));
    if (a == m) cout << b * c / 2 << endl;
    if (b == m) cout << c * a / 2 << endl;
    if (c == m) cout << a * b / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct ii {
    int a, b;
    bool operator < (ii o) const {
        return tie(a, b) < tie(o.a, o.b);
    }
};
struct iii {
    int a, b, c;
    bool operator < (iii o) const {
        return tie(a, b, c) < tie(o.a, o.b, o.c);
    }
};

const int MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 200005;

int arr[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int N, K;
    cin >> N >> K;
    
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    
    int l = 1;
    int r = 1000000000;
    while (l < r) {
        int rem = K;
        int maxLen = (l+r)/2;
        for (int i = 0; i < N; i++) {
            rem -= (arr[i]-1)/maxLen;
        }
        if (rem >= 0) r = maxLen;
        else l = maxLen+1;
    }
    cout << r << "\n";
}


Measured memory_bytes: 4368
###==================================================
### import
#import bisect
#from collections import Counter, deque, defaultdict
#from copy import deepcopy
#from functools import reduce, lru_cache
#from heapq import heappush, heappop
#import itertools
#import math
#import string
import sys
### stdin
def input(): return sys.stdin.readline()
def iIn(): return int(input())
def iInM(): return map(int, input().split())
def iInM1(): return map(int1, input().split())
def iInLH(): return list(map(int, input().split()))
def iInLH1(): return list(map(int1, input().split()))
def iInLV(n): return [iIn() for _ in range(n)]
def iInLV1(n): return [iIn()-1 for _ in range(n)]
def iInLD(n): return [iInLH() for _ in range(n)]
def iInLD1(n): return [iInLH1() for _ in range(n)]
def sInLH(): return list(input().split())
def sInLV(n): return [input().rstrip('\n') for _ in range(n)]
def sInLD(n): return [sInLH() for _ in range(n)]
### stdout
def OutH(lst, deli=' '): print(deli.join(map(str, lst)))
def OutV(lst): print('\n'.join(map(str, lst)))
### setting
sys.setrecursionlimit(10 ** 6)
### utils
int1 = lambda x: int(x) - 1
### constants
INF = int(1e9)
MOD = 1000000007
dx = (-1, 0, 1, 0)
dy = (0, -1, 0, 1)
###---------------------------------------------------

N = iIn()
A = iIn()

if N % 500 <= A:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 62148
#include <iostream>
using namespace std;
string S;
long N[13];
long MOD=1000000007; 
int main() {
	N[0]=1;
	cin >> S;
	int n=S.length();
	int w=1;
	for(int i=0;i<n;i++){
		char c=S[n-i-1];
		int Nnew[13]={};
		if(c=='?'){
			for ( int j=0;j<10;j++){
				int m= (j*w) % 13 ;
				for(int k=0;k<13;k++){
					Nnew[(m + k) % 13 ] += N[k];
					Nnew[(m + k) % 13 ] %= MOD;
				}
			}
		}else{
			int m= ((int)(c-'0')*w) % 13 ;
			for(int k=0;k<13;k++)Nnew[(m + k) % 13 ] = N[k];
		}
		for(int k=0;k<13;k++)N[k]=Nnew[k];
//	for(int k=0;k<13;k++)cout<<Nnew[k]<<" ";

		w=(w*10)%13;
	}
	cout<<N[5]<<endl;
//	for(int k=0;k<13;k++)cout<<N[k]<<" ";
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long


const int inf = 1e9;
int n, k, c;
char s[200005];
int main() {
  //auto start_clock = clock();
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d%d%d", &n, &k, &c);
  scanf("%s", s);

  vector<int> p;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'o') {
      p.push_back(i);
    }    
  }
  int m = p.size();
  vector<int> l(m, 0), r(m, 0);

  for(int i = 0, j = -1, x = 0; i < m; i++) {
    while(p[j + 1] + c + 1 <= p[i]) {
      j += 1;
      x = max(x, l[j]); 
    }
    l[i] = x + 1;
  }

  for(int i = m - 1, j = m, x = 0; i >= 0; i--) {
    while(p[j - 1] - c - 1 >= p[i]) {
      j -= 1;
      x = max(x, r[j]); 
    }
    r[i] = x + 1;
  }

  if(l[m - 1] > k) {
  } else if(l[m - 1] < k) {
    for (auto v : p) {
      printf("%d\n", v + 1);
    }
  } else {
    for (int i = 0; i < m; i++) {
      if(r[i] + l[i] - 1 == k) {
        if(i > 0 && l[i - 1] == l[i]) continue;
        if(i < m - 1 && l[i] - 1 + r[i + 1] == k) continue;
        printf("%d\n", p[i] + 1);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4212
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int h, w;
		cin >> h >> w;
		char pix[64][64];
		for (int i = 0; i < h; ++i)
			cin >> pix[i];

		bool safe = true;
		while (true)
		{
			int x1[26], y1[26], x2[26], y2[26];
			for (int i = 0; i < 26; ++i)
			{
				x1[i] = y1[i] = 333;
				x2[i] = y2[i] = -1;
			}

			for (int y = 0; y < h; ++y)
			{
				for (int x = 0; x < w; ++x)
				{
					if (isalpha(pix[y][x]))
					{
						int c = pix[y][x] - 'A';
						min_swap(x1[c], x);
						min_swap(y1[c], y);
						max_swap(x2[c], x);
						max_swap(y2[c], y);
					}
				}
			}

			bool no_obj = true;
			bool update = false;
			for (int i = 0; i < 26; ++i)
			{
				if (x2[i] == -1)
					continue;

				no_obj = false;


				bool rect = true;
				for (int y = y1[i]; y <= y2[i]; ++y)
					for (int x = x1[i]; x <= x2[i]; ++x)
						if (pix[y][x] != 'A' + i && pix[y][x] != '@')
							rect = false;

				if (rect)
				{
					update = true;
					for (int y = y1[i]; y <= y2[i]; ++y)
						for (int x = x1[i]; x <= x2[i]; ++x)
							pix[y][x] = '@';
				}
			}

			if (no_obj)
				break;
			else if (!update)
			{
				safe = false;
				break;
			}
		}

		cout << (safe ? "SAFE" : "SUSPICIOUS") << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define N 2000050

#define x first
#define y second

using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
pii f[N],tmp1[N],tmp2[N];
int ch[N][2],fa[N],v[N],tp[N],vis[N],le[N],ri[N],mid[N],n,m;
LL lim;
bool flag;

void link(int a,int b) {ch[a][0] ? ch[a][1] = b : ch[a][0] = b;}
inline int rd() {int r;scanf("%d",&r);return r;}

void solve(int u,int l,int r) {
	if (!flag) return ;
	if (!ch[u][0] && !ch[u][1]) {
		f[l] = pii(v[u], v[u]);
		tp[u] = l;
		return ;
	}
	int L = ch[u][0], R = ch[u][1];
	solve(L, l, mid[u]);
	solve(R, mid[u]+1, r);

	int T = tp[R], q1 = 0, q2 = 0;
	for (int i=tp[L];i>=l;i--) {
		while (T>=mid[u]+1 && f[i].y+f[T].x > lim) T--;
		if (T>=mid[u]+1 && f[i].y + f[T].x <= lim)
			tmp1[++q1] = pii(f[i].x, f[T].y);
	}

	T = tp[L];
	for (int i=tp[R];i>=mid[u]+1;i--) {
		while (T>=l && f[i].y+f[T].x > lim) T--;
		if (T>=l && f[i].y+f[T].x <= lim)
			tmp2[++q2] = pii(f[i].x, f[T].y);
	}

	if (!q1 && !q2) {flag = 0; return ;}
	tp[u] = l-1;
	while (q1 || q2) {
		pii cur;
		if (q1 && q2)
			cur = tmp1[q1].x < tmp2[q2].x ? tmp1[q1--] : tmp2[q2--];
		else
			cur = !q1 ? tmp2[q2--] : tmp1[q1--];
		if (tp[u] >= l && cur.y >= f[ tp[u] ].y) continue;
		f[ ++tp[u] ] = cur;
	}
	for (int _=l;_<=tp[u];_++) f[_].x += v[u], f[_].y += v[u];

}

void dfs(int u) {
	if (!ch[u][0] && !ch[u][1]) {
		le[u] = ri[u] = ++m;
		return ;
	}
	dfs(ch[u][0]); dfs(ch[u][1]);
	le[u] = le[ ch[u][0] ];
	ri[u] = ri[ ch[u][1] ];
	mid[u] = ri[ ch[u][0] ];
}

bool go(LL x) {
	lim = x, flag = 1;
	solve(1,1,m);
	return flag;
}

int main() {
	n = rd();
	for (int _=2;_<=n;_++) {
		fa[_] = rd(), v[_] = rd();
		link(fa[_], _);
		if (!vis[ fa[_] ]) vis[ fa[_] ] = 1;
	}

	dfs(1);
	LL l = 0, r = 100000000000LL;
	while (l < r) {
		LL mi = (l + r) >> 1;
		if (go(mi)) r = mi; else l = mi + 1;
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 33536
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAX = 1000;
 
long long n, limit;
long long val[MAX], wt[MAX];

map<int, map<int, int> > dp;

long long knapsack(int n, int W) {
	if (n == 0 || W == 0)
		return 0;
	if (dp.find(n) != dp.end() && dp[n].find(W) != dp[n].end())
		return dp[n][W];
	if (wt[n - 1] > W)
		dp[n][W] = knapsack(n - 1, W);
	else dp[n][W] = max(knapsack(n - 1, W - wt[n - 1]) + val[n - 1], knapsack(n - 1, W));
	return dp[n][W];
}

int main () {
	scanf("%lld %lld", &n, &limit);
	for (int i = 0; i < n; i++)
		scanf("%lld %lld", &wt[i], &val[i]);
	printf("%lld\n", knapsack(n, limit));
	return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<unordered_set>
#include<vector>
#include<climits>
using namespace std;

long long int max(long long int a,long long int b)
{
    if(a>=b)
    {
        return a;
    }
    else
    {
        return b;
    }
}

int main()
{
    long long int n,w;
    cin>>n>>w;
    long long int arr[n+1][w+1];
    for(long long int i=0;i<(w+1);i++)
    {
        arr[0][i] = 0;
    }
    for(long long int i=0;i<(n+1);i++)
    {
        arr[i][0] = 0;
    }
    for(long long int i=1;i<(n+1);i++)
    {
        long long int x,y;
        cin>>x>>y;
        for(long long int j=1;j<(w+1);j++)
        {
            if((j-x)>=0)
            {
                arr[i][j] = max(arr[i-1][j],arr[i-1][j-x]+y);
            }
            else
            {
                arr[i][j] = arr[i-1][j];
            }
        }
    }

    cout<<arr[n][w]<<endl;
}




Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, e, t;
    cin >> b >> e >> t;
    for (int i = b; i < e; i++) {
      swap(v[i], v[t + i - b]);
    }
  }
  for (int i = 0; i < n; i++) {
    if (i)
      cout << " ";
    cout << v[i];
  }
  cout << endl;
}


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

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

    if (a == b && b == c && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    while (1) {
        if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
            ll aa = a, bb = b, cc = c;
            a = (bb + cc) / 2;
            b = (cc + aa) / 2;
            c = (aa + bb) / 2;
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	int a,b,c;
	a=n/100;
	b=((n-(a*100))/10);
	c=n-(a*100)-(b*10);
	
	if(a == 7){
		puts("Yes");
	}else if(b==7){
		puts("Yes");
	}else if(c==7){
		puts("Yes");
	}else{
		puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 1644
import java.util.*;

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

        /* 入力受取 */
        int n = sc.nextInt();
        int[] S = new int[n];
        for(int i = 0;i < n;i++){
            S[i] = sc.nextInt();
        }
        int q = sc.nextInt();
        int[] T = new int[q];
        for(int i = 0;i < q;i++){
            T[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0;i < q;i++){
            for(int j = 0;j < n;j++){
                if(T[i] == S[j]){
                    count++;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


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

ll comb2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i]--;
    vector<int> cnt(n);  //cnt[i]はiの個数
    rep(i,n) cnt[a[i]]++;
    
    ll sum = 0;
    rep(i,n){
        sum += comb2(cnt[i]);
    }
    rep(i,n){
        cout << sum - (cnt[a[i]] -1) << endl;
    }
    return 0;    
}

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

using namespace std;
typedef long long ll;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fr first
#define sc second
#define close(x){cout<<x<<endl;return 0;}
#define pb push_back
#define mp make_pair
#define forr(i,a,b) for(ll i=a;i<b;i++)
ll d(ll x)
{ll c,i,r=1;
for(i=2;i*i<=x;i++)
{if(x%i==0)
{c=0;
while(x%i==0)x/=i,c++;
r*=(c+1);}}
if(x>1)r*=2;
return r;}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);ll n;
cin>>n;;ll s=0;
forr(i,0,n+1)
if(d(i)==8 && i&1)s++;
cout<<s<<endl;
return 0;}


Measured memory_bytes: 256
import java.util.Scanner;

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

         //A,B,C格納用配列
         int[] numList = new int[3];

         //入力値を配列に格納
         for (int i = 0; i < numList.length; i++) {
             numList[i] = sc.nextInt();
         }
         //取り出すカードの枚数: K
         int K = sc.nextInt();
         sc.close();

         //取り出したカードの総和
         int count = 0;
         //カードの数
         int cardNum = 1;

         for (int num : numList) {
             if (num > 0) {
                 if (num > K) {
                     num = K;
                 }
                 count += (cardNum * num);
                 K -= num;
                 if (K == 0) {
                     break;
                 }
             }
             cardNum--;
         }
         System.out.println(count);

    }

}


Measured memory_bytes: 35624
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		for (int i = 0; i < n; i++) {
		    if (dist(sc.nextInt(), sc.nextInt()) <= d) {
		        count++;
		    }
		}
		System.out.println(count);
	}
	
	static double dist(double x, double y) {
	    return Math.sqrt(x * x + y * y);
	}
}


Measured memory_bytes: 60564
/*                                  /   \                                 */      
/*                                 /*****\                               */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K             */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define fi first
#define se second
#define mkp make_pair    
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vll vector< pair<ll,ll> > 
#define mpl map<ll, ll>
#define pr pair<ll,ll>
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second); }
ll pow1(ll n,ll p){if(p==0)return 1;ll x=pow1(n, p/2);x=(x*x)%MOD;if(p%2==0) return x%MOD;else return (x*n)%MOD;}
ll pd(ll x,ll y){if(x%y==0) return x/y;else return x/y+1;}  
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;


//	   cin>>t;
	      while(t--)
{
ll n,m,j,k,l,i;
/*
3
1 1
2 4
3 2*/
cin>>n;
ll a[n],b[n];
vl v1,v2;
//ma=-MOD,mb=-MOD;
fo(i,n)	
{cin>>a[i]>>b[i];
	v1.pb(a[i]+b[i]);
	v2.pb(a[i]-b[i]);
//	ma=max(ma,a[i]);
}
sall(v1);
sall(v2);
ll ans=max(v1[n-1]-v1[0],v2[n-1]-v2[0]);
cout<<ans;
ee;
}
return 0;
}









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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while(true){
    C -= B;
    if(C <= 0){
      cout << "Yes" << endl;
      return 0;
    }
    A -= D;
    if(A <= 0){
      cout << "No" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    VI cnt(n+1);
    REP(i,0,n) cnt[a[i]]++;
    REP(i,0,n) cout<< cnt[i+1] << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 5632
dishes = []
for _ in range(5):
    dishes.append(int(input()))

time = []
min = 10

for dish in dishes:
    if dish % 10 == 0:
        time.append(dish)
    else:
        time.append((dish // 10 + 1)* 10)
        if min > dish % 10:
            min = dish % 10

print(sum(time) - (10 - min))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using namespace std;
typedef pair<int,int> P;
int N,M;
struct edge{
    int to,dist,cost;
};

int main(){
    while(cin >> N >> M && N){
        int inf = INT_MAX;
        vector<vector<edge>> v(N+1);
        vector<int> D(N+1,inf);
        D[1] = 0;
        int a,b,d,c;
        for(int i=0;i<M;i++){
            cin >> a >> b >> d >> c;
            v[a].push_back({b,d,c});
            v[b].push_back({a,d,c});
        }
        int ans = 0;
        priority_queue<P,vector<P>,greater<P>> Q;
        Q.push({0,1});
        while(!Q.empty()){
            P p = Q.top(); Q.pop();
            if(D[p.second]<p.first) continue;
            int t = inf;
            for(auto x:v[p.second]){
                if(D[x.to]!=inf && D[x.to]+x.dist==p.first) t = min(t,x.cost);
                else if(D[x.to]>p.first+x.dist){
                    D[x.to] = p.first+x.dist;
                    Q.push({D[x.to],x.to});
                }
            }
            if(t!=inf) ans += t;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3860
N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

edge1 = 0
edge2 = 0
start = 0

prev = A[start]
for i in range(start + 1, N):
    if A[i] == prev:
        edge1 = prev
        start = i + 1
        break
    prev = A[i]

prev = A[start]
for i in range(start + 1, N):
    if A[i] == prev:
        edge2 = prev
        break
    prev = A[i]

print(str(edge1 * edge2))


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

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

  vector<uint64_t> p(N + 1);  // 各組織の親組織を示す配列
  p.at(0) = 2;
  p.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    p.at(i) = p.at(i - 2) + p.at(i - 1);
  }

  cout << p.at(N) << endl;
}

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

int main() {

    int N;
    cin >> N;

    int cnt = 0;
    int a;
    rep(i, N) {
        cin >> a;
        if(i%2 == 0 && a%2 == 1) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


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

int main(){
    int h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;
    cout<<max(0,(h2*60+m2)-(h1*60+m1)-k)<<endl;
}

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

int main(){
  ll N;
  cin >> N;
  string M;
  cin >> M;
  ll ans;
  ll r=0,g=0,b=0;
  for(ll i=0;i<N;i++){
    
    if(M[i]=='R'){
      r++;
    }
    if(M[i]=='G'){
      g++;
    }
    if(M[i]=='B'){
      b++;
    }
    if(i==N-1){
      ans=r*g*b;
    }
  }

  for(ll i=0;i<N;i++){
    for(ll j=i+1;2*j-i<N;j++){
      if(M[j]==M[i]){
        continue;
      }
      else{
        if(M[2*j-i]!=M[j] && M[2*j-i]!=M[i]){
            ans--;
        }
      }
    }
  }
  cout << ans <<endl;
}
        
        

Measured memory_bytes: 3604
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    public void solve() {
    	long H = nl();
    	long ans = 0;
    	long cnt = 1;
    	while(true) {
    		if(H == 1) {
    			ans += cnt;
    			break;
    		} else {
    			ans += cnt;
    			H /= 2;
    			cnt *= 2;
    		}
    	}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


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

int main() {
  int n, k;
  cin >> n >> k;
  ll ans = k;
  for (int i = 1; i<n; i++) ans *= k-1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  string N;
  cin >> N;
  int s = N.size();
  if (N.at(s-1)=='3') cout << "bon" << endl;
  else if (N.at(s-1)=='0' || N.at(s-1)=='1' || N.at(s-1)=='6' || N.at(s-1)=='8') cout << "pon" << endl;
  else cout << "hon" << endl;

  

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define int long long int
using namespace std;
vector<vector<int> >g(100001);
int b[100001],w[100001],m=1e9+7,n,x,y;
void rec(int v){
	b[v]=w[v]=1;
	for(int i=0;i<g[v].size();i++){
		if(b[g[v][i]]!=0) continue;
		rec(g[v][i]);
		b[v]*=w[g[v][i]];
		b[v]%=m;
		w[v]*=w[g[v][i]]+b[g[v][i]];
		w[v]%=m;
	}
}
main(){
	cin>>n;n--;
	while(n--){
		cin>>x>>y;
		g[x-1].push_back(y-1);
		g[y-1].push_back(x-1);
	}
	rec(0);
	cout<<(b[0]+w[0])%m;
}

Measured memory_bytes: 11392
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[101];
  int i;

  scanf("%s", s);
  for(i = 0; i < strlen(s); i++) {
    s[i] = 'x';
  }
  printf("%s\n", s);

  return 0;
}


Measured memory_bytes: 128
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B=get
if A==B
    puts "="
elsif A>B
    puts ">"
else
    puts "<"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define dcout cout << fixed << setprecision(15)
#define rep(i, a) for(int i = 0; i < a; i++)
#define arep(i, x) for(auto i : x)
#define all(v) v.begin(), v.end()
#define int long long
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
using namespace std;
signed main() {
    int n, k;
    cin >> n >> k;
    if(n == k)
        cout << 1;
    else
        cout << (n - k - 1) / (k - 1) + 2;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <climits>
#include <cstdlib>
#include <cassert>
using namespace std;
template <typename T> using vec=vector<T>;
template <typename T> using mat=vec<vec<T>>;
using base=complex<double>;
using pp=pair<int,int>;
using lint=long long;

int N,K;
const int MAX_N = 100005;
const lint MOD = 1e9+7;
const lint INF = 1e18;

mat<int> path;

void input(){
	cin >> N >> K;
	path.assign(N+1,vec<int>());
	for(int i=1,x,y;i<N;i++){
		cin >> x >> y;
		path[x].push_back(y);
		path[y].push_back(x);
	}
}

int dfs(int v,int p,int h){
	if(h>K/2)return 0;
	int ret = 1;
	for(int u:path[v]){
		if(u==p)continue;
		ret += dfs(u,v,h+1);
	}
	return ret;
}

void solve(){
	int ans = 0;

	if(K%2==0){
		for(int i=1;i<=N;i++){
			ans = max(ans, dfs(i,i,0));
		}
	}else{
		for(int v=1;v<=N;v++){
			for(int u:path[v]){
				ans = max(ans, dfs(u,v,0)+dfs(v,u,0));
			}
		}
	}
	cout << N - ans << endl;
}

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

	input();
	solve();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 55;
int n,m,tot;
ll dis[maxn][2600],c[maxn],t[maxn];
ll s;
int head[maxn];
struct node
{
	int to,next;
	ll w,cost;
}e[maxn*maxn];
void add(int u,int v,ll w,ll c){
	e[tot].to = v;
	e[tot].w = w;
	e[tot].cost = c;
	e[tot].next = head[u];
	head[u] = tot++;
}
void dijkstra(ll s,ll d[][2600]){
	queue<pair<int,ll> > q;
	int vis[n+5][2600];
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<=2500;j++) dis[i][j] = 0x3f3f3f3f3f3f3f3f,vis[i][j] = 0;
	}
	d[1][s] = 0;
	q.push({1,s});
	while(!q.empty()){
		int cur = q.front().first;
		ll w = q.front().second;
		q.pop();
		//if(vis[cur][w]) continue;
		//vis[cur][w] = 1;
		for(int i = head[cur];~i;i = e[i].next){
			int y = e[i].to;
			ll a = e[i].w,b = e[i].cost;
			if(w>=b && d[y][w - b] > d[cur][w] + a ){
				d[y][w-b] = d[cur][w] + a;
				q.push({y,w-b});
			}
		}
		if(d[cur][min(w + c[cur],(ll)2500)]> d[cur][w] + t[cur]){
			d[cur][min(w + c[cur],(ll)2500)] = d[cur][w] + t[cur];
			q.push({cur,min(w + c[cur],(ll)2500)});
		}
	}
}
int main(){
	scanf("%d%d%lld",&n,&m,&s);
	s = min(s,(ll)2500);
	for (int i = 0; i <=n; ++i) head[i] = -1;
		/* code */
	for (int i = 0; i <m; ++i)
	{
		int u,v;ll a,b;
		scanf("%d%d%lld%lld",&u,&v,&a,&b);
		add(u,v,b,a);
		add(v,u,b,a);
		/* code */
	}
	for(int i = 1;i<=n;i++){
		scanf("%lld%lld",&c[i],&t[i]);
	}
	dijkstra(s,dis);
	for(int i = 2;i<=n;i++){
		ll ans = 0x3f3f3f3f3f3f3f3f;
		for(int j = 0;j<=2500;j++) ans = min(ans,dis[i][j]);
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 5916
import bisect
a,b,q=map(int,input().split())
s=[-999999999999]+[int(input()) for i in range(a)]+[999999999999]
t=[-999999999999]+[int(input()) for i in range(b)]+[999999999999]
x=[int(input()) for i in range(q)]
for i in range(q):
  a1=s[bisect.bisect_left(s,x[i])-1]
  a2=s[bisect.bisect_left(s,x[i])]
  b1=t[bisect.bisect_left(t,x[i])-1]
  b2=t[bisect.bisect_left(t,x[i])]
  l=[]
  for j in [a1,a2]:
    for k in [b1,b2]:
      l.append(abs(j-k)+min(abs(x[i]-j),abs(x[i]-k)))
  print(min(l))

Measured memory_bytes: 85676