akhauriyash/Code-Regression huggingface dataset:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
# MOD = 10 ** 9 + 7
MOD = 998244353
num_list = []
str_list = []

def main():
    n, k = i_map()
    num_list = i_row_list(k)

    dp = [0] * (n+1)
    dp_sum = [0] * (n+1)
    dp[1] = 1
    dp_sum[1] = 1

    for i in range(2, n+1):
        for j in range(k):
            li = i - num_list[j][1]
            ri = i - num_list[j][0]
            if ri < 0:
                continue
            li = max(li, 0)
            dp[i] += dp_sum[ri] - dp_sum[li-1]
            dp[i] %= MOD
        dp_sum[i] = dp_sum[i-1] + dp[i]
    
    print(dp[n]%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81872
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    if(n+1 < a+b or ll(a)*b<n) {
        cout << -1 << endl;
        return 0;
    }
    if(a == 1) {
        rep(i, n) {
            cout << n-i << (i == n-1?'\n':' ');
        }
        return 0;
    }
    vi ans;
    int h = n;
    h -= b;
    int g = h/(a-1);
    int gj = h%(a-1);
    gj++;
    int l = n+1;
    rep(i, g) {
        rep(j, a) {
            ans.push_back(l-a+j);
        }
        l -= a;
    }
    rep(i, gj) {
        ans.push_back(l-gj+i);
    }
    l -= gj;
    rep(i, l-1) {
        ans.push_back(l-1-i);
    }

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

Measured memory_bytes: 5324
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return(b%a,a);
}
int main()
{
    fast
    ll n;
    cin>>n;
    ld a[n];
    go(i,0,n){
        cin>>a[i];
    }
    sort(a,a+n);
    go(i,1,n){
        a[i] = (a[i]+a[i-1])/(ld)2;
    }
    cout<<fixed<<setprecision(20)<<a[n-1];
    return 0;
}



Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
		for(int i=0;i<n;i++){
			int a = scanner.nextInt();
			for(int j=-1;j<=1;j++){
				if(map.containsKey(a+j)){
					map.put(a+j, map.get(a+j) + 1);
				}else{
					map.put(a+j, 1);
				}
			}
		}
		int max = 0;
		for(Integer key : map.keySet()){
			max = Math.max(max, map.get(key));
		}
		System.out.println(max);
	}

}


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

vector<int> buf;

int main()
{
    string S, T, ans;
    cin>>S>>T;
    for (int i = 0; i < S.size(); i++)
    {
        ans = "Yes" ;
        if (S[i] != T[i])
        {
            ans = "No";
            break;
        }
    }

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

Measured memory_bytes: 3628
n, m = map(int, input().split())
ans = [0 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        ans[b - 1] += 1
    elif b == n:
        ans[a - 1] += 1

if 2 in ans:
    print("POSSIBLE")
else:
     print("IMPOSSIBLE")

Measured memory_bytes: 4656
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <tuple>
#include <complex>
#include <stdio.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LD PI = acos(-1.0);
const LL mod = 1000000007;
const LL INF = 1e9;
const LL MAXN = 100001;

int n;
int m;
VVCH a;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> n >> m;
	a.assign(n, VCH(m, 0));
	FOR(i, 0, n)
		FOR(j, 0, m)
		cin >> a[i][j];

	auto b = a, c = a;

	FOR(i, 0, m)
		b[0][i] = '#', c[n - 1][i] = '#';

	for (int i = 0; i < m; i += 2)
		FOR(j, 1, n - 1)
		b[j][i] = '#';

	for (int i = 1; i < m; i += 2)
		FOR(j, 1, n - 1)
		c[j][i] = '#';

	FOR(i, 0, n)
	{
		FOR(j, 0, m)
			cout << b[i][j];
		cout << endl;
	}
	cout << endl;

	FOR(i, 0, n)
	{
		FOR(j, 0, m)
			cout << c[i][j];
		cout << endl;
	}
	//cin >> n;
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//セグメント木のテンプレ.RMQ.
//findでは[a,b)の範囲で返す.[a,b]でないことに注意.
class SegmentTree{
	public:
		int n;
		vector<set<int>> node;
		set<int> inf;
		
		SegmentTree(vector<int> v){
			int sz = v.size();
			this->n = 1;
			while(n < sz)
				n = n * 2;
			this->node.resize(2 * n - 1, this->inf);
			for (int i = 0; i < sz; i++)
				node[i + n - 1] = set<int>({v[i]});
			for (int i = n - 2; i >= 0; i--){
				set<int> res;
				set_union(all(node[2 * i + 1]), all(node[2 * i + 2]), inserter(res, res.end()));
				node[i] = res;
			}
		}
		void update(int x, int val){
			x += n - 1;
			node[x] = set<int>({val});
			while(x > 0){
				x = (x - 1) / 2;
				set<int> res;
				set_union(all(node[2 * x + 1]), all(node[2 * x + 2]), inserter(res, res.end()));
				node[x] = res;
			}
		}
		set<int> find(int a, int b, int k = 0, int l = 0, int r = -1){
			if (r < 0)
				r = n;
			if (r <= a || b <= l)
				return this->inf;
			if (a <= l && r <= b)
				return node[k];
			set<int> lv = this->find(a, b, 2 * k + 1, l, (l + r) / 2);
			set<int> rv = this->find(a, b, 2 * k + 2, (l + r) / 2, r);
			set<int> res;
			set_union(all(lv), all(rv), inserter(res, res.end()));
			return res;

		}
};

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> v(n);
	rep(i, n) v[i] = s[i] - 'a';
	SegmentTree st(v);

	int q;
	cin >> q;
	rep(qi,q){
		int c;
		cin >> c;
		if (c == 1){

			int x;
			char y;
			cin >> x >> y;
			st.update(x-1, y - 'a');
		}
		else
		{
			int x,y;
			cin >> x >> y;
			cout << st.find(x - 1, y).size() << endl;
		}
	}

	return 0;
}

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

pub 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")
}

use std::cmp::min;

fn main() {
    let n: usize = read();
    let m: usize = read();
    let mut minv = std::i64::MAX;
    let x: usize = read();
    let mut books: Vec<(usize, Vec<usize>)> = vec![];
    for _ in 0..n {
        let c: usize = read();
        let mut a: Vec<usize> = vec![];
        for _ in 0..m {
            let ai = read();
            a.push(ai);
        }
        books.push((c, a))
    }

    for i in 0..2_u32.pow(n as u32) {
        let result: String = format!("{:0>keta$b}", i, keta = n as usize);
        let mut skills = vec![0; m];
        let mut price = 0;
        let v: Vec<char> = result.chars().collect();
        for i in 0..n {
            if v[i] == '1' {
                for j in 0..books[i].1.len() {
                    skills[j] += books[i].1[j]
                }
                price += books[i].0;
            }
        }
        let mut check = skills.iter().all(|a| *a >= x);
        if check {
            minv = min(minv, price as i64);
        }
    }
    if minv == std::i64::MAX {
        println!("-1");
    } else {
        println!("{}", minv);
    }
}


Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, T;
  cin >> n >> T;
  vector<ll> c(n), t(n);
  REP(i, n) { cin >> c[i] >> t[i]; }

  ll ans = 1e18;
  REP(i, n) {
    if (t[i] > T) continue;
    ans = min(ans, c[i]);
  }

  if (ans == 1e18) {
    cout << "TLE" << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	
	int xa, yb, yc, yd, jp;
	int xlim, ylim, jlim;
	
	scanf("%d", &xa);
	scanf("%d", &yb);
	scanf("%d", &yc);
	scanf("%d", &yd);
	scanf("%d", &jp);
	
	xlim = xa * jp;
	
	if (jp <= yc) {
		ylim = yb;
	} else {
		ylim = (jp - yc) * yd + yb;
	}
	
	jlim = (xlim < ylim)? xlim : ylim;
	
	printf("%d\n", jlim);
	
	return 0;
}

Measured memory_bytes: 2748
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1e18;

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

	ll n, h, w;
	cin >> h >> w >> n;
	cout << min((n + h-1) / h, (n + w-1) / w) << '\n';
}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}

int64_t calcmodcomb(int64_t n,int64_t r){
  return (((modfact.at(n)*modinvfact.at(r))%univMod)*modinvfact.at(n-r))%univMod;
}

int64_t calcmodpositive(int64_t n){
  return (n + ((abs(n)+univMod-1)/univMod)*univMod)%univMod;
}
  
    */


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t a,b,c;
  cin >> a >> b >> c;
  cout << b + min(c,a+b+1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
int k,t;
cin>>k>>t;
priority_queue<int> a;
for(int i=0;i<t;i++){
int b;
cin>>b;
a.push(b);
}
while(a.size()!=1){
	int b,c;
	b=a.top();
	a.pop();
	c=a.top();
	a.pop();
	a.push(b-c);
//	cout<<b<<' '<<c<<' '<<b-c<<endl;
}
if(a.top()==0){
	cout<<0<<endl;
}else{
	cout<<a.top()-1<<endl;
}

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <vector>
#include <utility>
#include <time.h>
#include <set>
#include <unordered_set>
#include <list>
#include <iterator>
#include <time.h>
#include <chrono>
#include <deque>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <climits>
using namespace std;

#define ll long long
#define ldb long double

ll mod(ll a, ll b)
{
	return (b + (a % b)) % b;
}

ll subMod(ll a, ll b, ll M)
{
	return mod((mod(a, M) - mod(b, M)), M);
}

void solve()
{
	unordered_set<ll> a;
	ll n;
	cin >> n;

	bool test = true;

	for (int i = 0; i < n; i++)
	{
		ll temp;
		cin >> temp;

		if (a.find(temp) != a.end())
		{
			test = false;
		}

		a.insert(temp);
	}

	if (test)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
}

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

	solve();

	return 0;
}

Measured memory_bytes: 8520
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#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 = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {

	int n, m;
	scanf("%d%d", &n, &m);
	vector<int> a(n);
	unordered_map<int, int> d;
	rep(i, n) {
		scanf("%d", &a[i]);
		++d[a[i]];
	}
	int b, c;
	rep(i, m) {
		scanf("%d%d", &b, &c);
		a.pb(c);
		d[c] += b;
	}
	sort(all(a));
	a.erase(unique(all(a)), a.end());
	reverse(all(a));
	//for (auto aa : a)debug("%d ", aa);
	//printf("\n");
	ll ans = 0;
	for(int i = 0, count = 0; count < n; ++count, ++i) {
		//debug("%lld\n", ans);
		ans += (ll)a[i] * (ll)min(d[a[i]], n - count);
		//cerr << '+' << a[i].first << " * " << min(d[a[i].first], n - count) << endl;
		count += min(d[a[i]], n - count) - 1;
	}
	
	printf("%lld\n", ans);

	Please AC;
}

Measured memory_bytes: 8948
//00
#include<iostream>
#include<algorithm>

using namespace std;

int calc(bool *f,bool *l,bool *m){
  int r=0;
  for(bool *n=m-1;n!=f&&*n;n--){
    r++;
  }
  for(m++;m!=l&&*m;m++){
    r++;
  }
  return r+1;
}

int main(){
  for(int n,k;cin>>n>>k,n|k;){
    bool c[100001]={};
    while(k--){
      int r;
      cin>>r;
      c[r]=true;
    }
    int ans=0;
    if(c[0]){
      for(int i=1;i<=n;i++){
	if(!c[i]){
	  ans=max(ans,calc(c,c+n+1,c+i));
	}
      }
    }else{
      int cc=0;
      for(int i=1;i<=n;i++){
	if(c[i]){
	  cc++;
	}else{
	  cc=0;
	}
	ans=max(ans,cc);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}
	
	

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  printf("%c%c%c", toupper(a[0]), toupper(b[0]), toupper(c[0]));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dp[200005];
long long int n,k;
vector< int > arr(200005);
long long int mini=1e5;
 int gen(long long int i)
{
    //for(int i=x;i<n;i++)
      //  dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
     // long long int ans;
        if(i>=n-1)
            return 0;
        if(dp[i]!=-1)
            return dp[i];
        int ans=INT_MAX;

        for(int j=1;j<=k;j++)
        {
            if(i+j>=n)
                break;
            ans=min(ans,gen(i+j)+abs(arr[i]-arr[i+j]));
        }



      return dp[i]=ans;
}
int main()
{
   // int n;
    cin>>n>>k;
   // vector<int> arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    //input part has been done

    long long int mini=1e5;
    memset(dp,-1,sizeof(dp));
    //initialization
    //dp[0]=0;
    //dp[1]=abs(arr[0]-arr[1]);


    cout<<gen(0);
    //cout<<dp[n-1];
}


Measured memory_bytes: 10272
(n,),*v = $<.map{|l|l.split.map &:to_i}
path = (0..n).map{[]}
v.each{|s,t|
  path[s]+=[t]
}
through = (0..n).map{0.0}
through[1] = 1.0
(1..n-1).each{|i|
  th = through[i]/path[i].size
  path[i].each{|j|
    through[j] += th
  }
}
dp_all = (0..n).map{0.0}
dp_del = (0..n).map{0.0}
(1..n-1).reverse_each{|i|
  nextpath = path[i].map{|t|dp_all[t]}
  sum = nextpath.inject(:+)
  dp_del[i] = dp_all[i] = sum/nextpath.size + 1
  if nextpath.size > 1
  	dp_del[i] = (sum - nextpath.max)/(nextpath.size - 1) + 1
  end
}
ans = dp_all[1] - (1..n-1).map{|i|(dp_all[i]-dp_del[i])*through[i]}.max
p ans

Measured memory_bytes: 113068
#include <stdio.h>
#include <stdlib.h>

int A[1000];
int i;
void push(int s);
int pop();
int main()
{
  int x,y;
  char su[100];
  i=0;  
  while(scanf("%s",su)!= EOF){   
    if(su[0]=='+'){
      x = pop();
      y = pop();
      push(x+y);
    }
    else if(su[0]=='-'){
      x = pop();
      y = pop();
      push(y-x);
    }
    else if(su[0]=='*'){
      x = pop();
      y = pop();
      push(x*y);  
    }
    else{
      push(atoi(su));
    }   
  } 
  printf("%d\n",pop());
  return 0;                          
}               

void push(int s){
 
  A[++i]=s;
}
int pop(){
  i--;
  return A[i+1];
}



Measured memory_bytes: 2048
N,M = map(int, input().rstrip().split())
k_s = [list(map(int, input().rstrip().split())) for _ in range(M)]
for i in range(M):
    k_s[i].pop(0)
P = list(map(int, input().split()))
#on=1,off=0
count = 0
counter = 0
limit = 2**N
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                for m in range(2):
                    for n in range(2):
                        for o in range(2):
                            for p in range(2):
                                for q in range(2):
                                    for r in range(2):
                                        counter += 1
                                        stats = [r,q,p,o,n,m,l,k,j,i]
                                        flg = True
                                        index = 0
                                        for s in k_s:
                                            sums = 0
                                            for t in s:
                                                sums += stats[t-1]
                                            rem = sums % 2
                                            if rem != P[index]:
                                                flg = False
                                                break
                                            index += 1
                                        if flg:
                                            count += 1
                                        if limit == counter:
                                            print(count)

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=1000000007
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    c=[0,0,0]
    ans=1
    for i in range(N):
        tmp=0
        color=-1
        for x in range(3):
            if A[i]==c[x]:
                tmp+=1
                color=x
        ans*=tmp
        ans%=MOD
        c[color]+=1
    print(ans%MOD)

if __name__ == '__main__':
    main()


Measured memory_bytes: 52952
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
    int n;
    int m;
    int l;
 
   cin >> n >> m >> l;
  
   if(n==1){
     
      cout << "Hello World" << endl;
   }else{
     
     cout << m+l << endl;
     
   }
  
  
  
  
  return 0;
}

Measured memory_bytes: 256
n,y = map(int,input().split())

b = [0,0,0]
total = b[0] * 10000 + b[1] * 5000 + b[2] * 1000

for i in range(n + 1):
    b[0] = i
    for j in range(n - i + 1):
        b[1] = j
        b[2] = n - i - j
        total = b[0] * 10000 + b[1] * 5000 + b[2] * 1000
        #print(b)
        if sum(b) == n and total == y:
            print(*b)
            exit()

print(-1,-1,-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int X[ 110 ];
int Y[ 110 ];
int H[ 110 ];


int main()
{
int i;
int j;
int k;
int N;
int iTmp;
int iChk;
int x;
int y;
int h;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;

	h = 0;
	for( i = 0; i < N; i++ )
	{
		cin >> X[ i ];
		cin >> Y[ i ];
		cin >> H[ i ];
		
		if( h == 0 && H[ i ] != 0 )
		{
			x = X[ i ];
			y = Y[ i ];
			h = H[ i ];
		}
	}

	for( i = 0; i <= 100; i++ )
	{
		for( j = 0; j <= 100; j++ )
		{
			iChk = h + abs( i - x ) + abs( j - y ); 

			for( k = 0; k < N; k++ )
			{
				if( H[ k ] != max( iChk - abs( i - X[ k ] ) - abs( j - Y[ k ] ), 0 ) )
					break;
			}

			if( k == N )
			{
				cout << i << " " << j << " " << iChk << endl;

				return 0;
			}
		}
	}

	return 0;
}






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

const string YES = "Yes";
const string NO = "No";

/*
void solve(std::vector<std::vector<long long>> c){
    ll left = c[0][0] + c[1][1] + c[2][2];
    ll right = c[0][2] + c[1][1] + c[2][0];
    ll all = (c[0][0] + c[0][1] + c[0][2] + c[1][0] + c[1][1] + c[1][2] + c[2][0] + c[2][1] + c[2][2]) % 3;
    if(left == right && all == 0) cout << YES << endl;
    else cout << NO << endl;
}
*/

void solve(std::vector<std::vector<long long>> c){
    if(c[1][0] - c[0][0] == c[1][1] - c[0][1] && c[1][1] - c[0][1] == c[1][2] - c[0][2] && c[2][0] - c[0][0] == c[2][1] - c[0][1] && c[2][1] - c[0][1] == c[2][2] - c[0][2]) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    std::vector<std::vector<long long>> c(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&c[i][j]);
        }
    }
    solve(std::move(c));
    return 0;
}


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

int main() {

	int n; cin >> n;
	int ans = -1;
	for (int i = n * 0.9; i <= n; i++) {
		if ((int)(1.08 * i) == n) {
			ans = i;
		}
	}
	if (ans == -1) cout << ":(" << endl;
	else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
package main

import (
	"fmt"
)

func main() {
	var N, r int
	fmt.Scan(&N)
	a := make([]int, N)
	x := make([]int, N*15)
	y := make([]int, N*15)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
		for j := 0; j < a[i]; j++ {
			fmt.Scan(&x[i*N+j], &y[i*N+j])
		}
	}
	for s := 0; s < 1<<uint(N); s++ {

		q := make([]int, 0)
		m := map[int]int{}
		for i := 0; i < N; i++ {
			if (s & (1 << uint(i))) > 0 {
				q = append(q, i)
				m[i]++
			}
		}
		b := true
		for k, _ := range m {
			for j := 0; j < a[k]; j++ {
				wx := x[k*N+j]
				wy := y[k*N+j]
				_, isExist := m[wx-1]
				if wy == 1 {
					if !isExist {
						b = false
						break
					}
				} else {
					if isExist {
						b = false
						break
					}
				}
			}
			if !b {
				break
			}
		}
		if b {
			r = Max(r, len(m))
		}
	}
	fmt.Println(r)

}
func Max(a, b int) int {
	if b > a {
		return b
	}
	return a
}


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

int main()
{
    int N; cin >> N;
    int V[N], C[N];
    for(int i = 0; i < N; ++i) {
        cin >> V[i];
    }
    for(int i = 0; i < N; ++i) {
        cin >> C[i];
    }
    int A[N];
    for(int i = 0; i < N; ++i) {
        A[i] = V[i] - C[i];
    }
    int sum = 0;
    for(int i = 0; i < N; ++i) {
        if(A[i] >= 0) sum += A[i];
    }
    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 764
n=int(input())
h=list(map(int,input().split()))
from itertools import groupby
ans=0
for i in range(101):
  c=[0]*n
  for j in range(n):
    if h[j]>0:c[j]=1
  gr=groupby(c)
  for k,v in gr:
    if k>0:ans+=1
  for j in range(n):
    if h[j]>0:h[j]-=1
print(ans)




Measured memory_bytes: 3060
import numpy as np
n,m = list(map(int, input().split()))
tmp_a = [list(input()) for _ in range(n)]
tmp_b = [list(input()) for _ in range(m)]

a = np.array(tmp_a)
b = np.array(tmp_b)

for a_i in range(n - m + 1):
	for a_j in range(n - m + 1):
		if((a[a_i:a_i + m, a_j:a_j + m] == b).all()):
			print("Yes")
			exit()
print("No")

Measured memory_bytes: 12500
#include <iostream>
#include <algorithm>
using namespace std;
int n,t,ans,b;
int main(void){
    cin>>n>>t>>b;
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        if(b+t<a)ans+=t;
        else ans+=(a-b);
        b=a;
    }
    cout<<ans+t<<endl;
}


Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
base = 10**9 + 7
comb = [[0 for i in range(j + 1)] for j in range(n + 1)]
comb[0][0] = 1
for i in range(n):
	for j in range(i + 2):
		if j == 0 or j == i + 1:
			comb[i + 1][j] = 1
		else:
			comb[i + 1][j] = (comb[i][j - 1] + comb[i][j]) % base

def cmb(i, j):
	if j > i or j < 0:
		return 0
	return comb[i][j]

for i in range(k):
	print((cmb(n - k + 1, i + 1) * cmb(k - 1, i)) % base)
	

Measured memory_bytes: 83736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,s,w,q;
    while(cin >>n >>s >>w >>q,n){
        int g = s;
        vector<ll> a(n);
        rep(i,n){
            a[i] = (g/7)%10;
            if(g%2==0) g = (g/2);
            else g = (g/2)^w;
        }

        ll ans = 0;
        if(q==2 || q==5){
            ll non_zero = 0;
            rep(i,n){
                non_zero += (a[i]!=0);
                if(a[i]%q==0){
                    ans += non_zero;
                }
            }
        }
        else{
            vector<ll> pw(n);
            pw[0] = 1;
            for(int i=1; i<n; ++i) pw[i] = (pw[i-1]*10)%q;

            vector<ll> suf(n);
            suf[n-1] = a[n-1]%q;
            for(int i=1; i<n; ++i){
                suf[n-1-i] = (suf[n-i]+pw[i]*a[n-1-i])%q;
            }

            map<ll,int> ct;
            rep(i,n){
                if(a[i]!=0) ++ct[suf[i]];
            }

            for(int i=n-1; i>=0; --i){
                ll sub = 0;
                if(i+1<n) sub = suf[i+1];

                if(ct.count(sub)) ans += ct[sub];
                if(a[i]!=0) --ct[suf[i]];

            }
        }

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



Measured memory_bytes: 10740
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<vector<ll>> mp(201, vector<ll>(201, -1));

ll gcd(ll a, ll b) {
  if (mp.at(a).at(b) != -1) {
    return mp.at(a).at(b);
  }
  if (mp.at(b).at(a) != -1) {
    return mp.at(b).at(a);
  }

  ll result = b ? gcd(b, a % b) : a;
  mp.at(a).at(b) = result;

  return result;
}

void solve(ll K) {
  ll result = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= K; j++) {
      ll r1 = gcd(i, j);
      for (int k = 1; k <= K; k++) {
        if (k == i || k == j) {
          result += r1;
        } else {
          ll v;
          if (r1 > k) {
            v = gcd(r1, k);
          } else {
            v = gcd(k, r1);
          }
          result += v;
        }
      }
    }
  }

  cout << result << endl;
}

int main() {
  ll K;
  scanf("%lld", &K);
  solve(K);
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    //Aの中で絶対値が最大のものがA[j]
    int j = -1, M = 0;
    rep(i, N){
        int A;
        cin >> A;
        if(abs(A) >= abs(M)){
            M = A;
            j = i;
        }
    }
    cout << 2*N-1 << endl;
    rep(i, N){
        cout << j+1 << ' ' << i+1 << endl;
    }
    if(M > 0){
        rep2(i, 1, N-1){
            cout << i << ' ' << i+1 << endl;
        }
    }
    else{
        rep3(i, N, 2){
            cout << i << ' ' << i-1 << endl;
        }
    }
}

Measured memory_bytes: 256
EPS = 1e-4

#外積
def OuterProduct(one, two):
	tmp = one.conjugate() * two
	return tmp.imag

#直線の交点，平行の場合はFを返す
def Crosspoint(a, b, c, d):
	if abs(OuterProduct(b-a, d-c)) <= EPS:
		return False
	else:
		u = OuterProduct(c-a, d-a) / OuterProduct(b-a, d-c)
		return (1-u)*a + u*b

n = int(input())
for _ in range(n):
	pp = list(map(int, input().split()))
	p = [complex(pp[i], pp[i+1]) for i in range(0, 8, 2)]
	ans = Crosspoint(p[0], p[1], p[2], p[3])
	print(ans.real, ans.imag)


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

#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli a,b,c;

  while(1){
    cin>>a>>b>>c;
    if(a==-1 and b==-1 and c==-1)break;

    if(a==-1 or b==-1){
      cout<<"F"<<endl;
    }else if(a+b>=80){
      cout<<"A"<<endl;
    }else if(a+b>=65){
      cout<<"B"<<endl;
    }else if(a+b>=50){
      cout<<"C"<<endl;
    }else if(a+b>=30){
      if(c>=50){
	cout<<"C"<<endl;
      }else{
	cout<<"D"<<endl;
      }
    }else{
      cout<<"F"<<endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 2976
#include<iostream>
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    int v[n];
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=v[i]*v[j];
        }
    }
    cout<<ans<<endl;

    return 0;
}

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

int main() {
    while (1) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0)
            break;

        rep(i, h) {
            rep(j, w) {
                if ((i + j) % 2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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

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

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

const ll MAX = 102000;

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;
	ll h[MAX], dp[MAX];

	for (ll i = 0; i < N; ++i) cin >> h[i];
	for (ll i = 0; i < N; ++i) dp[i] = INF;

	dp[0] = 0;
	for (ll i = 0; i < N; ++i)
	{
		for (ll j = 1; j <= K; ++j)
		{
			chmin(dp[i+j], abs(h[i]-h[i+j])+dp[i]);
		}
	}
	std::cout << dp[N-1] << std::endl;
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int root[1000000];
int depth[1000000];
int n_component;

int find_root(int x){
  int y = root[x];
  if(x == y){
    return x;
  }
  int z = find_root(y);
  root[x] = z;
  return z;
}

void merge(int x,int y){
  int xx = find_root(x);
  int yy = find_root(y);
  if(xx == yy){
    return;
  }
  n_component -= 1;
  if(depth[xx] >= depth[yy]){
    root[yy] = xx;
    depth[xx] += 1;
  } else {
    root[xx] = yy;
    depth[yy] += 1;
  }
  return;
}

int main(){
  int N;
  int M;
  cin >> N >> M;
  n_component = N;
  for(int i=1;i <= N;i++){
    root[i] = i;
  }
  for(int i=0;i<M;i++){
    int x,y,z;
    cin >> x >> y >> z;
    merge(x,y);
  }
  cout << n_component << endl;
}

Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  long long h; cin >> h;

  cout << (ll) (pow(2, 1+floor(log2(h))) - 1) << endl;

  return 0;
}

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

using namespace std;

int main() {

	int D;
	cin >> D;

	vector<int> c(27);
	for (int i = 1; i <= 26; i++) {
		cin >> c[i];
	}

	vector<vector<int>> sd(D + 1, vector<int>(27));

	for (int i = 1; i <= D; i++) {
		for (int j = 1; j <= 26; j++) {
			cin >> sd[i][j];
		}
	}

	vector<int> cont(D + 1);
	for (int i = 1; i <= D; i++) {
		cin >> cont[i];
	}

	mt19937 mt{ std::random_device{}() };

	uniform_int_distribution<int> dist(1, 26);


	int resmax = 0;
	vector<int> maxcont(D + 1);
	vector<int> tmpres(D+1);

	for (int k = 0; k < 1; k++) {

		//vector<int> cont(D + 1);
		vector<int> lastcont(27);
		int tmpress = 0;

		for (int i = 1; i <= D; i++) {

			//cont[i] = dist(mt);

			lastcont[cont[i]] = i;
			tmpress += sd[i][cont[i]];

			for (int j = 1; j <= 26; j++) {
				tmpress -= c[j] * (i - lastcont[j]);
			}
			tmpres[i] = tmpress;
		}

		if (resmax < tmpress) {
			resmax = tmpress;
			maxcont = cont;
		}
	}

	for (int i = 1; i <= D; i++) {
		cout << tmpres[i] << endl;
	}

	return 0;
	
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  vec.at(N-1) /=2;
  int sum =0;
  for(int i = 0;i<N; i++){
    sum += vec.at(i);
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    bool f=false;
    for(int i=1;i<=9;i++){
        if(N%i==0 && N/i<=9) f=true;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000+20
  int c[MAXN]={0};
typedef struct Node{
  int num;
  long long year;
  int t;
  int st;
}city;
bool cmp1(Node s1,Node s2){
  if(s1.num == s2.num){
    return (s1.year<s2.year)?true:false;
  }else{
    return (s1.num<s2.num)?true:false;
  }
}
bool cmp2(Node s1,Node s2){
      return (s1.t<s2.t)?true:false;
}
int fx(int n){
  int rst = 0;
  if(n == 0)
  return 1;
  while(n>0){
    n/=10;
    rst++;
  }
  return rst;
}
city b[MAXN];
int main(){
  int n,m;
  cin>>n>>m;

  for(int i=1;i<=m;i++){
    cin>>b[i].num>>b[i].year;
    b[i].t = i;
  }
  sort(b+1,b+m+1,cmp1);

  for(int i = 1;i<=m;i++){
    b[i].st = c[b[i].num];
    c[b[i].num]++;
  }
  sort(b+1,b+m+1,cmp2);
  for(int i =1;i<=m;i++){
    int x = fx(b[i].num);
    int y = fx(b[i].st+1);
    // cout<<x<<" "<<y<<endl;
    while(x<6){
      cout<<'0';
      x++;
    }
    cout<<b[i].num;
    while(y<6){
      cout<<'0';
      y++;
    }
    cout<<b[i].st+1<<endl;
    // cout<<b[i].num<<" "<<b[i].year<<" "<<b[i].st<<endl;
  }
}


Measured memory_bytes: 4224
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let q: usize = sc.read();
    for _ in 0..q {
        let a: i64 = sc.read();
        let b: i64 = sc.read();
        let (a, b) = if a > b { (b, a) } else { (a, b) };
        if a * b <= a + 1 {
            println!("0");
            continue;
        }

        let mut ok = 1;
        let mut ng = b;
        while ng - ok > 1 {
            let m = (ok + ng) / 2;
            let mut max = cmp::max(a + m, m * (a + 1));
            let x1 = (m + 1 - a) / 2;
            if 1 <= x1 && x1 <= m {
                max = cmp::max((m + 1 - x1) * (a + x1), max);
            }
            let x2 = (m + 1 - a + 1) / 2;
            if 1 <= x2 && x2 <= m {
                max = cmp::max((m + 1 - x2) * (a + x2), max);
            }

            if a * b > max {
                ok = m;
            } else {
                ng = m;
            }
        }
        println!("{}", ok + a - 1);
    }
}

/// A<B
/// (A-i)*(B+i) = AB-iB+iA-i^2<AB
/// 1...m, A+1,...,A+m
/// (A+i)(m+1-i) 1<=i<=m
/// -i2 + (m+1-A)i + A(m+1)
/// -(i - (m+1-A)/2)^2 + (m+1-A)^2/4+A(m+1)<AB
/// (A^2)/4 - (m+1)/2 + (m+1)^2/4 + A(m+1) < AB
/// m+1-A

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: 4352
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  ll n,check=0;
  cin>>n;
  for(ll h=1;h<=3500;h++){
    for(ll b=1;b<=3500;b++){
      if(4*h*b>n*(h+b) && (n*h*b)%(4*h*b-n*(h+b))==0){
        int w=(n*h*b)/(4*h*b-n*(h+b));
        cout<<h<<" "<<b<<" "<<w;
        check=1;
        break;
      }
    }
    if(check==1)break;
  }
}


Measured memory_bytes: 256