akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Control.Monad
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

data Tree a = Tree (Tree a) a (Tree a)

instance Functor Tree where
    fmap f (Tree l m r) = Tree (fmap f l) (f m) (fmap f r)

index :: Tree a -> Int -> a
index (Tree _ m _) 0 = m
index (Tree l _ r) n = case (n - 1) `divMod` 2 of
    (q,0) -> index l q
    (q,1) -> index r q

nats :: Tree Int
nats = go 0 1
    where go !n !s = Tree (go l s') n (go r s')
            where l = n + s
                  r = l + s
                  s' = s * 2

memo :: (Int -> a) -> (Int -> a)
memo f = index cached
    where cached = fmap f nats

memo2 :: (Int -> Int -> a) -> (Int -> Int -> a)
memo2 f = memo (\x -> memo (f x))

memo3 :: (Int -> Int -> Int -> a) -> (Int -> Int -> Int -> a)
memo3 f = memo (\x -> memo2 (f x))

intsToPair :: [Int] -> (Integer, Integer)
intsToPair [a,b] = (fromIntegral a, fromIntegral b)

solve :: [(Integer, Integer)] -> Integer
solve (p:e) = let (sp, se) = foldl merge p e in sp + se
    where merge (lp, le) (p, e) = let (a, b) = ((lp+p-1) `div` p , (le+e-1) `div` e) in
            if p*a < lp || e*a < le then (p*b, e*b) 
            else if p*b < lp || e*b < le then (p*a, e*a)
            else if p*a + e*a < p*b + e*b then (p*a, e*a)
            else (p*b, e*b)

main :: IO ()
main = do
    [n] <- getInts
    ls <- replicateM n getInts
    print (solve (map intsToPair ls))

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005]; 
int main()
{
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;++i)
	cin>>a[i];
	for(int i=k+1;i<=n;++i)
	{
		if(a[i]>a[i-k]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
} 

Measured memory_bytes: 5192
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll ans = 0;
	ll c = n - 1;
	for (ll i = 1; i * i <= n - 1; i++) {
		if (c % i == 0) {
			ans += 2;
			if (i * i == n - 1)ans--;
			if (i == 1)ans--;
		}
	}
	c++;
	for (ll i = 1; i * i <= n; i++) {
		c = n;
		if (c % i == 0) {
			if (i != 1) {
				while (c % i == 0) {
					c /= i;
				}
				if (c % i == 1)ans++;
			}
			c = n;
			ll k = c / i;
			//cout << c << " " << i << " " << k << "\n";
			if (k == i)continue;
			while (c % k == 0) {
				c /= k;
			}
			if (c % k == 1)ans++;
		}

	}
	cout << ans;
}

Measured memory_bytes: 256
/**
 * Worst Sportswriter
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

import static java.lang.Integer.parseInt;

public class Main {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int n = parseInt(br.readLine());
		int m = parseInt(br.readLine());
		List<Integer>[] indeg = new List[n + 1];
		List<Integer>[] outdeg = new List[n + 1];
		List<Integer> idx = new ArrayList<Integer>();
		Deque<Integer> rank = new ArrayDeque<Integer>();
		boolean alt = false;

		for (int i = 1; i <= n; i++) {
			indeg[i] = new ArrayList<Integer>();
			outdeg[i] = new ArrayList<Integer>();
			idx.add(i);
		}
		for (int i = 0; i < m; i++) {
			line = br.readLine();
			int a = parseInt(line.substring(0, line.indexOf(' ')));
			int b = parseInt(line.substring(line.indexOf(' ') + 1));
			indeg[b].add(a);
			outdeg[a].add(b);
		}
		//solve
		while (!idx.isEmpty()) {
			if (!alt) {
				int winners = 0;
				for (Integer winner : idx) {
					if (indeg[winner].size() == 0) {
						winners++;
						if (winners > 1) {
							alt = true;
							break;
						}
					}
				}
			}
			for (Integer winner : idx) {
				if (indeg[winner].size() == 0) {
					rank.add(winner);
					for (int loser : outdeg[winner]) {
						indeg[loser].remove(winner);
					}
					break;
				}
			}
			idx.remove(rank.peekLast());
		}
		rank.add(alt ? 1 : 0);
		for (int i : rank) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 46828
loop do
    n = gets.to_i
    break if n == 0
    w, h = gets.split.map(&:to_i)
    f = Array.new(h+1).map{Array.new(w+1, 0)}
    n.times do
        p = gets.split.map(&:to_i)
        f[p[1]][p[0]] = 1
    end
    s, t = gets.split.map(&:to_i)
    (h+1).times do |i|
        (w+1).times do |j|
            f[i][j] += f[i][j-1] if j > 0
        end
    end
    (w+1).times do |i|
        (h+1).times do |j|
            f[j][i] += f[j-1][i] if j > 0
        end
    end
    max = 0
    for i in 1..(h - t + 1)
        for j in 1..(w - s + 1)
            max = [max, f[i + t - 1][j + s - 1] + f[i - 1][j - 1] - f[i + t - 1][j - 1] - f[i - 1][j + s - 1]].max
        end
    end
    puts max
end

Measured memory_bytes: 6144
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
#include<stack>
#include<fstream>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

int main(){
	deque<char> Q;
	string s;
	cin>>s;
	rep(i,s.size())Q.push_back(s[i]);
	ll q;
	cin>>q;
	bool flag=0;//元の文字列が反転しているか
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			flag^=1;
		}
		else{
			ll f;
			char c;
			cin>>f>>c;
			if(flag^(f==1))Q.push_front(c);
			else Q.push_back(c);
		}
	}
	if(flag==0){
		while(!Q.empty()){
			cout<<Q.front();
			Q.pop_front();
		}
		cout<<endl;
	}
	if(flag==1){
		while(!Q.empty()){
			cout<<Q.back();
			Q.pop_back();
		}
		cout<<endl;
	}
}


Measured memory_bytes: 896
import bisect

N , M , K = map ( int , input().strip().split(" ") ) ;
A = list ( map  ( int , input().strip().split(" ") ) ) ;
B = list ( map  ( int , input().strip().split(" ") ) ) ;

A.insert ( 0 , 0 ) ;
B.insert ( 0 , 0 ) ;

for i in range ( 1 , len ( A ) ) :
		A[i] = A[i-1] + A[i] ; 
for i in range ( 1 , len ( B ) ) :
		B[i] = B[i-1] + B[i] ; 



t = 0 ;
for i , v in enumerate ( A ) :
	if v > K : break ;
	x2 = bisect.bisect_right( B , K - v ) ; 
	t = max ( t , x2 - 1 + i ) ;

print ( t ) ;

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> data(N+1,vector<int>(3));
    for (int i=1; i<N+1; i++) {
        for (int j=0; j<3; j++) {
            cin >> data.at(i).at(j);
        }
    }

    //
    vector<int> t(N+1);
    vector<int> X(N+1);
    for (int i=0; i<N+1; i++) {
        t.at(i) = data.at(i).at(0);
        X.at(i) = data.at(i).at(1) + data.at(i).at(2);
    }

    for (int i=1; i<N+1; i++) {
        if (abs(X.at(i)-X.at(i-1)) > t.at(i)-t.at(i-1)) {
            cout << "No" << endl;
            exit(0);
        }
        else if (abs((X.at(i)-X.at(i-1)))%2 != (t.at(i)-t.at(i-1))%2) {
            cout << "No" << endl;
            exit(0);
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 9664
N = int(input())
R=[["1","2","3","4","5","6","7","8","9"]]
count=9
temp=[]
for i in range(N):
  if count>=N:
    break
  else:
    temp=[]
    for r in R[i]:
      if r[-1]=="9":
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
      elif r[-1]=="0":
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
      else:
        temp.append(str(r)+str(int(r[-1])-1))
        temp.append(str(r)+str(int(r[-1])))
        temp.append(str(r)+str(int(r[-1])+1))
    R.append(temp)
    count+=len(temp)
N=N-(count-len(temp))
print(R[-1][N-1])

Measured memory_bytes: 23228
N = int(input())
S = str(input())
result=""
for c in S:
    if ord('A') <= ord(c) <= ord('Z'):
        result =  result+chr(abs(((ord(c) + N - ord('A')) % 26)) + ord('A'))
    else :
        result =  result+chr(abs(((ord(c) + N - ord('A')) % 26)) + ord('A'))
print(result)

Measured memory_bytes: 3188
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int A, B;
	cin >> A >> B;

	auto x = vector<int>({
		A + B,
		A - B,
		A * B
		});

	cout << *max_element(x.begin(),x.end())<< endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}




Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,d;
  cin >> h >> w >> d;
  int px[90001],py[90001];
  int dis[90001];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int a;
      cin >> a;
      px[a]=i;
      py[a]=j;
    }
  }
  for(int i=d+1;i<=h*w;i++){
    dis[i]=dis[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
  }
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int l,r;
    cin >> l >> r;
    cout << dis[r]-dis[l] << endl;
  }
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(){
	int i, max;
    int n;
    int a, b, c;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%d %d %d", &a, &b, &c);
        
        max = a;
        if (max < b) max = b;
        if (max < c) max = c;
        
        if (max*max == a*a + b*b + c*c - max*max) printf("YES\n");
        else                                      printf("NO\n");
    }
    
    return 0;
}

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

int main() {
    long H, W;
    cin >> H >> W;
    if((H==1)|(W==1)){
      cout << "1" << endl;
    }else{
  	  cout << (H*W+1)/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ll(x.size()) 
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

const int MAX = 300000;

template <typename X>
struct SegTree {
  using FX = function<X(X, X)>; // X•X -> X となる関数の型
  int n;
  FX fx;
  const X ex;
  vector<X> dat;
  SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
    int x = 1;
    while(n_ > x) x *= 2;
    n = x;
  }
  void set(int i, X x) { dat[i + n - 1] = x; }
  void build() {
    for(int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
  }
  void update(int i, X x) {
    i += n - 1;
    dat[i] = x;
    while(i > 0){
      i = (i - 1) / 2;  // parent
      dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
  X query_sub(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l){
      return ex;
    }else if(a <= l && r <= b){
      return dat[k];
    }else{
      X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
      X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
      return fx(vl, vr);
    }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k; cin >> n >> k;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  auto fx = [](int x1, int x2) -> int { return max(x1, x2); };
  int ex = 0;
  SegTree<int> rmq(MAX+1, fx, ex);
  rmq.set(a[0], 1);
  rmq.build();

  vector<int> dp1(n,0), dp2(n,0);
  dp1[0] = 1;
  FOR(i,1,n){
    dp1[i] = rmq.query(max(a[i]-k,0), min(a[i]+k,MAX)+1)+1;
    dp2[i] = max(dp1[i-1], dp2[i-1]);
    rmq.update(a[i], dp1[i]);
  }

  int ans = 0;
  REP(i,n){
    chmax(ans, dp1[i]);
    chmax(ans, dp2[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11396
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
  string line;
  int a,b,c;
  int n = 0;
  getline (cin,line);
  stringstream(line) >> a >> b >> c;
  while ( a <= b )
  {
    if ( c % a++ == 0 ) { n++; }
  }
  cout << n << '\n';
  return 0;
}

Measured memory_bytes: 3184
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
	ll n;
	int ans = 100;
	scanf("%lld",&n);
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			int cnt = 0;
			ll x = n / i;
			while(x>0){
				x /= 10;
				cnt++;
			}
			ans = min(ans,cnt);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
using Graph = vector<vector<int>>;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
// 大きい順
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const  long long INF = 1LL << 60;
typedef  long long ll;
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;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<int,int> mp;

int primeFactorization(int a){ //素因数分解を出力するプログラム
    int i,sq;
    if(a%2==0){ //偶数の場合
        if(!mp.count(2)){
            mp[2] = 1;
        }
        else{
            mp[2] +=1;
        }
        return primeFactorization(a/2); //2で割った値で再帰
    }
    sq = sqrt(a);
    for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
        if(a%i==0){
            if(!mp.count(i)){
                mp[i] = 1;
            }
            else{
                mp[i] += 1;
            }
            return primeFactorization(a/i); //割れた値で再帰
        }
    }
    //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
    if(a!=1){ //aが1でないなら、a自身は素数
        if(!mp.count(a))
        mp[a] = 1;
        else{
            mp[a] += 1;
        }
    }
    return 0;
}


ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}





int main(){
int a; cin >> a;
cout << a + a * a + a * a * a << endl;

}

Measured memory_bytes: 3652
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000009LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int n;
string s;
long long gogo[20000];
int solve(int len) {
	long long dying = 1;
	int itr = 0;
	long long now = 0;
	for (int q = 0; q < s.length(); ++q) {
		now *= 26LL;
		now += s[q] - 'a';
		now %= MAX_MOD;
		if (q >= len) {
			now += (MAX_MOD - ((dying * (s[q - len] - 'a') % MAX_MOD))) % MAX_MOD;
			now %= MAX_MOD;
		}
		else {
			dying *= 26LL;
			dying %= MAX_MOD;
		}
		if (q >= len - 1) {
			gogo[itr] = now;
			itr++;
		}
	}
	set<long long> nya;
	for (int i = itr - len - 1; i >= 0; --i) {
		nya.insert(gogo[i + len]);
		if (nya.find(gogo[i]) != nya.end()) return true;
	}
	return false;
}
int main() {
	cin >> n >> s;
	int bot = 0;
	int top = s.length();
	while (top - bot > 1) {
		int mid = (top + bot) / 2;
		if (solve(mid) == true) {
			bot = mid;
		}
		else top = mid;
	}
	cout << bot << endl;
}


Measured memory_bytes: 888
#include <stdio.h>

#define MAX 100005 
#define NIL -1

typedef struct {
  int p;  // �e(parent)
  int l;  // ���ԍ��̎q(left child)
  int r;  // �E�̌Z��(right sibling)
} Node;

Node T[MAX]; 
int D[MAX];

void print(int);
void calcDepth(int, int);


int main() { 
  int i, j, k; 
  int n; 
  int id, sib, child; 
  int root = NIL;
  
  scanf( "%d" , &n ); 
  for ( i=0; i<n; i++ ) T[i].p = T[i].l = T[i].r = NIL; 
  for ( i=0; i<n; i++ ) { 
    scanf( "%d %d" , &id , &k ); 
    for ( j=0,sib=NIL; j<k; j++) {  //�q�����͂��� (input children) 
      scanf( "%d" , &child ); 
      T[child].p = id; 
      if ( j == 0 ) T[id].l = child;  //id�̈��ԍ��̎q (the most left child of id) 
      else T[sib].r = child;  //���̌Z���Ɍq���� (connect to left sibling) 
      sib = child;  //���̎q���̍��̌Z�� (the left sibling of the next child) 
    } 
  }
  for ( i=0; i<n; i++ ) if ( T[i].p == -1 ) root = i;  //�������߂� (find the root)
  calcDepth(root, 0);  //���ꂼ���̃m�[�h�̐[�������߂� (find depth of each node)

  for ( i=0; i<n; i++ ) print(i);  //�o�� (output)

  
  return 0; 
}


void print(int u){ 
  int i, c;
  
  printf( "node %d: parent = %d, depth = %d, " , u , T[u].p , D[u] ); 

  if ( T[u].p == -1 ) printf( "root, " ); 
  else if ( T[u].l == NIL ) printf( "leaf, " ); 
  else printf( "internal node, " ); 
  
  printf( "[" ); 
  for ( i=0,c=T[u].l; c!=NIL; i++,c = T[c].r ) { 
    if ( i ) printf( ", " ); 
    printf( "%d" , c ); 
  } 
  printf( "]\n" ); 
} 

void calcDepth(int u, int p){ 
  D[u] = p; 
  if ( T[u].l != NIL )
    calcDepth(T[u].l, p+1); 
  if ( T[u].r != NIL )
    calcDepth(T[u].r, p); 
}



Measured memory_bytes: 3252
#include<bits/stdc++.h>
using namespace std;
long long dp[405][405],qs[405];
main()
{
	int t;
	scanf("%d",&t);
	for(int i=  0;i <= 404;i++)
	{
		for(int j = 0;j <= 404;j++)
		dp[i][j]=1e15;
	}
	for(int i = 1;i <= t;i++)
	{
		scanf("%lld",&dp[i][i]);
		qs[i]=dp[i][i];
		qs[i]+=qs[i-1];
		dp[i][i]=0;
	}
	for(int i = 2;i <= t;i++)
	{
		for(int j = 1;j+i-1 <= t;j++)
		{
			for(int k = 0;k < i;k++)
			{
				dp[j][j+i-1]=min(dp[j][j+k]+dp[j+k+1][i+j-1]+qs[j+i-1]-qs[j-1],dp[j][j+i-1]);
				//printf("%d %d %lld\n",j,j+i-1,dp[j][j+i-1]);
			}
		}
	}
	printf("%lld",dp[1][t]);
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n;
	cin >>n;
	int a[n];
	int l,m;
	l=0;
	m=0;
	for(int i=0;i<n;++i){
		cin >>a[i];
		if(a[i]%4==0){m++;}
		if(a[i]%4!=0&&a[i]%2==0){l++;}
	}
	if((((n-l)%2==0||l==0)&&(n-l)/2<=m)||((n-l)%2==1&&(n-l)/2<m)){cout<<"Yes"<<endl;}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

S = s_in()
Y = 753

ans = 10**4
for i in range(len(S) - 2):
    x = int(S[i: i+3])
    ans = min(abs(Y - x), ans)

print(ans)


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

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  
  if (a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0)) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
def chg(n):
  if n==1:
    return 9
  elif n==9:
    return 1
  return n

n = int(input())
n,a1 = divmod(n,10)
n,a2 = divmod(n,10)
n,a3 = divmod(n,10)


print(100*chg(a3)+10*chg(a2)+chg(a1))

Measured memory_bytes: 3060
N,M = map(int,input().split(" "))
sum1 = []
sum2 = []
sum3 = []
sum4 = []
sum5 = []
sum6 = []
sum7 = []
sum8 = []

for i in range(N):
    x,y,z = map(int,input().split(" "))
    a1 = x+y+z
    sum1.append(a1)
    #+++
    a2 = a1-z*2
    sum2.append(a2)
    #++-
    a3 = a2-y*2
    sum3.append(a3)
    #+--
    a4 = a3+z*2
    sum4.append(a4)
    #+-+
    a5 = a4-x*2
    sum5.append(a5)
    #--+
    a6 = a5+y*2
    sum6.append(a6)
    #-++
    a7 = a6-z*2
    sum7.append(a7)
    #-+-
    a8 = a7-y*2
    sum8.append(a8)
    #---
sum1.sort()
sum1.reverse()
sum2.sort()
sum2.reverse()
sum3.sort()
sum3.reverse()
sum4.sort()
sum4.reverse()
sum5.sort()
sum5.reverse()
sum6.sort()
sum6.reverse()
sum7.sort()
sum7.reverse()
sum8.sort()
sum8.reverse()
print(max(sum(sum1[:M]),sum(sum2[:M]),sum(sum3[:M]),sum(sum4[:M]),sum(sum5[:M]),sum(sum6[:M]),sum(sum7[:M]),sum(sum8[:M])))


Measured memory_bytes: 3316
package main

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

func main() {
	N := nextInt()
	D := nextInt()

	var c = math.Ceil(float64(N) / float64(2*D+1))

	fmt.Println(int(c))
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)


vector<int> primVec(int N){
	vector<int> res, vec;
	vec= vector<int>(N+1,1);
	for(int i=2; i<N+1; i++){
		if(vec.at(i)==1){
			for(int j = 0; i*(j+2)<N+1; j++){
				vec.at(i*(j+2))=0;
			}
		}
	}
	res=vec;
	return res;
}

int main(){
  int N=1e5+3;
  vector<int> v(N);
  v = primVec(N);
  vector<int> key(N,0);
  FOR(i,3,N-1){
    if(v[i]==1&&v[(i+1)/2]==1)key[i]=1;
  }
  FOR(i,3,N){
    key[i]+=key[i-1];
  }


  ll Q;
  cin>>Q;
  ll a,b;
  FOR(i,0,Q){
    cin>>a>>b;
    cout<<key[b]-key[a-1]<<endl;
  }
}


Measured memory_bytes: 1408
#include <stdio.h>
int main () {
	int n,i,j;
	int job=0;
	scanf("%d",&n);
	for (i=1;i<=9;i++) {
		for (j=1;j<=9;j++) {
			if (i<=j && n==i*j) job++;
		}
	}
	if (job>0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main(){
	int r=0,rmax=0;
	string s;
	cin>>s;
	for(int loop=0;loop<s.length();loop++){
		if(s[loop]=='R'){
			r++;
		}else{
			if(rmax<r){
				rmax=r;
			}
			r=0;
		}
	}
	if(rmax<r){
		rmax=r;
	}
	cout << rmax << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
using namespace std;
#define INF 1000000001
int main(){
  int n,m;
  int d[1001],c[1001];
  int dp[1001][1001];
  fill_n(*dp,1001*1001,INF);
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++) scanf("%d",&d[i]);
  for(int i=0;i<m;i++){
    scanf("%d",&c[i]);
    dp[0][i] = c[i]*d[0];
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      dp[i][j+1] = min(dp[i][j+1],dp[i][j]);
      dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+d[i+1]*c[j+1]);
    }
  }
  
  printf("%d\n",dp[n-1][m-1]);

  return (0);
}

Measured memory_bytes: 6648
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0; i < a;i++){
            if(i % 2 == a % 2){
            	list.add(sc.nextInt());
            }else{
              	list.add(0,sc.nextInt());
            }
            
        }
      
        for(int i = 0; i < a;i++){
      		System.out.print(list.get(i) + " ");
        }
        System.out.println();
 
    }
}

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

int main(){
    int n, k;
    cin >> n >> k;
    bool is = true;
    int beki = 0;
    int x;
    while(is){
        x = pow(k, beki);
        if (n < x) is = false;
        else beki += 1;
    }

    if (beki == 0) cout << 1 << endl;
    else cout << beki << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a,b,c,t;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	if(a%b==0)t=a/b;
	else t=a/b+1;
	printf("%d",t*c);
	return 0;
}


Measured memory_bytes: 3824
# Function to find modulo inverse of b. It returns  
# -1 when inverse doesn't  
# modInverse works for prime m 
def gcd(b, m):
  if b == 0:
    return m
  return gcd(m%b, b)

def modInverse(b,m): 
    g = gcd(b, m) 
    if (g != 1): 
        # print("Inverse doesn't exist")  
        return -1
    else:  
        # If b and m are relatively prime,  
        # then modulo inverse is b^(m-2) mode m  
        return pow(b, m - 2, m) 
  
  
# Function to compute a/b under modulo m  
def modDivide(a,b,m): 
    a = a % m 
    inv = modInverse(b,m) 
    if(inv == -1): 
        print("Division not defined") 
    else: 
        return (inv*a) % m

MOD = (10 ** 9) + 7
H, W, A, B = list(map(int, input().split(' ')))

DP = []
j = 1
for i in range(1,200002):
    j *= i
    j %= MOD
    DP.append(j)

# print(DP)
def factorial(i):
    if (i == 0):
        return 1
    global DP
    # print(i)
    # print(i, DP[i-1])
    # print(DP[i-1])
    return DP[i-1]

def move2(H, W, A, B):
    numPaths = 0
    h = H-A
    w = W-(W-B)+1
    a = A+1
    pttp = 0
    for b in range(w, W+1):
        # print(h, b, a, W-b+1)
        ttp = (factorial(h+b-2)*modInverse((factorial(h-1)*factorial(b-1))% MOD, MOD)) % MOD
        tpttp = ttp
        ttp -= pttp
        pttp = tpttp
        btp = (factorial(a+(W-b+1)-2)*modInverse((factorial(a-1)*factorial(W-b))% MOD, MOD)) % MOD
        # btp = factorial(a+(W-b+1)-2)//(factorial(a-1)*factorial(W-b))
        numPaths += ttp*btp
    return numPaths

ways = move2(H, W, A, B)
print(ways % (10**9 + 7))

Measured memory_bytes: 11056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,K;
    cin >> N >> K;
    deque<int> dq;
    rep(i,N) {
        int v;cin>>v;
        dq.push_back(v);
    }
    int ans = 0;
    rep(l,N+1)rep(r,N+1){
        if(l+r>N||l+r>K) continue;
        int k = max(K-(l+r),0);
        deque<int> d;
        d = dq;
        vec<int> v;
        rep(i,l){
            v.push_back(d.front());
            d.pop_front();
        }
        rep(i,r){
            v.push_back(d.back());
            d.pop_back();
        }
        sort(all(v));
        int tmpans = accumulate(all(v),0);
        rep(i,min(k,(int)v.size())) if(v[i]<0) tmpans-=v[i];
        ans = max(ans,tmpans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define N 100010
ll n,m,q;
ll a[N],b[N],c[N];
namespace uf{
    ll p[N],s[N];
    void init(){
        for(int i=0;i<N;i++){
            p[i]=i,s[i]=1;
        }
    }
    ll par(ll x){
        return p[x]=(p[x]==x?x:par(p[x]));
    }
    void unite(ll a,ll b){
        a=par(a),b=par(b);
        if(a==b)return;
        s[a]+=s[b];
        p[b]=a;
    }
    bool same(ll a,ll b){
        a=par(a),b=par(b);
        return a==b;
    }
};

int main(){
  cin>>n>>m>>q;
  uf::init();
  for(int i=0;i<q;i++){
      cin>>a[i]>>b[i]>>c[i];
      if(c[i]==0){
          uf::unite(a[i],b[i]);
      }
  }
  ll cnt=0;
  for(int i=0;i<n;i++){
      if(uf::p[i]==i){
          cnt++;
      }
  }
  bool ok=1,th=0;
  for(int i=0;i<q;i++){
      if(c[i]==1){
          th=1;
          if(uf::same(a[i],b[i])){
              ok=0;
          }
      }
  }
  if(cnt==1){
      if(n-1==m&&ok)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }
  if(cnt==2){
      if(n-1==m&&th==0&&ok)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }
  if(cnt>=3){
      bool ans=0;
      if(cnt*(cnt-1)/2-(cnt-1)>=m-(n-1)&&ok){
          if(th==1&&m==n-1)ans=0;
          else ans=1;
      }
      if(ans)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 4224
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)[:X]
q = sorted(list(map(int, input().split())), reverse=True)[:Y]
r = sorted(list(map(int, input().split())), reverse=True)[:X+Y]
pqr = sorted(p+q+r, reverse=True)
print(sum(pqr[:X+Y]))


Measured memory_bytes: 111212
$s = 0
$heap = []

def max_heapify(i)
    l = i * 2
    r = l + 1

    if (l <= $s) && ($heap[i] < $heap[l])
        maxi = l
    else
        maxi = i
    end

    if (r <= $s) && ($heap[maxi] < $heap[r])
        maxi = r
    end

    if maxi != i
        $heap[i], $heap[maxi] = $heap[maxi], $heap[i]
        max_heapify(maxi)
    end
end

def heap_increase(v)
    $s += 1
    $heap[$s] = v
    i = $s
    while (i > 1) && ($heap[i/2] < $heap[i])
        $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
        i /= 2
    end
end

def heap_extract
    max = $heap[1]
    $heap[1] = $heap[$s];
    $s -= 1
    max_heapify(1)
    max
end

while cmd = gets.chomp do
    if cmd == "end"
        break
    end

    if cmd == "extract"
        puts heap_extract
    else
        c = cmd.split[1].to_i
        heap_increase(c)
    end
end


Measured memory_bytes: 16376
#include <iostream>
#include <vector>

using namespace std;

struct UnionFind {
    vector<int> par;
    
    UnionFind(int N) : par(N) {
        for(int i=0; i<N; i++) {
            par[i] = i;
        }
    }
    
    int root(int x) {
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    
    void unite(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }
    
    bool same(int x, int y) {
        int rx=root(x);
        int ry=root(y);
        if(rx==ry) return true;
        else return false;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    
    vector<int> p(N);
    for(int n=0; n<N; n++) {
        cin >> p[n];
    }
    
    for(int m=0; m<M; m++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }
    
    int ans=0;
    for(int n=0; n<N; n++) {
        if(tree.same(n, p[n]-1)) {
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		double a = scanner.nextDouble();
		double b = scanner.nextDouble();
		double degree = scanner.nextDouble();

		double S = 0.5*a*b*Math.sin(Math.PI*degree/180.0);
		double c = Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.PI*degree/180.0));

		System.out.printf("%.10f\n",S);
		System.out.printf("%.10f\n", a+b+c);
		System.out.printf("%.10f\n", 2*S/a);
	}
}


Measured memory_bytes: 28204
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    cout << A * B / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vdebug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    string s;
    cin >> s;
    set<char> use;
    int slen = s.length();
    rep(i, slen){
        use.insert(s[i]);
    }

    if(use.size() == 1){
        cout << 0 << endl;
        return 0;
    }

    int res = 1e6;
    for(auto const& e : use){
        string bufs = s;
        int cnt = 0;
        while(true){
            string news = "";
            rep(i, bufs.length()-1){
                if(bufs[i] == e || bufs[i+1] == e){
                    news += e;
                }else{
                    news += bufs[i];
                }
            }
            bool good = true;
            rep(i, news.length()){
                if(news[i] != e){
                    good = false;
                    break;
                }
            }
            cnt++;
            if(good) break;
            bufs = news;
        }
        chmin(res, cnt);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, s; cin >> n >> s;
  if (n < s) {
    cout << -1 << endl;
    return 0;
  }
  if (n == s) {
    cout << n+1 << endl;
    return 0;
  }

  for(ll b=2; b*b<=n; b++) {
    ll cnt = 0;
    auto tmp = n;
    while(tmp) {
      cnt += tmp%b;
      tmp /= b; 
    }
    if (cnt==s) {
      cout << b << endl;
      return 0;
    }
  }

  ll ans = LLONG_MAX;
  for(ll p=1; p*p<n; p++) {
    ll b = (n-s)/p + 1;
    if (b <= n/b) continue;
    ll cnt = 0;
    auto tmp = n;
    while(tmp) {
      cnt += tmp%b;
      tmp /= b;
    }
    if (cnt == s) chmin(ans, b);
  }

  if (ans == LLONG_MAX) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


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

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

  int C[N - 1], S[N - 1], F[N - 1];
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  int ans[N] = {0};

  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j <= i; j++) {
      if (ans[j] < S[i]) {
        ans[j] = S[i];
      }
      else {
        int tmp = ans[j] % F[i];
        if (tmp) {
          ans[j] += F[i] - tmp;
        }
      }
      ans[j] += C[i];
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << "\n";
  }
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - K-th Common Divisor
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b, k;
  scanf("%d%d%d", &a, &b, &k);

  int d = min(a, b);
  for (int c = 0;; d--)
    if (a % d == 0 && b % d == 0 && ++c >= k) break;
  printf("%d\n", d);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int len = s.length();
	int ans = len;
	for (int i = 0; i < len; i++) {
		if (s[i] != s[i + 1])
			ans = min(ans,max(i+1,len-i-1));
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
def merge(A, left, mid, right):
    global count
    L = A[left:mid] + [1000000001]
    R = A[mid:right] + [1000000001]
    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
    count += right - left


def merge_sort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)

N = int(input())
A = list(map(int, input().split()))
count = 0
merge_sort(A, 0, N)
print(*A)
print(count)

Measured memory_bytes: 63780
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K, C = lr()
S = sr()
# 左からと右からでそれぞれ貪欲、重なったところが必須
left = []; right = []

def work(S):
    ret = []
    cur = 0
    count = 0
    while count < K:
        if S[cur] == 'o':
            count += 1
            ret.append(cur)
            cur += C + 1
        else:
            cur += 1
    return ret

left = work(S)
right = work(S[::-1])
right = [N-1-x for x in right]
right.reverse()
answer = []
for l, r in zip(left, right):
    if l == r:
        answer.append(str(l+1))
print('\n'.join(answer))


Measured memory_bytes: 41388
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main()
{
	int n, m, p, d[10004],ans,a,b;
	cin >> n >> m >> p;
	int i;
	for (i = 0; i < m; i++){
		cin >> d[i];
	}
	if (m == 1){
		ans = min((d[0] - p + n) % n, (p - d[0] + n) % n);
		goto last;
	}
	sort(begin(d), begin(d) + m);
	if (d[m-1] - p < 0){
		a = d[m-1] - p + n;
	}
	else{
		a = d[m-1] - p;
	}
	if (p - d[0] < 0){
		b = p - d[0] + n;
	}
	else{
		b = p - d[0];
	}
	ans = min(a, b) * 2 + max(a, b);
	if (d[m-1] <= p&&p <= d[0]){
		if (ans>n - (p - d[m-1])){
			ans = n - (p - d[m-1]);
		}
		if (ans>n - (d[0] - p)){
			ans = n - (d[0] - p);
		}
	}
	if (d[m - 1] > d[0]){
		if (d[m - 1]<p){
			if (ans>n - (p-d[m - 1])){
				ans = n - (p-d[m - 1]);
			}
		}
		if (d[0] > p){
			if (ans > n - (d[0]-p)){
				ans = n - (d[0]-p);
			}
		}
	}
	for (i = 0; i < m-1; i++){
		if (d[i] - p < 0){
			a = d[i] - p + n;
		}
		else{
			a = d[i] - p;
		}
		if (p - d[i + 1] < 0){
			b = p - d[i + 1] + n;
		}
		else{
			b = p - d[i + 1];
		}
		if (ans>min(a, b) * 2 + max(a, b)){
			ans = min(a, b) * 2 + max(a, b);
		}
		if (d[i] <= p&&p <= d[i + 1]){
			if (ans>n - (p - d[i])){
				ans = n - (p - d[i]);
			}
			if (ans>n - (d[i + 1] - p)){
				ans = n - (d[i + 1] - p);
			}
		}
		if (d[i] > d[i + 1]){
			if (d[i]<p){
				if (ans>n - (p-d[i])){
					ans = n - (p-d[i]);
				}
			}
			if (d[i + 1] > p){
				if (ans > n - (d[i + 1]-p)){
					ans = n - (d[i + 1]-p);
				}
			}
		}
	}
	last:
	cout << ans * 100 << endl;



	return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef unsigned us;
typedef unsigned long long ull;
//typedef long long ll;
using namespace std;

const int N=200005;

int n,p1,p2,pos[N],num,ll,rr,o,tr[2][N*4],a[N],x,y,l,r;
priority_queue<pair<pair<int,int> ,pair<pair<int,int>,int> > ,vector<pair<pair<int,int> ,pair<pair<int,int>,int> > >,greater<pair<pair<int,int> ,pair<pair<int,int>,int> > > > q;


void build(int l,int r,int now,int o) {
	if (l==r) {
		if (o) {
			if (l%2==1) tr[o][now]=a[l];else tr[o][now]=1<<30; 
		}else {
			if (l%2==0) tr[o][now]=a[l];else tr[o][now]=1<<30;

		}
		return;
	}
	int mid=(l+r)>>1;
	build(l,mid,now*2,o);
	build(mid+1,r,now*2+1,o);
	tr[o][now]=min(tr[o][now*2],tr[o][now*2+1]);
}

void ask(int l,int r,int now,int o) {
	if (ll<=l && rr>=r) {
		num=min(tr[o][now],num); 
		return;
	}
	int mid=(l+r)>>1;
	if (ll<=mid) ask(l,mid,now*2,o);
	if (rr>mid) ask(mid+1,r,now*2+1,o);
}


void work(int l,int r,int o) {
	ll=l;rr=r;num=1<<20;
	ask(1,n,1,o);
}

int main(){
	scanf("%d",&n);
//	n=200000;
	rep(i,1,n+1) scanf("%d",&a[i]),pos[a[i]]=i;
	build(1,n,1,1);
	build(1,n,1,0);
	work(1,n,1);cout<<num<<' ';p1=pos[num];
	work(p1+1,n,0);p2=pos[num];cout<<num<<' ';
	if (p1>1) {
		work(1,p1-1,1);x=num;work(pos[x]+1,p1-1,0);y=num;
		q.push(mp(mp(x,y),mp(mp(1,p1-1),1)));
	}
	if (p2<n) {
		work(p2+1,n,1);x=num;work(pos[x]+1,n,0);y=num;
		q.push(mp(mp(x,y),mp(mp(p2+1,n),1)));
	}
	if (p1+1<p2) {
		work(p1+1,p2-1,0);x=num;
		work(pos[x]+1,p2-1,1);y=num;
		q.push(mp(mp(x,y),mp(mp(p1+1,p2-1),0)));
	}
	int cnt=0;
	while (sz(q)) {
		x=q.top().fi.fi;y=q.top().fi.se;
		cout<<x<<' '<<y<<' ';
		l=q.top().se.fi.fi;r=q.top().se.fi.se;o=q.top().se.se;
		p1=pos[x];p2=pos[y];
		q.pop();
		if (p1>l+1) {
			work(l,p1-1,o);x=num;work(pos[x]+1,p1-1,o^1);y=num;
			q.push(mp(mp(x,y),mp(mp(l,p1-1),o)));
		}
		if (p2<r-1) {
			work(p2+1,r,o);x=num;work(pos[x]+1,r,o^1);y=num;
			q.push(mp(mp(x,y),mp(mp(p2+1,r),o)));
		}
		if (p1+1<p2-1) {
			work(p1+1,p2-1,o^1);x=num;
			work(pos[x]+1,p2-1,o);y=num;
			q.push(mp(mp(x,y),mp(mp(p1+1,p2-1),o^1)));
		}
	//	cnt++;if (cnt==(n/2-1)) return 0;
	}	
}

Measured memory_bytes: 9332
# soundhound2018-summer-qualC - Ordinary Beauty
def main():
    N, M, D = map(int, open(0).read().split())
    x = 2 if D else 1
    ans = x * (N - D) * (M - 1) / (N * N)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			 int sam ;
			 int check ;
			 
			
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			// スペース区切りの整数の入力
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();

	    		 check = ( a * 100  + b * 10  + c) % 4 ;
	    		 if(check != 0 ){
		       		// 出力
		        	System.out.println("NO");
		        	return ;
	    	     }

    		 // 出力
			System.out.println("YES");
		}
}


Measured memory_bytes: 22868
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  int cs[30]={},ct[30]={};
  cin >> s >> t;
  for(int i=0; i<s.size(); i++) {
    cs[s[i]-'a']++;
    ct[t[i]-'a']++;
  }
  sort(cs,cs+26);
  sort(ct,ct+26);
  for(int i=0; i<26; i++) {
    if(cs[i]!=ct[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 916