akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,r,s,p,ans=0;
    string t;
    queue<int> q;
    cin >> n >> k >> r >> s >> p >> t;
    for(int i=0;i<t.length();i++){
        if(i<k){
            if(t[i]=='r'){
                ans+=p;
                q.push(1);
            }
            else if(t[i]=='s'){
                ans+=r;
                q.push(2);
            }
            else{
                ans+=s;
                q.push(3);
            }
        }
        if(i>=k){
            if(t[i]=='r'){
                if(q.front()==1){
                    ans+=0;
                    q.push(0);
                }
                else{
                    ans+=p;
                    q.push(1);
                }
            }
            else if(t[i]=='s'){
                if(q.front()==2){
                    ans+=0;
                    q.push(0);
                }
                else{
                    ans+=r;
                    q.push(2);
                }
            }
            else{
                if(q.front()==3){
                    ans+=0;
                    q.push(0);
                }
                else{
                    ans+=s;
                    q.push(3);
                }
            }
            q.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <iterator>
#include <algorithm>

typedef long long lint;

using namespace std;

void showIntArray(lint a[], lint n);

int max(int a[], int N) {
  int val = a[0];
  for (int i = 1; i < N; i++) {
    if (val < a[i]) {
      val = a[i];
    }
  }
  return val;
}

int min(int a[], int N) {
  int val = a[0];
  for (int i = 1; i < N; i++) {
    if (val > a[i]) {
      val = a[i];
    }
  }
  return val;
}

int main() {
  int N, M;
  cin >> N >> M;
  int L[100001], R[100001];
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
  }

  int maxL = max(L, M);
  int minR = min(R, M);

  int ans = 0; 
  for (int i = maxL; i <= minR; i++) {
    ans++;
  }

  cout << ans << endl;

  return 0;
}

void showIntArray(lint a[], lint n) {
  for (int i=0; i<n; i++) {
    cout << a[i] << ' ';
  } cout << endl;
}




Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll& a, ll& b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, d; cin >> n >> d;
	d *= 2; d += 1;
	cout << (n + d - 1) / d;
	return 0;
}
/*

*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(ll i = 0; i < (ll) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

vector<ll> loop_path;
vector<ll> used;
ll first_loop_pos = -1;
ll cnt = 0;
void get_loop_path(ll pos, const vector<vector<ll>> &G)
{
    if(used[pos] == 3)
    {
        first_loop_pos = pos;
        return;
    }
    used[pos]++;
    loop_path.push_back(pos);
    for(ll i = 0; i < G[pos].size(); i++)
    {
        ll u = G[pos][i];
        get_loop_path(u, G);
    }
}

void get_dist(ll pos, const vector<vector<ll>> &G)
{
    if(pos == first_loop_pos) return;
    for(ll i = 0; i < G[pos].size(); i++)
    {
        ll u = G[pos][i];
        cnt++;
        get_dist(u, G);
    }
}


void dfs(ll pos, const vector<vector<ll>> &G, ll k)
{
    if(k == 0)
    {
        cout << pos + 1 << endl;
        return;
    }
    for(ll i = 0; i < G[pos].size(); i++)
    {
        ll u = G[pos][i];
        dfs(u, G, k - 1);
    }
}

void solve()
{
    ll n, k; cin >> n >> k;
    vector<vector<ll>> G(n);
    for(ll i = 0; i < n; i++)
    {
        ll a; cin >> a;
        a--;
        G[i].push_back(a);
    }

    if(k <= 1e7)
    {
        dfs(0, G, k);
        return;
    }

    used.resize(n, 0);
    get_loop_path(0, G);

    vector<ll> target_path;
    for(ll i = 0; i < loop_path.size(); i++)
    {
        if(used[loop_path[i]] >= 2)
        {
            target_path.push_back(loop_path[i]);
        }
    }

    get_dist(0, G);
    k -= cnt;
    k %= (ll)target_path.size();
    dfs(first_loop_pos, G, k);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 43096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  ll mod = 1e9 + 7;

  for(int i = k; i <= n+1; i++) {
    ans += -pow(i, 2) + (n+1)*i + 1;
  }

  cout << ans % mod << endl;

  return 0;
}

Measured memory_bytes: 3580
package main

import "fmt"

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scanln(&n)
	b := make([]int, n-1)
	for i := 0; i < n-1; i++ {
		fmt.Scan(&b[i])
	}
	ans := b[0] + b[n-2]
	for i, j := 0, 1; j < n-1; {
		ans += min(b[i], b[j])
		i++
		j++
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
//#include "combo.h"
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define pii pair<int,int>

const int maxn=2e3+10;
int n,X,Y;
int ret[maxn],dist[maxn][maxn];

main()
{
    cin>>n>>X>>Y;
    forinc(i,1,n) forinc(j,1,n) dist[i][j]=INT_MAX;
    forinc(i,1,n) dist[i][i]=0;
    forinc(i,1,n-1) forinc(j,i+1,n) dist[i][j]=dist[i][j-1]+1;
    forinc(i,1,n-1) forinc(j,i+1,n)
    {
        if(X>=i&&Y<=j) dist[i][j]=min(dist[i][j],X-i+j-Y+1);
        else if(X>=i&&X<=j&&Y>=j) dist[i][j]=min(dist[i][j],X-i+1+Y-j);
        else if(Y>=i&&Y<=j&&X<=i) dist[i][j]=min(dist[i][j],i-X+1+j-Y);
        else if(X<=i&&j<=Y) dist[i][j]=min(dist[i][j],i-X+1+Y-j);
        dist[i][j]=min(dist[i][j],dist[i][j-1]+1);
    }
    //cout<<dist[2][6]<<" ";
    forinc(i,1,n-1) forinc(j,i+1,n){
            ret[dist[i][j]]++;
//cout<<dist[i][j]<<" ";
    }
    forinc(i,1,n-1) cout<<ret[i]<<"\n";
}

	 	

Measured memory_bytes: 31616
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m,x;
    int A = 0, B= 0;
    cin >> n >> m >> x;
    int *r = new int[m];
    for(int i = 0;i < m;i++){
        cin >> r[i]; 
    }
    for(int i = x;i > 0;i--){
        for(int j = 0;j < m;j++){
            if(r[j] == i){
                A++;
            }
        }
    }
    for(int i = x;i < n;i++){
        for(int j = 0;j < m;j++){
            if(r[j] == i){
                B++;
            }
        }
    }
    if(A < B){
        cout << A;
    }else{
        cout << B;
    }
    return 0;
}

Measured memory_bytes: 256
temp=list(map(int,input().rstrip().split()))
a=temp[0]
b=temp[1]
c=temp[2]
d=temp[3]
while True :
    c=c-b
    if c<=0 :
        print("Yes")
        break
    else :
        a=a-d
        if a<=0 :
            print("No")
            break

Measured memory_bytes: 9144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int m, nmin, nmax;
int p[10000];

int main(){
	while (cin >> m >> nmin >> nmax&&m + nmin&&nmax){
		int gap = -1, ans;
		REP(i, m)cin >> p[i];
		sort(p, p + m, greater<int>());
		for (int i = nmin; i <= nmax; i++){
			if (gap <= p[i - 1] - p[i]){
				gap = p[i - 1] - p[i];
				ans = i;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
import itertools
import sys
input = sys.stdin.readline
def inputs():
    return [int(x) for x in input().split()]
H,W = inputs()
c = [inputs() for _ in range(10)]
HW = [inputs() for _ in range(H)]
A = (0,9,8,7,6,5,4,3,2)
B = list(itertools.permutations(A))
N = [c[i][1] for i in range(10)]
for i in B:
    a = i[0]
    ans = 0
    for j in range(1,9):
        ans +=c[i[j-1]][i[j]]
        if N[a]<=ans:
          break
        N[a] = min(ans+c[i[j]][1],N[a])    
ans = 0
for i in range(H):
    for j in range(W):
        if HW[i][j]!=-1:
            ans += N[HW[i][j]]
print(ans)

Measured memory_bytes: 50292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll GCD(ll m,ll n){
	ll remain;
	if((remain = m % n) == 0)return n;
	else return GCD(n,remain);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	REP(i,n) cin >> a[i];
	ll l[n];
	l[0] = a[0];
	for(int i = 1; i < n; i++) l[i] = GCD(l[i - 1], a[i]);
	ll r[n];
	r[n - 1] = a[n - 1];
	for(int i = n - 2; i >= 0; i--) r[i] = GCD(r[i + 1], a[i]);
	ll ans = r[1];
	for(int i = 1; i < n - 1; i++) ans = max(ans, GCD(l[i - 1], r[i + 1]));
	ans = max(ans, l[n - 2]);
	cout << ans << endl;
}

Measured memory_bytes: 2560
var GET = (function () {function f(s) {return new g(s);}function g(s) {this._s = s.trim().split("\n");}g.prototype.getValue = function (n) {return this._s[n];};g.prototype.getArray = function (n) {return this.stoa(this._s[n]);};g.prototype.slice = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));};g.prototype.sliceArray = function (s, limit) {return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));};g.prototype.stoa = function (s) {return s.split(" ").map(v => this.stox(v));};g.prototype.stox = function (v) {var i = +v;return (i === i) ? i : v;};return f;})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = o.getValue(0);
    var S = o.getValue(1);

    var merged = S.split("").reduce((a, c) => {
        if (a[a.length - 1] === c) {
            return a;
        }

        return a + c;
    }, "")

    return merged.length
}

Measured memory_bytes: 39628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

string s,t; cin >> s >> t;
int n = SZ(s);

vvi fi(26, vi(26));
rep(i,n) {
    int a = s[i] - 'a';
    int b = t[i] - 'a';
    fi[a][b] = 1;
}

rep(i,26) {
    int cnt = 0;
    rep(j,26) if (fi[i][j]) cnt++;
    if (2 <= cnt) {
        cout << "No" << endl;
        return 0;
    }
}
rep(j,26) {
    int cnt = 0;
    rep(i,26) if (fi[i][j]) cnt++;
    if (2 <= cnt) {
            cout << "No" << endl;
            return 0;
    }
}
cout << "Yes" << endl;
return 0;
}

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

using namespace std;
#define int long long
 main(){
    int n;
    cin >> n;
    long long a[n + 23];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
     int curr = a[1], ans = 0, sz = 1, i;
     queue<int> q;
     q.push(a[1]);
     for (i = 2; i <= n; i++) {
        if (a[i] == curr) {
            q.push(a[i]);
            sz++;
            ans += a[i];
        }
        else {
            break;
        }
     }

     while(i <= n) {
        int x = q.front();
        q.pop();
        ans += x;
        q.push(a[i]);
        q.push(a[i]);
        i++;
     }
    cout << ans;
}


Measured memory_bytes: 6676
from collections import deque
n,q = map(int,input().split())

stack = deque([[] for i in range(n)])

for i in range(q):
    query = [k for k in map(int,input().split())]

    if query[0] == 0:
        stack[query[1]].append(query[2])
    elif query[0] == 1:
        try:
            print(stack[query[1]][0])
        except:
            pass
    elif query[0] == 2:
        try:
            stack[query[1]].pop(0)
        except:
            pass



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

int main(void) {
  int N, k;
  cin >> N >> k;
  vector<int> a(N);
  int minid = -1;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] == 1) minid = i;
  }
  if (N == k) {
    cout << 1 << endl;
    return 0;
  }
  int rightstart = minid;
  int ret = 1e9;
  // if (minid < k && minid != 0) {
  //   rightstart = k - 1;
  // }
  // if (minid != 0) {
  //   ret += (minid - 1) / (k - 1) + 1; 
  // }
  // if (rightstart != N-1) {
  //   rightstart = N - 1 - rightstart;
  //   ret += (rightstart - 1) / (k - 1) + 1;
  // }
  // cout << ret << endl;

  // int ret = 0;
  for (int i = minid-k+1; i <= minid+k-1; i++) {
    if (i < 0 || i+k-1 > N-1) continue;
    int cnt = 1;
    int leftstart = i;
    int rightstart = i + k -1;
    if (leftstart != 0) {
      cnt += (leftstart - 1) / (k - 1) + 1; 
    }
    if (rightstart != N-1) {
      rightstart = N - 1 - rightstart;
      cnt += (rightstart - 1) / (k - 1) + 1;
    }
    ret = min(ret, cnt);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, x;
int a[100001], ans ;
int main() {
    cin.tie(0); ios::sync_with_stdio(false);
	cin >> n >> x;
	a[n] = x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a+n+1);
	for (int i = 1; i <= n; i++) {
		ans = __gcd(a[i]-a[i-1], ans);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e9
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, D, L, R, K, X, A, B, C, Z;
ll ans;
string S;
ll a[100000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
int main() {
	ll x;
	cin >> N >> x;
	rep(i, 0, N) {
		cin >> a[i];
	}
	sort(a, a + N);
	rep(i, 0, N) {
		x -= a[i];
		if (x < 0) {
			cout << i << endl;
			cin >> ans;
			return 0;
		}
	}
	if(x==0)cout << N << endl;
	else cout << N - 1 << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
def main():
    #input data
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    S = input()
    
    #solve
    all_black = S.count('#')
    fill_one = min(N-all_black,all_black)
    b_cnt = 0

    ans = 10**10
    for i in range(N-1):
        if S[i]=='#':
            b_cnt+=1
        else:
            pass
        tmp = b_cnt+((N-i-1)-(all_black-b_cnt))
        ans = min(tmp,ans)
        # print(i,ans)

    print(min(ans,fill_one))

if __name__=='__main__':
    main()




Measured memory_bytes: 9480
# -*- coding:utf-8 -*-
import collections
n = int(input())
command = [input().split() for i in range(n)]
ans = collections.deque()

for i in range(n):
    if command[i][0] == "insert":
        ans.appendleft(command[i][1])
    elif ans == []:
        continue
    elif command[i][0] == "delete":
        try:
            ans.remove(command[i][1])
        except:
            continue
    elif command[i][0] == "deleteFirst":
        ans.popleft()
    else:
        ans.pop()

print (' '.join(ans))

Measured memory_bytes: 557100
while (m, f, r = gets.split.map(&:to_i)) != [-1, -1, -1] do
	if m == -1 || f == -1 then
		puts 'F'
	else
		sum = m + f

		if sum >= 80 then
			puts 'A'
		elsif sum < 80 && sum >= 65 then
			puts 'B'
		elsif sum < 65 && sum >= 50 then
			puts 'C'
		elsif sum < 50 && sum >= 30 then
			if r >= 50 then
				puts 'C'
			else
				puts 'D'
			end
		else
			puts 'F'
		end
	end
end

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

#define rep(i,m,n) for(ll i=m;i<n;i++)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
 ll p,q,m;
  cin >> p >> q >> m;
  
 ll res=0; 
 vll a(p),b(q);
  rep(i,0,p) cin >> a[i];
  rep(i,0,q) cin >> b[i];
  res=*min_element(a.begin(), a.end())+*min_element(b.begin(), b.end());
 
  rep(i,0,m) {
    ll x,y,c;
    cin >> x >> y >> c;
    x--;
    y--;
    res=min(res,a[x]+b[y]-c);

  }
cout << res << endl;  
}

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

using namespace std;

int main() {

	double a, b, c;
	cin >> a >> b >> c;
	c = c / 180 * 3.14159265354;
	cout << fixed << setprecision(9) << b * a*sin(c) / 2 << endl;;
	cout << fixed << setprecision(9) << a + b + sqrt(a*a + b * b - 2 * a*b*cos(c)) << endl;;
	cout << fixed << setprecision(9) << b * sin(c) << endl;;

}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
const double EPS = 1e-8, INF = 1e12, PI = 2 * acos(0.0);
typedef complex<double> P;
namespace std {
    bool operator < (const P& a, const P& b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } 
    bool operator == (const P& a, const P& b) { return abs(real(a) - real(b)) < EPS && abs(imag(a) - imag(b)) < EPS; }
    P operator / (const P& a, const double& b) { return P(real(a) / b, imag(a) / b); }
    P operator * (const P& a, const double& b) { return P(real(a) * b, imag(a) * b); }
}
double argument(const P &a, const P &b) { // argument for A->B[-PI,PI]
    double ax = real(a), ay = imag(a), bx = real(b), by = imag(b);
    return atan2(by - ay, bx - ax);
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N;
//---------------------------------------------------------------------------------------------------
void _main()
{
    cin >> N;
    vector<P> v;
    rep(i, 0, N)
    {
        int x, y;
        cin >> x >> y;
        if(x != 0 or y != 0) {
            v.push_back(P(x, y));
        }
    }

    sort(all(v), [&](P a, P b) { return argument(P(0, 0), a) < argument(P(0, 0), b); });

    double ans = 0;
    int n = v.size();
    rep(i, 0, n) {
        double x = 0, y = 0;
        rep(j, 0, n) {
            auto p = v[(i + j) % n];
            x += real(p);
            y += imag(p);

            chmax(ans, sqrt(x * x + y * y));
        }
    }
    printf("%.10f\n", ans);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi           first
#define se           second
#define ll           long long
#define pb           push_back
#define mp           make_pair
#define pll          pair<ll,ll>
#define pii          pair<int,int>
#define all(x)       (x).begin(),(x).end()
#define isWorking()  cout<<"Wroking"<<endl
#define FOR(i,x,y)   for(int i=x; i<y; i++)
#define SORT(x)      sort(x.begin(),x.end())
#define PRINT(ok)    cout<<(ok? "YES":"NO")<<endl
#define Fast_Input   ios_base :: sync_with_stdio(false), cin.tie(NULL);
typedef vector < int > VI;
const ll mod= 1e9+7,INF=1e18,mx= 5e6+5,mn=100;
int testCase=1,cas=0;

int main() {
    Fast_Input

    //cin>>testCase;
    while(testCase--){

        ll n;
        cin>>n;
        ll cnt=1, sum=0;
        while(n>0){
            sum+=cnt;
            n/=2;
            cnt*=2;
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[101010],ans,r[101010],l[101010];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	r[0]=a[0];
	l[0]=a[n-1];
	for(int i=0;i<n;i++)
	{
		r[i+1]=__gcd(r[i],a[i]);
		l[i+1]=__gcd(l[i],a[n-i-1]);
	}
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			ans=max(ans,__gcd(a[1],l[n-i-1]));
		}
		else if(i==n-1)
		{
			ans=max(ans,__gcd(a[0],r[n-1]));
		}
		else
		{
			ans=max(ans,__gcd(r[i],l[n-i-1]));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <utility>
using namespace std;
 
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
#define rfor(i, a, b) for(int i = a - 1; i >= b; i--)
 
ll n,m;
double prob[3010];
double dp[3010][3010];
 
void solve(){
    double res = 0.0;
    dp[0][0] = 1.0;
    fore(i,1,n+1)dp[i][0] = prob[i-1]*dp[i-1][0];
    fore(i,1,n+1)dp[0][i] = (1.0-prob[i-1])*dp[0][i-1];
    fore(i,1,n+1){
        fore(j,1,n+1){
            if(i+ j <= n)dp[i][j] = prob[j+i-1]*dp[i-1][j] + (1.0-prob[j+i-1])*dp[i][j-1];
            else break;
        }
    }
    for(int i = 0 ; i <= n; i++){
        for(int j = 0; j < i; j++){
            if(i+j == n){
                res += dp[i][j];
            }
        }
    }
    cout<<setprecision(20)<<res<<endl;
}
 
int main(){
    cin>>n;
    fore(i,0,n)cin>>prob[i];
    solve();
    return 0;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  vector<int> A(N + 2);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector<int> L(N + 2), R(N + 2);
  for (int i = 0; i < N; i++) {
    L[i + 1] = abs(A[i + 1] - A[i]);
  }
  for (int i = N; i >= 0; i--) {
    R[i] = abs(A[i + 1] - A[i]);
  }
  for (int i = 0; i < N + 1; i++) {
    L[i + 1] += L[i];
  }
  for (int i = N + 1; i > 0; i--) {
    R[i - 1] += R[i];
  }
  // for (int i = 0; i < N + 2; i++) {
  //   cout << L[i] << " " << R[i] << endl;
  // }
  for (int i = 1; i <= N; i++) {
    cout << L[i - 1] + abs(A[i - 1] - A[i + 1]) + R[i + 1] << endl;
  }

  return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll x, y, z;
    cin >> x >> y >> z;
    ll ans = (x-z)/(y+z);
    cout << ans;
}

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

int main(){
    int n,h, w; cin>>n>>h>>w;
    int ans=0;
    for(int i=0; i<n; i++){
        int a,b; cin >> a >>b;
        if(a>=h&&b>=w) ans ++;
    }
    cout << ans << endl;
}

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

int main() {
	int N, K;
	scanf("%d%d",&N,&K);
	for (int i = 1;;i++) {
		if (N/K<K&&N/K==0) {
			printf("%d",i);
			break;
		}
		else if(N / K < K && N / K != 0){
			printf("%d", i+1);
			break;
		}
		else {
			N = N / K;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
int main(){
	int n,a[200002];
	cin >> n;
	int f=n/2,b=n/2+1;
	FOR(i,0,n){
		if((n-i)%2 == 0) cin >> a[b++];
		else cin >> a[f--];
	}
	FOR(i,f+1,b) cout << a[i] << " ";
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>

int main()
{
  int dices[101];
  int n, i, max, count;

  scanf("%d", &n);
  for (i = 0; i < n; i++)
  {
    scanf("%d", &dices[i]);
  }
  dices[n] = 0;

  max = 0;
  count = 0;

  for (i = 0; i <= n; i++)
  {
    if (dices[i] == 0)
    {
      if (max < count)
      {
        max = count;
      }
      count = 0;
    }
    else
    {
      count++;
    }
  }

  printf("%d\n", max + 1);


  return 0;
}


Measured memory_bytes: 2136
import collections


def main():
    cnt = 0
    R, G, B, N = list(map(int, input().split()))
    for r in range(N // R + 1):
        for g in range((N - r * R)//G + 1):
            k = N - r * R - g * G
            if k % B == 0:
                cnt += 1
    print(cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9404
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli n,k,i,sum;
   cin>>n>>k;
   lli p[n+1];
   for(i=0;i<n;i++)
   {
     cin>>p[i];
   }
   sort(p,p+n);
   sum=0;
   for(i=0;i<k;i++)
   {   //debug(p[i]);
       sum+=p[i];
   }
   cout<<sum<<"\n";
   return 0;
}//main


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

int main(){
  ll N;
  cin >> N;
  
  ll num = pow(N, 0.5);
  
  while (N % num != 0){
    num--;
  }
  
  num = N / num;
  
  int ans = 1;
  while (num < pow(10, ans - 1) || num >= pow(10, ans)){
    ans++;
  }
  
  cout << ans << endl;
}

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

#define int long long int 

int32_t main()
{
    string str;
    int k;
    cin>>str>>k;
    for(int i=0;i<min((long long)str.size(),k);i++)
    {
        if(str[i]>='2'){cout<<str[i]<<endl;
        return 0;}
    }
    cout<<"1"<<endl;
}


Measured memory_bytes: 3584
n, k=map(int, input().split())
l=[]
for i in range(n):
  l.append(int(input()))
l=sorted(l)
#print(l)
ans=l[len(l)-1]
for i in range(0, n-k+1):
  ans=min(ans, l[i+k-1]-l[i])
  #print(ans)
print(ans)

Measured memory_bytes: 14176
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;
  cin >> n;
  vi v(n);

  rep(i,n) cin >> v[i];

  vsort(v);

  int sum = 0;
  rep(i,n-1) sum += v[i];

  sum += v[n - 1] / 2;

  cout << sum << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sl(a) scanf("%lld", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define debug(a) cout << a << endl
#define pr(a) printf("%d ",a)
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define ull unsigned long long
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf=0x3f3f3f3f;
const int MAXN = 1e5+10;
const int mode=1e9+7;
int N,k;
int a[105];
bool dp[MAXN][2];
bool vis[MAXN][2];
int dfs(int K,int p)
{
	if(vis[K][p])return dp[K][p];
	bool ans=0;
	for(int i=1;i<=N;++i)
	{
		if(K>=a[i])
		ans|=!dfs(K-a[i],!p);
	}
	vis[K][p]=1;
	return dp[K][p]=ans;
}
int main()
{
	IO;
	cin>>N>>k;
	for(int i=1;i<=N;++i)
	{
		cin>>a[i];
	}
	if(dfs(k,0)==0)puts("Second");
	else puts("First");
 } 


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> t(100001);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    t.at(a.at(i))++;
  }
  
  int k=0,cnt =0;
  for(int i=0;i<100001;i++){
    if(t.at(i) >= 3){
      if(t.at(i)%2 == 0) t.at(i) = 2;
      else t.at(i) = 1;
    }
    
    if(t.at(i) == 2) k++;
    
    if(t.at(i) <= 2 && t.at(i) > 0) cnt++;
  }
  
  if(k%2 == 1) cnt--;
  
  cout << cnt << endl;  
  
  return 0;
}


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

struct data{
    int h, t, i;
    bool operator<(const data other) const{
        if(t != other.t)    return t < other.t;
        else                return h < other.h;
    }
};

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        int h[n], t[n];
        for(int i = 0; i < n; i++)  cin >> h[i];
        t[0] = m/h[0]*h[0];
        priority_queue<data> pq;
        pq.push(data({h[0], t[0], 0}));
        for(int i = 1; i < n; i++){
            int upper = pq.top().t;
            int want = (upper + h[i] - 1)*h[i];
            if(want > m){
                want = m/h[i]*h[i];
            }else if(want == upper && pq.top().h == h[i]){
                want += h[i];
                if(want > m)    want -= h[i];
            }
            t[i] = want;
            pq.push(data({h[i], t[i], i}));
        }
        vector<data> v;
        while(!pq.empty())  v.push_back(pq.top()), pq.pop();

        data d = v[n-1];
        data e = v[n-2];

        if(d.t == e.t){
            if(d.h == e.h)  cout << n << endl;
            else            cout << d.i+1 << endl;
        }else{
            cout << d.i+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3096
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 2;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, k;
  cin >> n >> k;
  if (n > k)
  {
    ll m = n / k;
    n -= m * k;
  };

  ll Min = LINF;
  rep(i, 10)
  {
    Min = min(Min, n);
    n = abs(n - k);
  }
  cout << Min << endl;
  return 0;
}


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

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

inline void Main() {
  string s, t; cin >> s >> t;
  int result = 0;
  rep(i, s.length()) {
    if (s[i] != t[i]) result++;
  }
  cout << result << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3812
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

bool used[85][85][7000];
int t[85][85][2];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	for(i=0;i<2;i++){
		for(j=0;j<n;j++){
			for(k=0;k<m;k++){
				cin>>t[j][k][i];
			}
		}
	}
	used[0][0][0]=true;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			a=t[i][j][0]-t[i][j][1];
			a=abs(a);
			for(k=0;k<7000;k++){
				if(!used[i][j][k])continue;
				if(k+a<7000)used[i][j+1][k+a]=true,used[i+1][j][k+a]=true;
				b=k-a;
				if(b<0)b=-b;
				used[i][j+1][b]=true,used[i+1][j][b]=true;
			}
		}
	}
	for(i=0;i<7000;i++){
		if(used[n][m-1][i] || used[n-1][m][i])break;
	}
	cout<<i<<endl;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int i = 0;
    while (i < N){
        string S;
        cin >> S;
        if (S == "Y"){
            cout << "Four" << endl;
            break;
        }
        i++;
        if (i == N){
            cout << "Three" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

int main()
{	
	std::set<int> S;
	
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int op, x, L, R;
		std::cin >> op;
		if (op==0) {
			std::cin >> x;
			S.insert(x);
			std::cout << S.size() << std::endl;
		}
		else if (op==1) {
			std::cin >> x;
			if (S.find(x) != S.end()) std::cout << 1 << std::endl;
			else std::cout << 0 << std::endl;
		}
		else if (op==2) {
			std::cin >> x;
			S.erase(x);
		}
		else {
			std::cin >> L >> R;
			std::set<int>::iterator lb = S.lower_bound(L);
			std::set<int>::iterator ub = S.upper_bound(R);
			for (std::set<int>::iterator it = lb; it != ub; ++it) std::cout << *it << std::endl;
		}
	}
	
	return 0;
}



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

int main(){
	int N;
  	cin>>N;
  	int D,X;
  	cin>>D>>X;
  	int a[100],count=0;
	for(int i=0;i<N;++i)cin>>a[i];
  	for(int i=0;i<N;++i){
    	for(int j=1;j<=D;j+=a[i])++count;
    }
  	cout<<count+X<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
    int N,A,B;
    int count=0;
    scanf("%d %d %d",&N,&A,&B);
    for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
    for (int k = 0; k < 10; k++){
    for (int l = 0; l < 10; l++){
        if(i+k+j+l>=A && i+j+k+l<=B &&i*1000+j*100+k*10+l <=N) count += i*1000+j*100+k*10+l;
    }
    }            
    }
    }
    if(N==10000 && A==1) count += N;
    printf("%d",count);    
}

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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

vector<int> a;

int main(){
	ios::sync_with_stdio(0);
	int N;
	cin >> N;
	int numUnique = 0;
	int minA = 1000000;
	int maxA = 0;
	a.resize(N);
	rep(i,0,N){
		cin >> a[i];
		minA = min(minA, a[i]);
		maxA = max(maxA, a[i]);
	}
	if(minA == maxA){
		if(minA == N-1){
			cout << "Yes" << endl;
			return 0;
		}
		if(2*minA <= N){
			cout << "Yes" << endl;
			return 0;
		}
		cout << "No" << endl;
		return 0;
	}
	if(minA < maxA-1){
		cout << "No" << endl;
		return 0;
	}
	rep(i,0,N){
		if(a[i] == minA)
			++numUnique;
	}
	if(numUnique+1 > maxA){
		cout << "No" << endl;
		return 0;
	}
	if(numUnique+(N-numUnique)/2 < maxA){
		cout << "No" << endl;
		return 0;
	}
	if(N-numUnique < 2){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 640
A,B = map(int,input().split())
dif = B-A+1
MAX = 45
ans = 0
for i in range(1,MAX):
  base = pow(2,i)
  if (B+1)%base <= base//2:
    up = ((B+1)//base)*(base//2)
  else:
    up = ((B+1)//base)*(base//2) + (B+1)%base - base//2
  if A%base <= base//2:
    down = (A//base)*(base//2)
  else:
    down = (A//base)*(base//2) + A%base - base//2
  ans += (up-down)%2*(base//2)
print(ans)


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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, H[16], W[16];
  string S[4];
  const string temp = "RGB";
  int bit[16][8][8][3] = {{{{}}}};
  int change[16][8][8][3] = {{{{}}}};
  int v[1 << 16];
  fill_n(v, 1 << 16, INF);
  queue< int > que;

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> H[i] >> W[i];
  }
  for(int i = 0; i < 4; i++) {
    cin >> S[i];
    for(int j = 0; j < 4; j++) {
      S[i][j] = temp.find(S[i][j]);
    }
  }

  for(int k = 0; k < N; k++) {
    for(int i = -3; i < 4; i++) {
      for(int j = -3; j < 4; j++) {
        for(int z = 0; z < 3; z++) {
          auto &tugi = bit[k][i + 3][j + 3][z];
          auto &kaee = change[k][i + 3][j + 3][z];
          for(int l = 0; l < H[k]; l++) {
            if(i + l < 0 || i + l >= 4) continue;
            for(int n = 0; n < W[k]; n++) {
              if(j + n < 0 || j + n >= 4) continue;
              int y = i + l, x = j + n;
              tugi |= (S[y][x] == z) << (y * 4 + x);
              kaee |= 1 << (y * 4 + x);
            }
          }
        }
      }
    }
  }

  que.emplace(0);
  v[0] = 0;
  while(!que.empty()) {
    int p = que.front();
    que.pop();
    if(p == (1 << 16) - 1) {
      cout << v[p] << endl;
      break;
    }
    for(int k = 0; k < N; k++) {
      for(int i = 0; i < 8; i++) {
        for(int j = 0; j < 8; j++) {
          for(int z = 0; z < 3; z++) {
            if(bit[k][i][j][z] == 0) continue;
            int s = p & ~change[k][i][j][z] | bit[k][i][j][z];
            if(v[s] > v[p] + 1) {
              v[s] = v[p] + 1;
              que.emplace(s);
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

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

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);
int asc(const void *a, const void *b);
int desc(const void *a, const void *b);
double to_deg(double rad);
double distance(int xi, int yi, int xj, int yj);

//main function
int main() {
    int x = iin(), i, j, y;
    for (i = x; i < 100004; i += 2) {
        if (i == 2) {
            iout(i);
            return 0;
        }
        if (i % 2 == 0) i++;
        y = 0;
        for (j = 3; j <= sqrt(i); j += 2) {
            if(i % j == 0) {
                y++;
                break;
            }
        }
        if (y == 0) {
            iout(i);
            return 0;
        }
    }
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

/*
    int型の最大公約数
*/

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    int型の最小公倍数
*/

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    long long型の最大公約数
*/

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

/*
    long long型の最小公倍数
*/

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}

/*
    int型の昇順用比較関数
*/

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

/*
    int型の降順用比較関数
*/

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

/*
    弧度法を度数法に
*/

double to_deg(double rad) {
    return rad * 180.0 / (atan(1.0) * 4.0);
}

double distance(int xi, int yi, int xj, int yj) {
    return hypot(xj - xi, yj - yi);
}


Measured memory_bytes: 128
def plus(x):
    X = str(x)
    p = int(X[len(X)-1])
    if p == 0:
        return(int(X+str(p)), int(X+str(p+1)))
    elif p == 9:
        return(int(X+str(p-1)), int(X+str(p)))
    else:
        return(int(X+str(p-1)), int(X+str(p)), int(X+str(p+1)))
    
A,B,C,D,E,F,G,H,I,J=[],[],[],[],[],[],[],[],[],[]
for i in range(1,10):
    A.append(i)
for i in A:
    B.extend(plus(i))
for i in B:
    C.extend(plus(i))
for i in C:
    D.extend(plus(i))    
for i in D:
    E.extend(plus(i))    
for i in E:
    F.extend(plus(i))
for i in F:
    G.extend(plus(i))
for i in G:
    H.extend(plus(i))
for i in H:
    I.extend(plus(i))
for i in I:
    J.extend(plus(i))

ans = A+B+C+D+E+F+G+H+I+J
print(ans[int(input())-1])

Measured memory_bytes: 13096
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;

typedef pair<int,int> pii;

#define INF 1000000000

int h, w, s;
int u[34][34];
int sum[34][34];
pii memo[34][34][34][34];

pii recur(int low, int high, int left, int right){
	if(memo[low][high][left][right].first == -1){
		int need = sum[high][right] + sum[low-1][left-1] - sum[low-1][right] - sum[high][left-1];
		pii r(1, s - (sum[h][w] - need));
		if(r.second < 0){
			r = pii(-INF, -INF);
		}
		else{
			for(int i = low; i < high; ++i){
				pii p1 = recur(low, i, left, right);
				pii p2 = recur(i + 1, high, left, right);
				pii q(p1.first + p2.first, min(p1.second, p2.second));
				r = max(r, q);
			}
			
			for(int i = left; i < right; ++i){
				pii p1 = recur(low, high, left, i);
				pii p2 = recur(low, high, i + 1, right);
				pii q(p1.first + p2.first, min(p1.second, p2.second));
				r = max(r, q);
			}
		}
		memo[low][high][left][right] = r;
	}
	return memo[low][high][left][right];
}

int main(){
	while(scanf("%d%d%d", &h, &w, &s), h){
		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			scanf("%d", &u[i][j]);
		}

		for(int i = 1; i <= h; ++i)
		for(int j = 1; j <= w; ++j){
			sum[i][j] = sum[i][j-1] + u[i][j];
		}
		
		for(int j = 1; j <= w; ++j)
		for(int i = 1; i <= h; ++i){
			sum[i][j] += sum[i-1][j];
		}

		for(int i = 0; i < 34; ++i)
		for(int j = 0; j < 34; ++j)
		for(int k = 0; k < 34; ++k)
		for(int l = 0; l < 34; ++l){
			memo[i][j][k][l] = pii(-1, -1);
		}

		pii ans = recur(1, h, 1, w);
		printf("%d %d\n", ans.first, ans.second);
	}
}

Measured memory_bytes: 11484
#include <bits/stdc++.h>
using namespace std;
int main(){
  map<string,vector<int> >A;
  string s;
  int n;
  while(cin>>s>>n){
    A[s].push_back(n);
  }
  map<string,vector<int> >::iterator t=A.begin();
  while(t!=A.end()){
    cout<<t->first<<endl;
    sort(t->second.begin(),t->second.end());
    for(int i=0;i<t->second.size();i++){
      if(i)cout<<' '<<t->second[i];
      else cout<<t->second[i];
    }
    cout<<endl;t++;
  }
}

Measured memory_bytes: 3156