akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i64 n, A = 0, B = 0; cin >> n;
    vi a(n), b(n), diff_less, diff_bigger;
    rep(i,n) {
        cin >> a[i];
        A += a[i];
    }
    rep(i,n) {
        cin >> b[i];
        B += b[i];
    }

    /**
     * たりないやつ( a < b )を考える。
     * ここは別のところから補充しないといけない
     * たりないやつについてb-aを保持
     * たりてるやつ( a >= b )から引いてく。
     * このとき一番a-bがでかいやつからとってくるのが最適
     */

    if(A - B < 0) {
        cout << -1 << '\n';
        return 0;
    }

    rep(i,n) {
        if(a[i] - b[i] < 0) diff_less.push_back(b[i] - a[i]);
        else diff_bigger.push_back(a[i] - b[i]);
    }
    sort(all(diff_bigger));
    reverse(all(diff_bigger));

    i64 ans = diff_less.size();
    i64 sum = 0;
    for(auto val : diff_less) sum += val;

    for(i32 i = 0; i < diff_bigger.size() && sum > 0; ++i) {
        sum -= diff_bigger[i];
        ++ans;
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second

bool dp[100005];
void solve(){
	
	int n,k;
	cin>>n>>k;
	int arr[n];
	rep(i,0,n)
		cin>>arr[i];
	dp[0] = false;

	rep(i,1,k+1){
		rep(j,0,n){
			if(arr[j]<=i && !dp[i-arr[j]])
				dp[i]=true;
		}
	}
	if(dp[k]){
		cout<<"First"<<endl;
	}
	else
		cout<<"Second"<<endl;
}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

const int N = 3e3 + 5;
double dp[N][N], p[N];

void solve(int test) {
	int n; cin >> n ;
	rep(i,1,n+1) cin >> p[i] ;

	dp[0][0] = 1.0 ; 

	rep(i,1,n+1) {
		dp[0][i] = (1 - p[i]) * dp[0][i-1] ;
		rep(j,1,n+1) {
			dp[j][i] = p[i] * (dp[j-1][i-1]) + (1.0 - p[i]) * (dp[j][i-1]) ;
		}
	}

	double ans = 0 ;

	for(int i = (n+1)/2 ; i <= n ; ++i ) ans += dp[i][n] ;

	cout << fixed << setprecision(10) << ans ; 
}
 
int32_t main() {


    fast;
	int t=1;
	// cin>>t;
	rep(i,1,t+1) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 74184
/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
# define err(x) cerr << #x << " ::   " << x << endl;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[30];
priority_queue<int> s;
int main(){
	ios_base::sync_with_stdio (0);
	int n,m;cin>>n>>m;
	for(int i=0 ; i<n ; i++)
		for(int j=0 ; j<m ; j++){
			char ch;cin>>ch;
			a[ch-'a']++;
		}
	for(int i=0 ; i<26 ; i++)
		s.push(a[i]);

	for(int i=1 ; i<=n/2 ; i++)
		for(int j=1 ; j<=m/2 ; j++){
			int tmp = s.top();
			s.pop();
			if(tmp < 4){
				cout<<"No\n";
				return 0;
			}
			else{
				tmp -= 4;
				s.push(tmp);
			}
		}
	if(n%2){
		for(int j=1 ; j<=m/2 ; j++){
			int tmp = s.top();
			s.pop();
			if(tmp < 2){
				cout<<"No\n";
				return 0;
			}
			else{
				tmp -= 2;
				s.push(tmp);
			}	
		}
	}
	if(m%2){
		for(int j=1 ; j<=n/2 ; j++){
			int tmp = s.top();
			s.pop();
			if(tmp < 2){
				cout<<"No\n";
				return 0;
			}
			else{
				tmp -= 2;
				s.push(tmp);
			}	
		}
	}
	if(n%2 && m%2){
		int tmp = s.top();
		s.pop();
			if(tmp < 1){
				cout<<"No4\n";
				return 0;
			}
			else{
				tmp -= 1;
				s.push(tmp);
			}
	}
	if(s.top() != 0){
		cout<<"No\n";
	}
	else
		cout<<"Yes\n";
	return 0;
}



Measured memory_bytes: 256
from collections import Counter
import math

s = input()
dic = Counter(s)

n_odd = 0
for c in dic:
    if dic[c] & 1:
        n_odd += 1
        if n_odd > 1:
            print(0)
            exit()
        dic[c] -= 1

ans = math.factorial(len(s) // 2)
for num in dic.values():
    ans //= math.factorial(num // 2)

print(ans)

Measured memory_bytes: 7872
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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 || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

struct Coordinate {
    int y, x;
};

int main(){
    int N, M; cin >> N >> M;
    string S; cin >> S;
    if (N+1 <= M){
        cout << N << endl;
        return 0;
    }

    int pos = S.size()-1;
    vector<int> ans(0);
    while (true){
        bool flg = false;
        for (int i = M; i >= 1; i--){
            if (S[pos-i] == '1'){
                continue;
            } else if (pos-i < 0){
                continue;
            } else if (S[pos-i] == '0'){
                ans.push_back(i);
                pos -= i;
                flg = true;
                i = 0;
            }
        }
        if (!flg || pos == 0) break;
    }

    if (pos > 0){
        cout << -1 << endl;
        return 0;
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

bool s(int n) {
  int d = n % 10;
  n /= 10;
  while(n > 0) {
    int nd = n % 10;
    if (d != nd) return false;
    n/=10;
    d = nd;
  }
  return true;
}

int main() {
  int n; cin >> n;
  for (int i = n; i <= 999; i++) {
    if (s(i) == true) { COUT(i); break; }
  }
  return 0;
}

Measured memory_bytes: 256
from collections import deque

x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())), reverse=True)
q = sorted(list(map(int,input().split())), reverse=True)
r = sorted(list(map(int,input().split())), reverse=True)

p = deque(p[0:x])
q = deque(q[0:y])
r = deque(r)


while len(r) != 0 and min(p[-1],q[-1]) < r[0]:
  if p[-1] < q[-1]:
    p.appendleft(r.popleft())
    p.pop()
  else:
    q.appendleft(r.popleft())
    q.pop()
    
print(sum(p)+sum(q))

Measured memory_bytes: 23616
N = int(input())
Data = list(map(int,input().split()))
Kind = [0] * 9
for d in Data:
    if d < 400:
        Kind[0] += 1
    elif d < 800:
        Kind[1] += 1
    elif d < 1200:
        Kind[2] += 1
    elif d < 1600:
        Kind[3] += 1
    elif d < 2000:
        Kind[4] += 1
    elif d < 2400:
        Kind[5] += 1
    elif d < 2800:
        Kind[6] += 1
    elif d < 3200:
        Kind[7] += 1
    else:
        Kind[8] += 1
k = 0
for i in range(8):
    if Kind[i] > 0:
        k += 1
if Kind[8] == 0:
    min1 = k
elif k == 0:
    min1 = 1
else:
    min1 = max(1,k)
max1 = k + Kind[8]
print(min1,max1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int calc(int x,int y){
	if(x<=0)return 0;
	if(x%y==0)return x/y;
	else return x/y+1;
}
int	n,k,a[maxn],tmp,ans;
int main(){
	n=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)if(a[i]==1){tmp=i;break;}
	ans=1e9;
	for(int i=tmp;i<tmp+k;i++)
		ans=min(ans,1+calc(i-k,k-1)+calc(n-i,k-1));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
 
int main(){
    int n, m, sum;
    scanf("%d%d",&n,&m);
    int a[n][m],b[m],c[n];
    int i,j;
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i = 0; i < m; i++){
        scanf("%d",&b[i]);
    }
    for(i = 0; i < n; i++){
        c[i] = 0;
        for(j = 0; j < m; j++){
            c[i] = c[i] + a[i][j] * b[j];
        }
    }
    for(int i = 0; i < n; i++){
        printf("%d\n",c[i]);
    }
    return 0;
}


Measured memory_bytes: 2720
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())

N,M=reads()

    
class UnionFind():
    def __init__(self, n):
        self.n=n
        self.parents=[-1]*n # 親(uf.find()で経路圧縮して根)の番号。根の場合は-(そのグループの要素数)
    def find(self,x):
        #グループの根を返す
        if self.parents[x]<0:return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    #def members(self, x):
    #    root = self.find(x)
    #    return [i for i in range(self.n) if self.find(i) == root]
    def unite(self,x,y):
        #要素x,yのグループを併合
        x,y=self.find(x),self.find(y)
        if x==y:return
        if self.parents[x]>self.parents[y]:#要素数の大きい方をxに
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x #要素数が大きい方に併合
    def roots(self):
        #全ての根の要素のリスト
        return [i for i, x in enumerate(self.parents) if x<0]
    def group_count(self):
        #グループの数
        return len(self.roots())
    #def __str__(self):
    #   return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf=UnionFind(N)
for i in range(M):
    a,b=reads()
    uf.unite(a-1,b-1)
count=uf.group_count()
print(count-1)


Measured memory_bytes: 78760
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */
const ll MOD = 1e9 + 7;
ll cnt[1001];

void addya(int i){
    for(int j = 2;j * j <= i;){
        if(i % j == 0){
            cnt[j] += 1;
            i /= j;
        }else{
            ++j;
        }
    }
    cnt[i] += 1;
}

int main(){
    ll N; cin >> N;
    ll ans = 1;
    for(int i = 2;i <= N;++i){
        addya(i);
    }
    for(int i = 2;i <= N;++i){
        if(cnt[i] != 0)
            ans = (ans * (cnt[i] + 1)) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;

  vll A(N);
  rep(i, N) {
    cin >> A[i];
  }

  vll f1 = divisor(A[0]);
  vll f2 = divisor(A[1]);
  vll f;
  set_union(ALL(f1), ALL(f2), inserter(f, end(f)));
  REVERSE(f);

  rep(i, f.size()) {
    ll count = 0;
    rep(j, N) {
      if (A[j] % f[i] != 0) {
        count++;
      }
      if (count == 2) {
        break;
      }
    }
    if (count < 2) {
      COUT(f[i]);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) vdeb(da[i]);
    std::cout << std::endl;
}

using namespace std;

const int CC = 5500;

int main(){
    int n, k; cin >> n >> k;
    vector<bitset<CC>> pre(n+1), bac(n+1);
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    pre[0][0] = 1;
    bac[n][0] = 1;
    rip(i,n,0){
        pre[i+1] = pre[i];
        if(da[i] <= k) pre[i+1] |= (pre[i] << da[i]);
    }
    rip(i,n,0){
        bac[n-i-1] = bac[n-i];
        if(da[n-i-1] <= k) bac[n-i-1] |= (bac[n-i] << da[n-i-1]);
    }
    int ans = 0;
    rip(i,n,0){
        auto &now1 = pre[i], &now2 = bac[i+1];
        int co = 0;
        rip(j, k, max(0, k-da[i])){
            if(now1[j]) ++co;
        }
        bool flag = false;
        rip(j,k,0){
            if(now2[j] && co > 0) flag =true;
            if(now1[k-j-1]) --co;
            if(k-da[i]-j-1 >= 0 && now1[k-da[i]-j-1]) ++co;
        }
        // cout << co << endl;
        if(flag) ++ans;
    }
    // vdeb(pre);vdeb(bac);
    cout << n-ans << endl;
}

Measured memory_bytes: 7040
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define fi first
#define se second
#define vec vector
const double eps=1e-6;
const int inf=0x3f3f3f3f;
#define N int(1e5+5)

ll q,h,s,d,n;


void solve(){
	scanf("%lld%lld%lld%lld%lld",&q,&h,&s,&d,&n);
		s=min(4*q,min(2*h,s));
		ll ret=0;
		if(2*s<=d){
			ret=s*n;
		}
		else {
			ret=(n/2)*d+(n%2)*s;
		}
		printf("%lld\n",ret);
}

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


Measured memory_bytes: 256
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};
ll N=1e6;

int main(){
    IOS;
    make(ll,n);
    makevec(ll,a,n);
    deque<ll> q;
    fr(i,n){
       if(i%2==0) q.push_back(a[i]);
       else q.push_front(a[i]);

    }
    if(n%2==0){
        for(auto x : q) cout<<x<<" ";
        cout<<endl;
    }
    else{
        auto it=q.end();
        it--;
        while(it!=q.begin()) {cout<<*it<<" "; it--;}
        cout<<*it<<endl;
    }




    return 0;
}



Measured memory_bytes: 6316
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[200009];
ll aaa[200009];

class SegmentTree {
    int n;
    vector<int> dat;

    // i は接点の番号、l, rはその接点が[l, r)に対応していることを示す
    int query_sub(int a, int b, int i, int l, int r) {
        if (r <= a || b <= l) return 1<<30;
        if (a <= l && r <= b)
            return dat[i];
        else {
            int vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
            int vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }

public:
    // 葉がn個のセグメント木
    // 実際の葉の数は完全二分木にしているので少し増える
    SegmentTree(int n_) {
        n = 1;
        while (n < n_) n *= 2;
        dat = vector<int>(2 * n - 1, N);
    }
    // i に x を入れる
    void update(int i, int x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    // [a, b) の最小値を求める
    int query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    // 配列にアクセス
    int at(int i) { return dat[i + n - 1]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    cin>>N;
    SegmentTree sg(N+9);
    
    rep(i,N) cin>>nums[i];
    
    ll sum=0;
    vector<pii> idx;
    idx.push_back({N,0});
    rrep(i,N-1){
        int n=nums[i];
        int nxt=sg.query(0,n+1);
        aaa[i]=1ll*n*(nxt-i);
        if(nxt!=N){
            aaa[i]+=aaa[nxt];
        }
        sum+=aaa[i];
        sg.update(n+1,i);
    }
    cout1(sum);
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
int main(){int n,a,b,k=0;cin>>n>>a>>b;for(int i=1;i<=n;i++){int s=0,d=i;for(int j=1;;j++){s+=d%10;d/=10;if(d==0)break;}if(s>=a&&s<=b)k+=i;} cout<<k<<endl;   }

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;

  int A[Q];
  for (int i = 0; i < Q; i++) cin >> A[i];

  int ans[N];
  for (int i = 0; i < N; i++) ans[i] = K - Q;

  for (int i = 0; i < Q; i++) {
    ans[A[i] - 1] += 1;
  }

  for (int i = 0; i < N; i++) {
    if (ans[i] > 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int n, q, t;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> a(26);
    rep(i, n)a[s[i]-'a'].insert(i);
    rep(i, q){
        cin >> t;
        if(t == 1){
            int x;
            char c;
            cin >> x >> c;
            a[s[x-1]-'a'].erase(x-1);
            a[c-'a'].insert(x-1);
            s[x-1] = c;
        }
        else{
            int l, r, ans = 0;
            cin >> l >> r;
            rep(j, 26){
                auto it = a[j].lower_bound(l-1);
                if(it != a[j].end() && *it < r)ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 24196
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    K = int(rl())
    S = rl().rstrip()
    
    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + '...')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61864
N = int(input())

M = []
for _ in range(N):
  M.append(list(map(int,input().split())))

s = 0
for i in range(N):
  for j in range(i+1,N):
    s += ((M[i][0]-M[j][0])**2 + (M[i][1]-M[j][1])**2)**0.5

print(s*2/N)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << (x - z) / (y + z) << endl;
}

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

int main() {
  int n;
  cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  map <int,int>kazu;
  for(int x:a){
    if(kazu.count(x)){
      kazu.at(x)++;
    }else{
      kazu[x]=1;
    }
  }
  long long kotae=0;
  for( auto i = kazu.begin(); i != kazu.end() ; ++i ) {
    if(i->first < i->second)kotae+=i->second- i->first;
    else if(i->first > i->second)kotae+=i->second;
  }  
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chadd(x, y) x = (x + y) % mod

ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

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

struct Combination{
    int sz;
    vector<ll> fact;
    vector<ll> ifact;

    Combination(int sz = 2 * 1e+5) : sz(sz) {
        fact = vector<ll>(sz + 1);
        ifact = vector<ll>(sz + 1);

        fact[0] = 1;
        for(ll i = 1; i <= sz; ++i){
            fact[i] = fact[i - 1] * i % mod;
        }

        ifact[sz] = mod_pow(fact[sz], mod - 2);
        for(ll i = sz; i > 0; --i){
            ifact[i - 1] = ifact[i] * i % mod;
        }
    }

    ll get_combination(int n, int r){
        if(n < 0 || r < 0 || n < r)     return 0;

        return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
    }
};

ll dp[3005][2];

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

    int h, w, n;
    cin >> h >> w >> n;
    vector<P> rc(n);
    for(int i = 0; i < n; ++i){
        int r, c;
        cin >> r >> c;
        --r, --c;
        rc[i] = P(r, c);
    }
    rc.push_back(P(0, 0));      // スタート地点
    rc.push_back(P(h-1, w-1));  // ゴール地点
    sort(rc.begin(), rc.end());
    Combination c;
    
    dp[0][1] = 1;
    // 包徐原理により dp テーブルを埋めていく
    // rc の要素数は n+2 個あり、最初の要素を除いた要素について走査
    // r の昇順に要素を見ていく
    for(int i = 1; i <= n+1; ++i){
        for(int j = 0; j < 2; ++j){
            for(int k = 0; k < i; ++k){     // (r_i, c_i) に到達し得る (r, c) について走査
                // 遷移不能ならば continue
                // r について昇順で並んでいるので、 c を比べて判定
                if(rc[i].second < rc[k].second) continue;

                int N = rc[i].first + rc[i].second - rc[k].first - rc[k].second;
                int K = rc[i].first - rc[k].first;
                // (r_k, c_k) から (r_i, c_i) に到達する経路数
                // j は (0, 1) → (1, 0) と遷移
                ll add = dp[k][j ^ 1] * c.get_combination(N, K) % mod;
                chadd(dp[i][j], add);
            }
        }
    }

    ll res = (dp[n+1][0] - dp[n+1][1]) % mod;
    if(res < 0) res += mod;
    cout << res << endl;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

bool check(int i, int j, int k, string& S) {
  vector<int> v = {i, j, k};
  int index = 0;
  for (char c : S) {
    if (v[index] == c - '0') ++index;
    if (index == 3) return true;
  }
  return false;
}

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

  int cnt = 0;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      for (int k = 0; k < 10; ++k) {
        if (check(i, j, k, S)) ++cnt;
      }
    }
  }

  cout << cnt << endl;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;


signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // Failed to predict input format
    int N;
    cin >> N;
    vector<char> c(N);
    rep(i,0,N) cin >> c[i];
    int answer = 0, left = 0, right = N-1;
    while (left < right) {
        while (c[left] == 'R') left++;
        while (c[right] == 'W') right--;
        if (left >= right) break;
        swap(c[left], c[right]);
        left++; right--;
        answer++;
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = vals[0];
        var Q = vals[1];
        var edges = Enumerable.Range(0, N + 1).Select(_ => new List<int>()).ToArray();

        for (int i = 0; i < N - 1; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = vals[0];
            var b = vals[1];
            edges[a].Add(b);
            edges[b].Add(a);
        }
        var count = new long[N + 1];
        for (int i = 0; i < Q; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var p = vals[0];
            var x = vals[1];
            count[p] += x;
        }

        var currents = new List<int>() { 1 };
        var vistied = new bool[N + 1];
        vistied[1] = true;
        while (currents.Count > 0)
        {
            var nexts = new List<int>();
            foreach (var cur in currents)
            {
                foreach (var e in edges[cur])
                {
                    if (!vistied[e])
                    {
                        vistied[e] = true;
                        nexts.Add(e);
                        count[e] += count[cur];
                    }
                }
            }
            currents = nexts;
        }

        Console.WriteLine(string.Join(" ", count.Skip(1)));
    }
}

Measured memory_bytes: 54324
import sys
input = sys.stdin.readline

A,B,C=map(int,input().split())

if A % 2 == 0 or B%2 == 0 or C%2==0:
    print(0)
else:
    AB=A*B
    BC=B*C
    CA=C*A
    print(min(AB,BC,CA))




Measured memory_bytes: 61820
nv, ne, r = [int(i) for i in input().split()]
# from, to, cost
edges = [[int(i) for i in input().split()] for _ in range(ne)]
costs = [float("inf")] * nv
costs[r] = 0

for i in range(nv):
    is_updated = False
    for edge in edges:
        f, t, c = edge
        if costs[f] + c < costs[t]:
            costs[t] = costs[f] + c
            is_updated = True

if is_updated:
    print("NEGATIVE CYCLE")
else:
    for c in costs:
        print(c if c < float("inf") else "INF")



Measured memory_bytes: 6056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

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

ll n, k, z;
vector<ll> a, b;

// 合計が x 以下のものを k 組作れるか
template<typename T>
bool check(T x) {
  ll ret = 0;

  if (x < 0) {
    ll x2 = -x;
    // 値としては "以上"
    rep(i, sz(a)) {
      int it;
      if (x % a[i] == 0) {
        it = lb(b, x2 / a[i]);
      } else {
        it = lb(b, (x2 + (a[i] - 1)) / a[i]);
      }
      ret += sz(b) - it;
    }
  }

  if (x >= 0) {
    // 0
    ret += max(0LL, 1LL * z * (z - 1) / 2);
    ret += z * sz(a);
    ret += z * sz(b);

    // 負全部
    ret += 1LL * sz(a) * sz(b);

    if (x > 0) {
      // "以下"
      auto calc = [&](vector<ll> a) {
        ll tmp = 0;
        rep(i, sz(a)) {
          int it = ub(a, x / a[i]); // debuged
          it--;
          tmp += it + 1;
          if (it >= i) tmp--;
        }
        tmp /= 2; // debuged
        ret += tmp;
      };
      calc(a);
      calc(b);
    }
  }

  // cout << x << " " << ret << endl;
  if (ret >= k) return 1;
  return 0;
}

template<typename T>
void binary_search(T ok, T ng) {
  while (abs(ng - ok) > 1) {
    T mid = (ng + ok) / 2;
    (check(mid) ? ok : ng) = mid;
  }
  // ok のなかで出来るだけ下がるようになる
  cout << ok << endl;
}

void solve() {
  cin >> n >> k;
  rep(i, n) {
    int c;
    cin >> c;
    if (c > 0) a.eb(c);
    else if (c < 0) b.eb(-c);
    else z++;
  }
  sort(all(a));
  sort(all(b));

  binary_search(pow(10LL, 18), -pow(10LL, 18) - 1);
}


Measured memory_bytes: 3056
a = int(input())
b = []
for i in range(0, a):
    b.append(input())
    if i != 0:
        if (b[i])[0] != (b[i-1])[-1]:
            print("No")
            exit()
        for j in range(len(b)-1):
            if b[j] == b[i]:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3060
#python3
from collections import deque

def main():

    k = int(input())
    cand = []
    for i in range(1, 10):
        cand.append(i)

    cnt = 0
    dq = deque()
    for i in range(1, 10):
        dq.append(i)

    while len(dq):
        v = dq.popleft()
        x = v%10 
        cnt += 1
        if x == 0:
            for j in (0, 1):
                nx = v*10 + j
                cand.append(nx)
                dq.append(nx)
        elif x == 9:
            for j in (-1, 0):
                nx = v*10 + 9 + j
                cand.append(nx) 
                dq.append(nx)
        else:
            for j in (-1, 0, 1):
                nx = v*10 + x + j
                cand.append(nx)
                dq.append(nx)
        if len(cand) > 2*k:
            break    

    cand.sort()
    print(cand[k-1])
main()

Measured memory_bytes: 13024
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void part_digit(long long b, long long n, vector<long long> &v){
  if (n < b) {
    v.push_back(n);
    return;
  } else {
    v.push_back(n % b);
    part_digit(b, n/b, v);
    return;
  }
  return;
}
long long sum_digit(long long b, long long n, long long tot){
  if (n < b) {
    tot += n;
    return(tot);
  } else {
    tot += n%b;
    return(sum_digit(b, n/b, tot));
  }
  return(tot);
}

int main(){
  long long n, s, b, sqrt_n;
  long long ds = 0;
  cin >> n >> s;
  sqrt_n = floor(sqrt((double)(n)));
  if (s == n) {
    cout << n+1 << endl;
    return(0);
  }
  if (s > n/2 + 1) {
    cout << -1 << endl;
    return(0);
  }
  
  for (long long i=2;i<=sqrt_n;i++) {
    long long tot = sum_digit(i, n, 0);
    if (s==tot) {
      cout << i << endl;
      return(0);
    }
  }
  for (long long i=sqrt_n+1;i<=n;) {
    long long h = sum_digit(i, n, 0);
    long long r = n/i;
    long long j = n/r;
    if (j > n) {
      j = n;
    }
    long long l = sum_digit(j, n, 0);
    if (l <= s && s <= h && (s-l)%r == 0) {
      cout << j - (s-l)/r << endl;
      return(0);
    }
    i = j+1;
  }
  cout << -1 << endl;
  return(0);
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N,M; cin>>N>>M;
    ll d=M-N;
  	cout<<(1+d)*d/2-M;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<ll,ll> mll;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
// #define mod 998244353
#define mod 1000000007 

#define trace1(x)                       cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                    cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(x, y, z , t)             cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<endl
#define trace5(x, y, z , t , u)         cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<endl
#define trace6(x, y, z , t , u , v)     cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<" | "<<#v<<": "<<v<<endl

#define repa(i,sta,end,inc) for(int i = sta ; i <= end ; i += inc)
#define repb(i,sta,end,inc) for(int i = sta ; i >= end ; i -= inc)

ll power(ll x , ll y , ll z){ll res = 1;x %= z;while(y){if(y&1){res = res * x % z;}x = x*x % z;y /= 2;}return res%z;}
ll gcd(ll a , ll b){return (b == 0 ? a : gcd(b , a % b));}

const int N = 2 * 100000 + 1;
const int inf = (1<<30);

void solve(){
    int n;
    cin >> n;
    ll ans = 0;
    repa(a,1,n,1){
        repa(b,1,n,1){
            repa(c,1,n,1){
                ans += __gcd( __gcd(a,b) , c );
            }
        }
    }
    cout << ans << endl;
}


int main(){
    FIO;
    int T = 1;
    // cin >> T;
    repa ( i , 1 , T , 1){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a + b - 1) / b << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
#define impossible cout<<"IMPOSSIBLE"<<endl;
#define error(s) throw runtime_error(s)
// std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// int myRand(int R) {
// 	int val=rng() % R;
//       assert(val>=0);
//       return val;
// }
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=3e18;
const int32_t LOG=21;
const int32_t MOD=MOD1;

int power(int x,int y)
{
    if(y==0)return 1;
    int temp=power(x,y/2);
    temp=(temp*temp)%MOD;
    if(y&1)temp=(temp*x)%MOD;
    return temp;
}

int fact[500005];
int inv[500005];


void init()
{
     fact[0]=inv[0]=1;
     rep(i,1,500002)
     {
         fact[i]=(fact[i-1]*i)%MOD;
         inv[i]=power(fact[i],MOD-2);
     }
}

int ncr(int n,int r)
{
    if(n<r)return 0;
    int x=fact[n];
    int y=inv[r];
    int z=inv[n-r];
    int ans=(x*y)%MOD;
    ans=(ans*z)%MOD;
    return ans;
}

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      { 
             init();
             int n,m;
             cin>>n>>m;
             int mul=(ncr(m,n)*fact[n])%MOD;
             int ans=0;
             rep(j,0,n+1)
             {
                 int sign=1;
                 if(j&1)sign=-1;
                 int toAdd=(ncr(n,j)*ncr(m-j,n-j))%MOD;
                 toAdd=(toAdd*fact[n-j])%MOD;
                 toAdd*=sign;
                 ans=(ans+toAdd+MOD);
                 while(ans>=MOD)ans-=MOD;
             }
             ans=(ans*mul)%MOD;
             cout<<ans<<endl;
      }
      return 0;                         
}

/*
 TIPS:
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 11412
#include <cstdio>
#include <algorithm>
using namespace std;
#define R for(i=0;i<n;++i)
int a[1<<17],b[1<<17],amn=1e7,amx=-1e7,bmn=1e7,bmx=-1e7,n,c,d,ow=-1e7,oh=-1e7,i;
int main(){
	scanf("%d",&n);
	R{
		scanf("%d %d",&c,&d);
		a[i] = c+d;
		b[i] = c-d;
		amn = min(amn,a[i]);
		amx = max(amx,a[i]);
		bmn = min(bmn,b[i]);
		bmx = max(bmx,b[i]);
	}
	R{
		ow = max(ow,min(max(a[i]-amn,b[i]-bmn),max(amx-a[i],bmx-b[i])));
		oh = max(oh,min(max(a[i]-amn,bmx-b[i]),max(amx-a[i],b[i]-bmn)));
	}
	printf("%d\n",min(ow,oh));
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    string s; cin >> s;
    if (s == "snuke") {
      cout << (char) ('A' + j) << i + 1 << '\n';
      break;
    }
  }
}

Measured memory_bytes: 256