akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];

  vector<ll> idx(n);
  rep(i,n) idx[A[i]-1]=i;

  set<ll> S{-1,n};
  ll ans=0;
  rep(p,n){
    ll i=idx[p];
    auto it1=S.insert(i).first;
    auto it2=it1;
    it1--; it2++;
    ll prev=*it1, next=*it2;
    // cerr<<p<<' '<<prev<<' '<<next<<endl;
    ans+=(p+1)*(i-prev)*(next-i);
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 12800
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int a = Cin.Ni();
        int b = Cin.Ni();
        int c = Cin.Ni();

        Console.WriteLine(b - a == c - b ? "YES" : "NO");
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    string s, yaki = "YAKI";
    cin >> s;
    string res = "Yes";
    if(s.size()>3){
        rep(i, 4){
            if(s[i]!=yaki[i]){
                res = "No";
                break;
            }
        }
    }else{
        res = "No";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
<?php
$max = "";

$strs = explode(" ", trim(fgets(STDIN)));
foreach($strs as $str) {
    strlen($max) < strlen($str) && $max = $str;
}
$cnts = array_count_values($strs);
arsort($cnts);

echo key($cnts), " ", $max, PHP_EOL;

Measured memory_bytes: 15272
counter = 0
def myAnswer(H:list) -> int:
   global counter
   if len(H) is 0:return
   if len(H) is 1:
      counter = counter + H[0]
      return
   m = min(H)
   counter += m
   H = [i - m for i in H]
   while 0 in H:
      length = len(H[:H.index(0)])
      myAnswer(H[:H.index(0)])
      H = H[H.index(0)+1:]
   myAnswer(H)


def modelAnswer():
   return
def main():
   N = int(input())
   H = list(map(int,input().split()))
   myAnswer(H[:])
   print(counter)
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
line = gets.split(' ').map(&:to_i)
n = line[0]
d = line[1]

lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end
kazu = 0
for i in 0..n-1 do
  for j in 0..n-1 do
    if i == j then
      break
    end
    g = 0
    for k in 0..d-1 do
      g+=(lines[i][k]-lines[j][k])**2
    end
    g = g**0.5
    aho = g.ceil
    if g == aho then
      kazu+=1
    end
  end
end
puts kazu

Measured memory_bytes: 3836
#include<iostream>
using namespace std;
int main()
{
	int x,y,z;
	cin>>x>>y>>z;
	for(int i=1;i<=z;i++)
	{
		if(i%2!=0)
		{
			if(x%2!=0)
			{
				x=x-1;
			}
			else
			x=x;
			x=x/2;
			y=y+x;
		}
		else
		{
			if(y%2!=0)
			y=y-1;
			else
			y=y;
			y=y/2;
			x=x+y;
		}
	} 
	cout<<x<<" "<<y;
} 

Measured memory_bytes: 256
while 1:
    h,w = map(int,input().split())
    if h==0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if (i+1) % 2 != 0:

                if (j+1) % 2 ==0:
                    print(".",end="")
                else:
                    print("#",end="")
            else:
                if (j+1) % 2 !=0:
                    print(".",end="")
                else:
                    print("#",end="")
        print("")
    print("")



Measured memory_bytes: 7016
#include <iostream>
#include <vector>
#include <algorithm>
#define GRID_SIZE 100

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int w, b; cin >> w >> b;
	vector<vector<char>> ans(GRID_SIZE, vector<char>(GRID_SIZE, '.'));
	for (int row = 0; row < GRID_SIZE; ++row) {
		for (int col = 0; col < GRID_SIZE/2; ++col) {
			ans[row][col] = 'B';
			ans[row][col + GRID_SIZE/2] = 'W';
		}
	}
	--w; --b;
	for (int row = 0; row < GRID_SIZE; row += 2) {
		for (int col = 0; col < GRID_SIZE/2; col += 2) {
			if (w == 0) {
				break;
			} else {
				ans[row][col] = 'W';
				--w;
			}
		}
	}
	for (int row = 0; row < GRID_SIZE; row += 2) {
		for (int col = GRID_SIZE/2 + 1; col < GRID_SIZE; col += 2) {
			if (b == 0) {
				break;
			} else {
				ans[row][col] = 'B';
				--b;
			}
		}
	}
	cout << GRID_SIZE << " " << GRID_SIZE << endl;
	for (int i = 0; i < GRID_SIZE; ++i) {
		for (int j = 0; j < GRID_SIZE; ++j) {
			cout << (ans[i][j] == 'W' ? '.' : '#');
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3
#ABC116 C

n = int(input())
h = list(map(int,input().split()))
ans = 0
while sum(h) != 0:
    front = False
    for i in range(n):
        if h[i] > 0:
            if not front:
                ans += 1
            front = True
            h[i] -= 1
        else:
            front = False
print(ans)


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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {int z=s[i]+n;char s1;
    if(z>90)
        {z=z-90+64;
            s1=z;
        cout<<s1;}
        else
            {s1=s[i]+n;
        cout<<s1;}
    }
    return 0;
}


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

vector<string> vec;
void func(int t,string s,int n) {
  if (t<n) {
    func(t+1,s,n);
    string p =s.insert(s.size()-1+t-(n-1),"+");
    func(t+1,p,n);
  }
  else if (t==n) {
    vec.push_back(s);
  }
}
int main() {
  string s;cin>>s;
  int n=s.size();
  long long sum=0;
  func(1,s,n);
  for (int i=0;i<pow(2,s.size()-1);i++) {
    long long a=0;
    for (int j=0;j<vec.at(i).size();j++) {
      if (vec.at(i)[j]!='+') {
        a=a*10+(vec.at(i)[j]-'0');
        if (j==vec.at(i).size()-1) {
          sum+=a;   
        }  
      }
      else {
        sum+=a;
        a=0;
      }
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

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

    int ans = max(0, c-a+b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <string>
#include <string.h>
#include <iomanip>
#include <cmath>
#define ll long long
#define PI 3.14159265358979323846
#define lp(i, n) for (int i = 0; i < n; i++)
#define rep(i, v) for (int i = 0; i < int(v.size()); i++)
using namespace std;
vector<ll> div(ll n)
{
	vector<ll> v;
	for(int i=1;i<=sqrt(n);i++){
		if(n%i==0)
				v.push_back((i+n/i)-2);
	}
	return v;
}		
int main()
{
	ll n;
	vector<ll> v;
	cin>>n;
	v=div(n);
	sort(v.begin(),v.end());
	cout<<v.front();
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
#include<cmath>
#include<complex>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

kz gcd(kz a,kz b) { if(b==0) return a; else gcd(b,a%b); }

bool pr(int n) {
    int i=2;
    while (i*i<=n) {
        if (n%i==0) return false;
        i++;
    }
    return true;
}

int main(){
    int mod=1000000007;
    bool b[111111]={0};
    for (int i=2;i<111111;++i) {
        b[i]=pr(i);
    }
    int n;
    for (;;) {
        scanf("%d",&n);
        if (n==0) break;
        int ans=0,cnt=0;
        for (int i=2;cnt<n;++i) {
            if (b[i]) {
                ans+=i;
                cnt++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

int main(){
long N;
cin >> N;
vector<long> p(N+1);
erep(i, N) cin >> p[i];
long cnt = 0;
erep(i, N-2){
    if(((p[i] > p[i+1]) && (p[i+1] > p[i+2])) || 
    ((p[i] < p[i+1]) && (p[i+1] < p[i+2]))){
        cnt++;
    }
}
show(cnt);

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,N;
  cin >> K >> N;
  
  /*
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A.at(i);
  }
  
  int tmp = 0;
  for (int i=0; i<N-1; i++) {
    if (tmp < (A.at(i+1)-A.at(i))) {
      tmp = (A.at(i+1)-A.at(i));
    }
  }

  if (tmp < A.at(0)+(K-A.at(N-1))) {
    tmp = A.at(0)+(K-A.at(N-1));
  }
  
  cout << tmp << endl;
  */
  
  int A0;
  int Anow;
  int Aprev;
  
  int ans;
  
  cin >> A0;
  Anow = A0;
  
  for (int i=0; i<N-1; i++) {
    Aprev = Anow;
    cin >> Anow;
    if (ans < Anow-Aprev) {
      ans = Anow-Aprev;
    }
  }
  if (ans < A0+K-Anow) {
    ans = A0+K-Anow;
  }
  
  cout << K - ans << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
int main() {
	int n,a[1000],ans=mod,mn,i,j;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=1;i<=100;i++)
	{
		mn=0;
		for(j=0;j<n;j++)
			mn+=pow(a[j]-i,2);
		ans=min(ans,mn);
	}
	cout<<ans;
	
}

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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int>l(N);
  for(int i = 0; i < N; i++){
    cin >> l.at(i);
  }
  
  sort(l.begin(), l.end(), greater<int>());
  int length = 0;
  for(int i = 0; i < K; i++){
    length += l.at(i);
  }
  cout << length << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<functional>

using namespace std;

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

int N, X;

int main() {
	cin >> N >> X;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	int now = 0;
	int ans = 1;
	for (int i = 0; i < N; i++) {
		now += L[i];
		if (now <= X) { ans++; }
		else { break; }
	}
	cout << ans << endl;
}

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

cnt1=0
cnt2=0
for i in range(N):
    if S[i]=="a" and cnt1<(A+B):
        print("Yes")
        cnt1+=1
    elif S[i]=="b":
        if cnt1<(A+B) and cnt2<B:
            print("Yes")
            cnt1+=1
            cnt2+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4708
n = int(input())
A = list(map(int, input().split()))
num = [i for i in range(n)]
B = [0]*(n)
C = []
ans = 0
for i in range(n-1, -1, -1):
  ms = sum(B[i::i+1])
  if ms % 2 != A[i]:
    ans += 1
    C.append(i+1)
    B[i] = 1
print(ans)
print(*C)

Measured memory_bytes: 21180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

int main(void) {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    for(int i=0; i<N; i++) {
        cin >> x[i];
        x[i] -= A;
    }

    int tmp = 1000;
    vector< vector<int64_t> > v(N+1, vector<int64_t>(2000));
    v[0][tmp] = 1;
    for(int i=0; i<N; i++) {
        for(int j=0; j<2000; j++) {
            v[i+1][j] += v[i][j];
            int next = j + x[i];
            if(next < 0 || next >= 2000) continue;
            v[i+1][next] += v[i][j];
        }
    }

    cout << v[N][tmp] - 1 << endl;
    return 0;
}


Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    // 前処理
    COMinit();
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    // sum(max-min) = sum(max) - sum(min)
    ll s_max = 0;
    for(int i=0;i<N;i++){
        if(i<K-1)continue;
        s_max+=A[i]*COM(i,K-1);
        s_max%=MOD;
    }
    ll s_min = 0;
    for(int i=0;i<N;i++){
        if(N-i<K)continue;
        s_min+=A[i]*COM(N-i-1,K-1);
        s_min%=MOD;
    }
    ll ans = s_max + MOD - s_min;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15848
import sys; sys.setrecursionlimit(50000)
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = sorted(map(int, input().split()), reverse=True)
B = sorted(map(int, input().split()), reverse=True)
C = sorted(map(int, input().split()), reverse=True)

result = []
for x in range(X):
    for y in range(Y):
        if x * y > K: break
        for z in range(Z):
            if x * y * z > K: break
            result.append(A[x]+B[y]+C[z])
            
for i in sorted(result, reverse=True)[:K]:
    print(i)


Measured memory_bytes: 130620
<?php
define('MOD', 10 ** 9 + 7);
list($n, $m) = ints();
if ($n < $m) list($n, $m) = [$m, $n];
if ($n - $m > 1) exit('0');
if ($n - $m === 1) {
    echo modmul(modFac($n), modFac($m));
    // nの間（両端含む）n+1個のうちm個を選ぶ、選んだ場所に並べる
} elseif ($n - $m === 0) {
    echo modMul(2, modmul(modFac($n), modFac($m)));
}

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modDiv(modFac($n), modFac($n - $r));
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}


Measured memory_bytes: 43512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <stack>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    int r, c, n, x[112345][2], y[112345][2];

    cin >> r >> c >> n;

    vector<P> v[4];

    REP(i, n)
    {
        cin >> x[i][0] >> y[i][0] >> x[i][1] >> y[i][1];

        if ((0 < x[i][0] && x[i][0] < r && 0 < y[i][0] && y[i][0] < c) ||
            (0 < x[i][1] && x[i][1] < r && 0 < y[i][1] && y[i][1] < c))
            continue;

        if (y[i][0] == 0)
            v[0].push_back({x[i][0], i});
        else if (x[i][0] == r)
            v[1].push_back({y[i][0], i});
        else if (y[i][0] == c)
            v[2].push_back({-x[i][0], i});
        else
            v[3].push_back({-y[i][0], i});

        if (y[i][1] == 0)
            v[0].push_back({x[i][1], i});
        else if (x[i][1] == r)
            v[1].push_back({y[i][1], i});
        else if (y[i][1] == c)
            v[2].push_back({-x[i][1], i});
        else
            v[3].push_back({-y[i][1], i});
    }

    for (int i = 0; i < 4; i++)
        SORT(v[i]);

    V w;

    for (int i = 0; i < 4; i++)
        for (P j : v[i])
            w.push_back(j.second);

    bool res = true;

    stack<int> s;
    bool used[112345];
    fill(used, used + n, false);

    for (int i : w)
    {
        if (used[i])
        {
            if (i != s.top())
            {
                res = false;
                break;
            }

            s.pop();
        }
        else
        {
            s.push(i);
            used[i] = true;
        }
    }

    cout << (res ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 5352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1e5+5;
int main()
{
	int a,b,c;
	scanf("%d/%d/%d",&a,&b,&c);
	printf("2018/%02d/%02d",b,c);
	return 0;
} 

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int n; cin >> n;
    vector<int> A;
    rep(i,n){
        A.push_back(i+1);
    }
    sort(A.begin(), A.end());
    do{
        rep(i,n){
            cout << A[i];
            if(i != n-1) cout << " ";
        }
        cout << endl;
    }while(next_permutation(A.begin(), A.end()));
}


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

int main(){
    int n;
    cin >> n;
    vector<int> hp;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        hp.push_back(x);
    }
    sort(hp.begin(), hp.end());
    int ans = hp[0];
    int ans_kari = hp[0];
    while(n > 1){
        ans = hp[0];
        for(int i = 1; i < n; i++){
            hp[i] %= ans;
            if(hp[i] == 0){
                hp.erase(hp.begin() + i);
                n--;
            }else{
                sort(hp.begin(), hp.end());
                break;
            }

        }
        sort(hp.begin(), hp.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 892
#include<cstdio>
#include<algorithm>

using namespace std;

const long long inf = 1e15;

long long mul(long long a, long long b){
	if(a == 0 || b == 0) return 0;
	long long tmp = inf / a;
	if(tmp <= b) return inf;
	long long x = a * b;
	return min(x, inf);
}

long long ex(long long a, int e){
	if(e == 0) return 1;
	long long tmp = ex(a, e / 2);
	tmp = mul(tmp, tmp);
	if(e % 2 == 1) tmp = mul(tmp, a);
	return tmp;
}

long long N, A;

long long solve(){
	long long ans = N;
	for(int n = 2; n <= 40; ++n){
		long long lb = 1, ub = N;
		while(ub - lb > 1){
			long long mid = (ub + lb) / 2;
			long long val = ex(mid, n);
			if(val <= N) lb = mid;
			else ub = mid;
		}
		if(lb == 1) continue;
		else{
			long long x = lb, y = lb + 1;
			int lb = -1, ub = n;
			while(ub - lb > 1){
				int mid = (ub + lb) / 2;
				long long val = mul(ex(x, n - mid), ex(y, mid));
				if(val >= N){
					ub = mid;
				}else{
					lb = mid;
				}
			}
			long long tmp = x * (n - ub) + y * ub + A * (n - 1);
			ans = min(ans, tmp);
		}
	}
	return ans;
}

int main(){
	scanf("%lld%lld", &N, &A);
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PPQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }



int main(){
    ll n,t;
    cin >> n >> t;
    ll a[n],b[n];
    rep(i,0,n) cin >> a[i] >> b[i];
    ll dp[2][n+1][t+1];
    rep(i,0,2) rep(j,0,n+1) rep(k,0,t+1) dp[i][j][k] = 0;

    rep(i,0,n){
        rep(j,0,t){
            // 0 -> 0
            dp[0][i+1][j] = max(dp[0][i+1][j],dp[0][i][j]);
            if(j+a[i] <= t) dp[0][i+1][j+a[i]] = max(dp[0][i+1][j+a[i]],dp[0][i][j]+b[i]); 

            // 1 -> 1
            dp[1][i+1][j] = max(dp[1][i+1][j],dp[1][i][j]);
            if(j+a[i] <= t) dp[1][i+1][j+a[i]] = max(dp[1][i+1][j+a[i]],dp[1][i][j]+b[i]); 

            // 0 -> 1
            dp[1][i+1][j] = max(dp[1][i+1][j],dp[0][i][j]+b[i]);
        }
    }

    ll ans = 0;
    rep(i,0,t){
        ans = max(ans,dp[1][n][i]);
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 144404
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;

int main(){
	ll n; cin>>n;
	string rta = "";
	while(n>0){
		n--;
		ll x = n%26;
		rta+=('a'+x);
		n/=26;	
	}
	reverse(rta.rbegin(), rta.rend());
	cout<<rta<<endl;
	return 0;
}


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

int main()
{

ll n ; 
cin>>n;

std::vector<char> ans ;

while(n)
{
    n--;
    ans.push_back('a'+n%26);
    n/=26;
}

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


Measured memory_bytes: 3560
use std::io;
use std::str::FromStr;
use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::cmp::max;

#[derive(Eq, PartialEq, Debug)]
struct Cost {
    value: u64,
    difficulty: u64,
}

impl Ord for Cost {
    fn cmp(&self, other: &Cost) -> Ordering {
        other.value.partial_cmp(&self.value).unwrap()
    }
}

impl PartialOrd for Cost {
    fn partial_cmp(&self, other: &Cost) -> Option<Ordering> {
        self.value.partial_cmp(&other.value)
    }
}

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn binary_search<F>(mut ok: i64, mut ng: i64, is_ok: F) -> i64
    where
        F: Fn(i64) -> bool
    {
        while (ok - ng).abs() > 1 {
            let mid = (ok + ng) / 2;
            if is_ok(mid) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        ok
}

fn main () {
    let (n, k) = input_tuple();
    let mut a_vec = input_vec();
    let mut f_vec = input_vec();

    a_vec.sort();
    f_vec.sort_by(|x, y| y.cmp(&x));
    
    let mut tmp_max = 0;
    for i in 0..n as usize {
        tmp_max = max(a_vec[i] * f_vec[i], tmp_max);
    }

    let ans = binary_search(tmp_max as i64, -1, |x| {
        let mut sum = 0;
        for i in 0..n as usize {
            if a_vec[i] * f_vec[i] > x as u64 {
                sum += a_vec[i] - x as u64 / f_vec[i];
            }
        }
        // println!("{}, {}", x, sum);
        sum <= k 
    });
    println!("{}", ans);
    
}

Measured memory_bytes: 7752
n = input()
card = []
for i in range(n):
    card.append(raw_input())

for a in ['S','H','C','D']:
    for b in range(1,14):
        check = a +  " " + str(b)
        for c in card:
            if check == c:
                flg = 0
                break
            else:
                flg = 1
        if flg == 1:
            print check

Measured memory_bytes: 4212
eval'H,W='+gets.split*?,
B=$<.map(&:chop)*?#+?#*W+=1
*Q=i=0
d=B.count ?.
p loop{(d-=1
i+=Q.size)if-1==i-=1
break d if H*W<3+k=Q.shift
[-W,-1,W,1].map{|l|B[l+=k][B[l]=?#]||Q<<l}}rescue p~0

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  vector<int> v(5);
  vector<int> mod(5);
  for (int m=0; m < 5; m++) {
    cin >> v.at(m);
    mod.at(m)=10-(v.at(m)%10);
    if (v.at(m)%10==0) mod.at(m)=0;
  }
  int max=0;
  for (int i=0; i<5;i++){
    if (max < mod.at(i) ) max=v.at(i);
  }
  sort(mod.begin(),mod.end());
  int ans=0;
  for (int i=0; i<5;i++){
    ans+=v.at(i);
    if (i!=4) ans+=mod.at(i);
  }
  cout << ans << endl;
  return 0;
}

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

int n,m;
char c[55][55];

int f(int x,int y)
{
	int t=0;
	if(x-1>=0&&c[x-1][y]=='#') t++;
	if(y-1>=0&&x-1>=0&&c[x-1][y-1]=='#') t++;
	if(x-1>=0&&y+1<m&&c[x-1][y+1]=='#') t++;
	if(y-1>=0&&c[x][y-1]=='#') t++;
	if(y+1<m&&c[x][y+1]=='#') t++;
	if(x+1<n&&y-1>=0&&c[x+1][y-1]=='#') t++;
	if(x+1<n&&c[x+1][y]=='#') t++;
	if(x+1<n&&y+1<m&&c[x+1][y+1]=='#') t++;
	return t;	 
}

int main()
{
    cin>>n>>m;
    for(int i=0;i<n;++i) for(int j=0;j<m;++j) cin>>c[i][j];
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<m;++j)
			if(c[i][j]=='.')
				cout<<f(i,j);
			else cout<<c[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1n(i,n) for(int i=1; i<=(n); ++i)
#define repxn(i,x,n) for(int i=x; i<=(n); ++i)
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define INF 1001001001  // 浮動小数点型
#define INF_L 1001001001001001001  // 浮動小数点型
#define bit(n,m)(((n)>>(m))&1)  // nのmビット目が1
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int n = 200000;
Graph g(n);
vector<bool> seen(n, false);
int an = 1;

void dfs(int i){
    if(seen[i]) return;
    seen[i] = true;
    for(auto next : g[i]){
        if(seen[next]) continue;
        an++;
        dfs(next);
    }
}

int main() {
    int n2, m; cin >> n2 >> m;
    rep(i,m){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].pb(b); g[b].pb(a);
    }
    int ans = 1;
    rep(i,n) {
        an = 1;
        dfs(i);
        ans= max(ans,an);
    }
    cout << ans << endl;
}

/*
g++ d.cpp
./a.out

oj d
oj t

debug:ctrl+shift+B problemin

*/


Measured memory_bytes: 20248
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()

alp = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')

s_t = ''
for x in s:
  s_t += alp[(alp.index(x) + n) % 26]
  
print(s_t)

Measured memory_bytes: 3060
#include <string.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define REP1(i,n) for(int i=1;i<=(n);++i)

#define SORT(V) sort((V).begin(), (V).end())

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

int N, K, L;
int a[2000001];
int b[2000001];
int p[1000001];
int q[1000001];
int rs[2000001];

int root(int* a, int x) {
  if (a[x] == x) {
    return x;
  } else {
    return a[x] = root(a, a[x]);
  }
}

void unite(int*a, int x, int y) {
  x = root(a, x);
  y = root(a, y);
  if (x == y) return;
  a[x] = y;
}

int main() {
  cin >> N >> K >> L;
  REP1(i, N) {
    a[i] = i;
    b[i] = i;
  }
  REP(i, K) {
    int p, q;
    cin >> p >> q;
    unite(a, p, q);
  }
  //cout << "hoge\n";
  //  REP1(i, N) {cout << a[i].root << endl;}
  REP(i, L) {
    int p, q;
    cin >> p >> q;
    unite(b, p, q);
  }
  // return 0;
  //  REP1(i, N) cout << rs[i] << endl;
  map<pair<int, int>, int> c;
  REP1(i, N) {
    c[make_pair(root(a, i), root(b, i))]++;
  }
  REP1(i, N) {
    cout << c[make_pair(root(a, i), root(b, i))] << " ";
  }
  cout << endl;
}


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

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

	int K;
	cin>>K;

	int g1,res;
	ll sum = 0;

	for(int a = 1;a<=K;a++)
		for(int b = 1;b<=K;b++)
			for(int c = 1;c<=K;c++)
			{
				g1 = __gcd(a,b);
				res = __gcd(g1,c);
				sum += res;
			}


	cout<<sum<<endl;	

	return 0;
}

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

int main()
{
  long long A, B;
  cin >> A >> B;
  for (int i = 1; i <= B; i++) {
    if ((A * i) % B == 0) {
      cout << A * i << endl;
      break;
    }
  }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
using namespace std;
int a[31][31],co[4],d[31][31][5];
typedef pair<int,pair<int,int> > P;
int dx[]={0,1,0,-1},dy[]={-1,0,1,0},w,h;
P lp;
int main(){
  while(cin>>w>>h,w){
    r(i,31)r(j,31)r(k,5)d[i][j][k]=1e9;
    r(i,h)r(j,w){
      cin>>a[i][j];
      if(a[i][j]!=4)a[i][j]=(a[i][j]+1)%4;
    }
    r(i,4)cin>>co[(i+1)%4];
    priority_queue<P,vector<P>,greater<P> >q;
    d[0][0][1]=0;
    lp.fi=0,lp.se.fi=0,lp.se.se=1;
    q.push(lp);
    while(!q.empty()){
      P p=q.top();q.pop();
      int x=p.se.fi%100,y=p.se.fi/100,v=p.se.se;
      r(i,5){
        if(i==4){if(d[y][x][4]>p.fi)d[y][x][4]=p.fi;}
        else{
          int vv=(v+3+i)%4;
          int xx=x+dx[vv],yy=y+dy[vv];
          if(xx<0||xx>=w||yy<0||yy>=h)continue;
          int cost=(i==a[y][x])?0:co[i];cost+=p.fi;
          if(d[yy][xx][vv]>cost){
            d[yy][xx][vv]=cost;
            lp.fi=cost,lp.se.fi=yy*100+xx,lp.se.se=vv;
            q.push(lp);
          }
        }
      }
    }
    cout<<d[h-1][w-1][4]<<endl;
  }
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    string n; cin >> n;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3])) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(std::string s) {
  int64_t ret = 0;
  int64_t blacks = 0;
  for (auto const ch : s) {
    if (ch == 'B') {
      blacks++;
      continue;
    }
    ret += blacks;
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::string s;
  std::cin >> s;
  auto const res = solve(s);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 788
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(a,b,x);
  Vi ans1;
  Vi ans2;
  Vi result;
  FOR(i,a,a+x){
    if(i<=b) ans1.pb(i);
  }
  for(int i = b-x+1; i <= b; i++){
    if(i>=a) ans2.pb(i);
  }
  set_union(ALL(ans1),ALL(ans2),inserter(result, end(result)));
  VOUT(result)
}

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

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

const int mod1 = 1000000007;
const int mod2 = 1000000009;
const int arg1 = 37;
const int arg2 = 1000007;
const int Maxn = 50005;

int pw1[Maxn], pw2[Maxn];
char str[Maxn];
int slen;
ii H[Maxn];
map <ii, int> M;

ii Get(int l, int r)
{
    ii res = H[r];
    if (--l >= 0) {
        res.first = (ll(res.first) - ll(pw1[r - l]) * H[l].first % mod1 + mod1) % mod1;
        res.second = (ll(res.second) - ll(pw2[r - l]) * H[l].second % mod2 + mod2) % mod2;
    }
    return res;
}

bool Ok(int len)
{
    M.clear();
    for (int i = 0; i + len <= slen; i++) {
        ii h = Get(i, i + len - 1);
        map <ii, int>::iterator it = M.find(h);
        if (it == M.end()) M.insert(make_pair(h, i));
        else if (it->second + len <= i) return true;
    }
    return false;
}

int main()
{
    pw1[0] = pw2[0] = 1;
    for (int i = 1; i < Maxn; i++) {
        pw1[i] = ll(pw1[i - 1]) * arg1 % mod1;
        pw2[i] = ll(pw2[i - 1]) * arg2 % mod2;
    }
    scanf("%d", &slen);
    scanf("%s", str);
    ii h = ii(0, 0);
    for (int i = 0; i < slen; i++) {
        h.first = (ll(h.first) * arg1 + ll(str[i] - 'a' + 1)) % mod1;
        h.second = (ll(h.second) * arg2 + ll(str[i] - 'a' + 1)) % mod2;
        H[i] = h;
    }
    int lef = 1, rig = slen;
    while (lef <= rig) {
        int mid = lef + rig >> 1;
        if (Ok(mid)) lef = mid + 1;
        else rig = mid - 1;
    }
    printf("%d\n", lef - 1);
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    cin >> n >> k;

    bitset<100000> bs;
    cin >> bs;

    vector<int64_t> p;
    p.push_back(0L);
    if (!bs[0]) {
        p.push_back(0L);
    }
    for (auto i : irange(1L, n)) {
        if (bs[i] != bs[i - 1]) {
            p.push_back(i);
        }
    }
    p.push_back(n);

    int64_t ans = 0;
    for (auto i : irange(0uL, p.size())) {
        if (i % 2 == 0) {
            ans = max(ans, p[min(p.size() - 1, i + 2 * k + 1)] - p[i]);
        }
    }
    cout << ans << endl;
}

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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
  	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  int n; cin>>n;
  int a[n];
  f(i,0,n) cin>>a[i];
  int cnt = 0;
  f(i,0,n) {
    while (i<n-1 && a[i] == a[i+1]) i++;
    if (i<n-1) {
    	if (a[i] < a[i+1]) while (i<n-1&&a[i]<=a[i+1]) i++;
      	else while (i<n-1&&a[i]>=a[i+1]) i++;
    }
    cnt++;
  }
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 640
using System;

public class Program
{
    public static int maxM;
    public static int[] shinamonotachi;

    public static void Main(string[] args)
    {
        var input = int.Parse(Console.ReadLine());

        var answers = new int[81];

        var index = 0;
        for (int i = 1; i < 10; i++)
        {
            for (int j = 1; j < 10; j++)
            {
                answers[index] = i * j;
                index++;
            }
        }

        foreach (var copyAnswer in answers)
        {
            if (copyAnswer == input)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }

}

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

INF = float('inf')

N = int(input().strip())
data = [list(map(int, input().split())) for _ in range(N)]
cost_b = []
cost_D = []
for b in range(1<<N):
  towns = []
  cost = INF
  for i in range(N):
    if (b>>i)&1:
      towns.append(data[i])
  for i in range(len(towns)):
    X = towns[i][0]
    cost = min(cost,sum(abs(towns[j][0]-X)*towns[j][2] for j in range(len(towns))))
  for i in range(len(towns)):
    Y = towns[i][1]
    cost = min(cost,sum(abs(towns[j][1]-Y)*towns[j][2] for j in range(len(towns))))
  if len(towns) == 0:
    cost = 0
  cost_b.append(cost)
  cost_D.append(sum(min(abs(towns[j][0]),abs(towns[j][1]))*towns[j][2] for j in range(len(towns))))

dp = [[INF]*(N+1) for i in range(1<<N)]

for i in range(1<<N):
  dp[i][0] = cost_D[i]
count = 0
for k in range(1,N+1):
  for i in range(1<<N)[::-1]:
    x = i
    while x>=0:
      x &= i
      new = dp[i-x][k-1]+cost_b[x]
      if dp[i][k] > new:
        dp[i][k] = new
      if new == 0:
        break
      x -= 1
for i in range(N+1):
  print(dp[-1][i])

Measured memory_bytes: 111252
n = int(input())

def digit(a):
    return sum(map(int,list(str(a))))

if n < 10:
    print(n)
else:
    n2 = list(str(n))
    ln = len(n2)

    if n == 10**ln - 1:
        print(9*ln)
    elif n == int(n2[0])*(10**(ln-1))+ 10**(ln-1)-1:
        print(int(n2[0])+9*(ln-1))
    else:
        for i in range(ln):
            if i == 0:
                n2[0] = str(int(n2[0]) - 1)
                if n2[0] == "0":
                    n2[0] = ""
            else:
                n2[i] = "9"
        n2 = int("".join(n2))
        print(digit(n2))


Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
 
#define NMAX 1000
 
int bs (int [], int, int);
 
int compar (const void *a, const void *b) {
  return *(int *)a- *(int *)b;
}
 
int main(void)
{
  while(1)
  {
  	int i,j,k,N,M,c,p[NMAX*NMAX],s;
  	scanf("%d%d",&N,&M);
	if(N==0 && M==0) break;
	for(i=0;i<=N-1;i++)
	{
		scanf("%d",&p[i]);
	}
	k=N;
	for(i=0;i<=N-1;i++)
	{
		for(j=i;j<=N-1;j++)
		{
			p[k]=p[i]+p[j];
			k++;
		}
	}
	p[k]=0;
	qsort(p,k+1,sizeof(int),compar);
	for(i=c=0;i<=k;i++)
	{
		if(p[i]<=M)
		{
			s=p[i]+bs(p,k+1,M-p[i]);
			if(s<=M&&s>c)c=s;
		}
	}
	printf("%d\n",c);
  }
  return 0;
}
 
 int bs (int D[], int n, int c) 
 {
    int j,k,l;
    j=0;
    k=n-1;
    while(1)
	{
        if(j<=k)
		{
            l=(j+k)/2;
            if(D[l] > c)
            {
                k=l-1;
            }
            else if(D[l+1] < c)
            {
                j=l+1;
            }
            else
            {
                return D[l];
            }
		}
		else
		{
	        return D[k];
		}
    }
}

Measured memory_bytes: 4984
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))

    r = 0
    d = 0
    for i in range(N):
        if (r+Bs[i]) >= As[i]:
            d += As[i]
            r = min((r+Bs[i] - As[i]), Bs[i])
        else:
            d += (r+Bs[i])
            r = 0
    else:
        d += min(As[N], r)
    print(d)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc135","c",main)

Measured memory_bytes: 19156
#include <iostream>
#include <vector>
//#include <algorightm>
#include <map>
#include <tuple>
//#include <cstudio>

int main() {
    int a = 0;
    std::string s;
    std::cin >> s;
    if(s[0] == '1') a++;
    if(s[1] == '1') a++;
    if(s[2] == '1') a++;
    std::cout << a << std::endl;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	priority_queue<ll, vector<ll>, greater<ll>> que;
	for (int i=0; i<n; i++) {
		ll a; cin >> a;
		que.push(a);
	}

	int ret=0;
	ll v = 0;
	for (int i=0; i<n; i++) {
		ll now = que.top();
		que.pop();
		if (2*v>=now) ret++;
		else ret = 0;
		v += now;
	}
	ret++;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1400
def main():
  n=int(input())
  a=sorted(map(int,input().split()))
  maxa=a[-1]
  tf=[True]*maxa
  r=0
  n-=1
  for i in range(n): # maxa以外の処理
    a_i=a[i]
    if tf[a_i-1] ==True: # これまでに素の場合のみ処理実行
      for j in range(a_i - 1,maxa,a_i):
        tf[j]=False
      if a_i < a[i+1]: # a[i]とa[i+1]が同値の場合を排除
        r+=1
  if tf[-1] == True: # maxaへの処理
     r+=1
  print(r)
main()

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

typedef long long ll;

int main(){
    int K, S;
    cin >> K >> S;
    
    int cnt=0;
    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
                if(S-(x+y)>=0 && S-(x+y)<=K)
                    cnt++;
        }
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[300002];

int getw(int l,int r){
  int res=a[r]-a[l-1];
  if(l>r)res=0;
  return res;
}

int gete(int l,int r){
  int res=r-l+1-(a[r]-a[l-1]);
  if(l>r)res=0;
  return res;
}

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=1e9;
  for(int i=1;i<=n;i++)
    a[i]+=a[i-1]+(s[i-1]=='W');
  for(int i=1;i<=n;i++){
    int res=getw(1,i-1)+gete(i+1,n);
    ans=min(ans,res);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1796
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
ull mod = 1e9 + 7;
using namespace std;

///aとbの最大公約数を求める関数。計算量はO(log min(a, b))
ll Gcd(ll a, ll b){
    if(b == 0)return a;
    else return Gcd(b, a % b);
}

///素因数分解をする関数
vector<pair<ll, ll>> Factorize(ll n){
    vector<pair<ll, ll>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i)continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)res.emplace_back(n, 1);
    return res;
}

int main(){
    
    ll a, b; cin >> a >> b;
    auto res = Factorize(Gcd(a, b));
    cout << res.size() + 1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

double x[10], y[10];

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

	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}

	double ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}

	cout << setprecision(15) <<ans / double(N) << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Tower {
public: 
  int id;
  vector<Tower *> tonari;
  int h;
  int count;
  Tower() {
    id = 0;
    h = 0;
    count = 0;
  }
};

int main() {
  long long int N, M;
  vector<Tower *> t;

  cin >> N >> M;
  for (int i = 0; i < N; i++)  {
    Tower *tow = new Tower();
    t.push_back(tow);
    int tmp;
    cin >> tmp;
    t[i]->h = tmp;
    t[i]->id = i;
  }
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    t[a - 1]->tonari.push_back(t[b - 1]);
    (t[a - 1]->count)++;
    t[b - 1]->tonari.push_back(t[a - 1]);
    (t[b - 1]->count)++;
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
     while (t[i]->count > 0) {
       if (t[i]->tonari[t[i]->count - 1]->h >= t[i]->h) {
         count--;
         break;
       }

       (t[i]->count)--;
     }
     count++;
  }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 12276
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int N = sc.nextInt();
    boolean[][] s = new boolean[W][H];
    for(int i = 0; i < N; i++){
      int x = sc.nextInt();
      int y = sc.nextInt();
      int a = sc.nextInt();
      switch(a){
        case 1:
          for(int j = 0; j < H; j++){
            for(int k = 0; k < x; k++){
              s[k][j] = true;
            }
          }
          break;
        case 2:
          for(int j = 0; j < H; j++){
            for(int k = x; k < W; k++){
              s[k][j] = true;
            }
          }
          break;
        case 3:
          for(int j = 0; j < y; j++){
            for(int k = 0; k < W; k++){
              s[k][j] = true;
            }
          }
          break;
        case 4:
          for(int j = y; j < H; j++){
            for(int k = 0; k < W; k++){
              s[k][j] = true;
            }
          }
          break;
      }
    }
    int sum = 0;
    for(int i = 0; i < W; i++){
      for(int j = 0; j < H; j++){
        sum += (s[i][j] == false) ? 1:0;
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22960
N = int(input())
h = list(map(int, input().split()))
ans = 0
while sum(h) != 0:
    for i in range(N):
        if(h[i]!=0):
            l = i
            r = N
            break
    for j in range(i+1, N):
        if(h[j]==0):
            r = j
            break

    x = min(h[l:r])
    for i in range(l, r):
        h[i] -= x
    ans += x
print(ans)

Measured memory_bytes: 3064