akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=205; int P;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n, lim, f[N][N], C[N][N], fac[N], ans; 

int calc(int k, int l, int lim) {
	int ans=0;
   	mem(f, 0); 
	f[0][1] = 1;
	rep(j, 1, l) {
		rep(i, 0, k-1) {
			f[i][j] = add(f[i][j], add(i?f[i-1][j]:0, f[i][j-1])); 
			if (l-j+1+i-1 > lim) f[i][j] = 0; 
		}
		rep(i, 0, k-1) {
			if (k-i+j-1 > lim) f[i][j] = 0; 
		}
	}
	rep(i, 1, k-1) ans = add(ans, f[i][l]); 
	return ans; 
}

int solve(int lim, int n) {
	if (n == 1) return 0; 
	if (n == 0) return 1; 
	if (lim < 0) return 0; 
	int r = 0; 
	rep(k, 1, min(n,lim+1)) {
		int t = mul(C[n-1][k-1], mul(fac[n-k], fac[k-1]));
		r = add(r, mul(t, calc(k, n-k, lim))); 
	}
	return r;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	cin >> n >> lim >> P; 
	C[0][0] = 1; 
	rep(i, 1, n) {
		C[i][0] = 1; 
		rep(j, 1, i) C[i][j] = add(C[i-1][j], C[i-1][j-1]); 
	}
	fac[0] = 1; 
	rep(i, 1, n) fac[i] = mul(fac[i-1], i); 
	rep(i, 0, lim+1) {
		ans = add(ans, mul(mul(fac[i], C[n][i]), solve(lim - i, n - i))); 
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  cin >> A;
  vector<char> vec(A);
  int B=0;
  for(int i=0;i<A;i++){
    cin >> vec.at(i);
    if(vec.at(i)=='Y'){
      B++;
    }
  }
  if(B>0){
    cout << "Four" << endl;
  }
  else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 764
N = int(input())
A = map(int, input().split())

x = sorted(a - i - 1 for i, a in enumerate(A))
mid = x[N//2] if N % 2 else (x[N//2] + x[N//2-1]) // 2
ans = sum(abs(xi - mid) for xi in x)
print(ans)


Measured memory_bytes: 26020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD=1000000007;
int main(){
  int N;
  int x[100005],a,b;
  int r[18][100005];//r[i][j]ｊが2^i乗日で行くことができる一番右のところ
  //r[i+1][j]=r[i][r[i][j]]; r[0][j]は二分探査でnlognで見ることができる。
  int L,Q;
  cin >> N;
  rep(i,N)cin >> x[i];
  cin >> L >> Q;
  rep(i,N-1){
    int up = N,low = i+1,mid;
    while(up-low>1){
      mid = (up+low)/2;
      if(x[mid] - x[i]<=L)low = mid;
      else up = mid;
    }
    r[0][i] = low;
  }
  r[0][N-1]=N-1;
  //cout << endl;
  //rep(i,N)cout<<r[0][i]<<" "  ;
  //cout << endl;
  rep(i,17)rep(j,N)r[i+1][j]=r[i][r[i][j]];
  rep(j,Q){
    int ret = 0;
    cin >> a >> b;
    if(a==b){
      cout << 0 << endl;
      continue;
    }
    a--,b--;
    if(b<a)swap(a,b);
    //rep(i,16)cout<<r[i][a]<<' ';
  for(int i = 16;i>=0;i--){
    if(r[i][a]<b){
      ret+=1<<i;
      a = r[i][a];
    }
  }

    cout  << ret+1<<endl;
  }

}


Measured memory_bytes: 8192
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
K = int(input())
print(l[K-1])


Measured memory_bytes: 3316
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <queue>
#include<bitset>
#include <set>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;

//abc134_e E - Sequence Decomposing 
//a[i]とa[j] が同じ色なら、a[i] < a[j] を満たす
//用いる色の数を最小にする
// 2 1 4 5 3 -> 145  23 の 2色
// 245 13でもよい
// 後ろから見て、現在の最小の値を保存したほうがよい?


int main(){
    int N;
    cin >> N;
    vector <ll> a(N);
    REP(i,N)
    {
        cin >> a[i];
    }
    vector <int> v;
    multiset<ll> s;
    int res = 1;
    s.insert(a[0]);
    s.insert(MOD);

    v.push_back(a[0]);
    for(int i = 1; i < N; ++i)
    {
        auto itr = s.lower_bound(a[i]);

        if(itr == s.begin())
        {
            s.insert(a[i]);
            ++res;
        }
        else
        {
            --itr;
            s.erase(itr);
            s.insert(a[i]);
        }

    }
        
    cout << res << endl;
    return 0;
}



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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n; cin >> n;
    V<double> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    double sum = 0;
    for(int i = 0; i < n; i++){
        sum += 1.0 / a[i];
    }

    cout << setprecision(12) << 1.0 / sum << endl;

    return 0;
}


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

int main()
{
    int n,ans;
    string s;
    cin>>n>>s;
    ans=n;
    rep(i,n-1) ans-=s[i]==s[i+1];
    cout<<ans;
}

Measured memory_bytes: 3712
N,M=map(int,input().split())

P=list(map(int,input().split()))
P=list(map(lambda x:x-1,P))

# Pもx,yも0-indexに変更
# UnionFindで、(x,y)で同組になるインデックスの集合を求める。
# 同じインデックスの集合に存在するPの値の集合で、インデックスの集合にも存在するものの数が答え

# 0-indexed
class UnionFind:
  N=0
  parent=None
  size=None
  def __init__(self,N):
    self.N=N
    self.parent=[i for i in range(self.N)]
    self.size=[1]*self.N
    
  def root(self,x):
    while x!=self.parent[x]:
      self.parent[x]=self.parent[self.parent[x]]
      x=self.parent[x]
    return x
  
  def same(self,x,y):
    return self.root(x)==self.root(y)
  
  def unite(self,x,y):
    x=self.root(x)
    y=self.root(y)
    if x==y:
      return
    if self.size[x]>self.size[y]:
      # 大きい方にくっつける
      self.parent[y]=x
      self.size[x]+=self.size[y]
    else:
      self.parent[x]=y
      self.size[y]+=self.size[x]
      
  def get_group_size(self,x):
    return self.size[self.root(x)]
  
  def get_roots(self):
    r=set()
    for i in range(self.N):
      r.add(self.root(i))
    return r
  
  def show_parent(self):
    print(self.parent)
    
  def show_size(self):
    print(self.size)
    
UF=UnionFind(N)
for i in range(M):
  x,y = map(int,input().split())
  UF.unite(x-1,y-1)
  
from collections import defaultdict
dic = defaultdict(list)
for i in range(N):
  r = UF.root(i)
  dic[r].append(i)
  
ans = 0
for inds in dic.values():
  vals = set()
  for i in inds:
    vals.add(P[i])
  ans += len(vals & set(inds))
  
print(ans)

Measured memory_bytes: 33616
#include <bits/stdc++.h>
#define int long long
using namespace std;
//const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
const int MOD = 2019;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  int L, R;
  cin >> L >> R;

  vector<int> b(MOD, 0);
  for (int i = 0; i < MOD * 2; i++)
  {
    if (L + i > R)
    {
      //cerr << L + i << endl;
      break;
    }
    b.at((L + i) % MOD)++;
  }
  
  vector<int> a;
  for (int i = 0; i < MOD; i++)
  {
    for (int j = 0; j < b.at(i); j++)
    {
      a.push_back(i);
    }
  }
  
  //for (int i = 0; i < a.size(); i++)
    //cerr << a.at(i) << endl;
  
  int ans = INF;
  for (int i = 0; i < a.size(); i++)
  {
    for (int j = i + 1; j < a.size(); j++)
    {
      chmin(ans, (a.at(i) * a.at(j)) % MOD);
      //if (chmin(ans, a.at(i) * a.at(j)))
        //cerr << a.at(i) << " " << a.at(j) << endl;
    }
  }

  cout << ans << endl;
}

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

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

typedef struct {
	long stock;
	long value;
} S_OPERATION;

int cmpVal(const void * n1, const void * n2)
{
	if (((S_OPERATION *)n1)->value > ((S_OPERATION *)n2)->value)
	{
		return -1;
	}
	else if (((S_OPERATION *)n1)->value < ((S_OPERATION *)n2)->value)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  S_OPERATION operation[m];
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld", &operation[i].stock, &operation[i].value);
  }
  qsort(a, n, sizeof(long), cmpnum);
  qsort(operation, m, sizeof(S_OPERATION), cmpVal);
  long operation_number = 0;
  for (long i = 0; i < n; i++) {
    if (operation_number >= m) {
      break;
    }
    if (operation[operation_number].value > a[i]) {
      a[i] = operation[operation_number].value;
      operation[operation_number].stock--;
    } else {
      break;
    }
    if (operation[operation_number].stock == 0) {
      operation_number++;
    }
  }
  long sum = 0;
  for (long i = 0; i < n; i++) {
    sum += a[i];
  }
  printf("%ld\n", sum);

  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int mult(int a, int b)
{
	return 1ll * a * b % mod;
}

int add(int a, int b)
{
	a += b;
	if(a >= mod) a %= mod;
	if(a < 0) a += mod;
	return a;
}

int binpow(int n, int s){
	if(s == 0) return 1;
	if(s % 2 == 0) 
	{
		int x = binpow(n, s / 2);
		return mult(x, x);
	}	
	return mult(binpow(n, s - 1), n);
}

int n, k, a[100005], f[100005], ans, s1, s2;

int cnk(int len, int s){
	if(s > len || len < 0 || s < 0) return 0;
	int b = mult(f[s], f[len - s]);
	return mult(f[len], binpow(b, mod - 2));
}        

main(){
	ios_base::sync_with_stdio(0);
	cin >> n >> k;  
	f[0] = 1;
	f[1] = 1;
	for(int i = 2; i <= 1e5; i++){
		f[i] = mult(f[i - 1], i);
	}
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++){
		int mx = cnk(i - 1, k - 1), mn = cnk(n - i, k - 1);
		s1 = add(s1, mult(mx, a[i]));
		s1 = add(s1, -mult(mn, a[i]));
	}
	cout << s1;
}          

Measured memory_bytes: 1024
n = int(input())
s = input()

f = [0]
tmp = 0
for c in s:
    if c == '#':
        tmp += 1
    f.append(tmp)

b = [0]
tmp = 0
for c in s[::-1]:
    if c == '.':
        tmp += 1
    b.append(tmp)
b.reverse()

# print(f)
# print(b)
print(min(map(sum, zip(f, b))))


Measured memory_bytes: 12956
# -*- coding: utf-8 -*-
import heapq

N, M = map(int, input().split())
H = list(map(int, input().split()))
A = list()
B = list()

for i in range(M):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)

descending = list()
observatorys = [[None, []] for _ in range(N)]
for i in range(N):
  heapq.heapify(observatorys[i][1])

for i in range(M):
  
  if observatorys[A[i]-1][0] == None:
    observatorys[A[i]-1][0] = H[A[i]-1] * -1
    heapq.heappush(observatorys[A[i]-1][1], H[B[i]-1] * -1)
  else:
    heapq.heappush(observatorys[A[i]-1][1], H[B[i]-1] * -1)

  if observatorys[B[i]-1][0] == None:
    observatorys[B[i]-1][0] = H[B[i]-1] * -1
    heapq.heappush(observatorys[B[i]-1][1], H[A[i]-1] * -1)
  else:
    heapq.heappush(observatorys[B[i]-1][1], H[A[i]-1] * -1)

    
count = 0
for observatory in observatorys:
  if observatory[0] is None or observatory[0] < observatory[1][0]:
    count += 1

print(count)

Measured memory_bytes: 110884
n = int(input())
s = input()
cntl,cntr,tmp=0,0,0
for i in range(n):
   if s[i] == ")":
     if cntl > 0:
         cntl -= 1
     else:
         cntr += 1
   else:
    cntl += 1
print(cntr*"("+s+cntl*")")

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define mp std::make_pair
#define pb push_back
using ll = long long;
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }

int main()
{
	// freopen("caddi2018-D.in", "r", stdin);
	int n;
	bool ans = true;
	scanf("%d", &n);
	while (n--)
	{
		int x;
		scanf("%d", &x);
		ans &= x & 1 ^ 1;
	}
	puts(ans ? "second" : "first");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;
const double PI = acos(-1);

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= a + b) cout << b + c << endl;
	else cout << a + 2 * b + 1 << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int Q;

bool Solve(int mid, ll A, ll B){
    int m = mid / 2;
	for(int j = m - 2; j <= m + 2; ++j) {
        if(j < 0 || B - A < j) continue;
        if((A + j) * (A + mid - j) >= A * B) return false;
      }
      return true;
}

int main(void){
    
    scanf("%d", &Q);
    for(int i = 0; i < Q; ++i){
        
        ll A, B; scanf("%lld %lld", &A, &B);
        if(A > B) swap(A, B);
        
        ll ans = 2 * (A - 1);
        
        int ok = B - A + 1;	//解が存在する値
	    int ng = 0;        //解が存在しない値
	    while(abs(ok - ng) > 1){
		    int mid = (ok + ng) / 2;
		    if(Solve(mid, A, B)) ng = mid;
		    else ok = mid;
	    }	
        
        printf("%lld\n", ans + ng);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int MAXN=1e5+5;

typedef long long lld;

lld n, q, b, c;
map<lld,lld> fq;
/*lld bit[MAXN];

void update(int i, int v){
    for(i;i<=n;i+=(i&-i)){
        bit[i]+=v;
    }
}

lld sum(int i){
    lld ret=0;
    for(i;i>0;i-=(i&-i)){
        ret+=bit[i];
    }
    return ret;
}*/

void solve(){
    lld sum=0;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
        fq[a[i]]++;
    }
    cin>>q;
    while(q--){
        cin>>b>>c;
        sum+=(c*fq[b])-(b*fq[b]);
        fq[c]+=fq[b];
        fq[b]=0;
        cout<<sum<<endl;
    }
}

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

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 062 C / Link: http://abc062.contest.atcoder.jp/tasks/abc062_c  ----- */


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

	LL H, W; cin >> H >> W;
	auto f = [](LL H, LL W) {
		DD(de("---------"))
			LL ret = LINF;
		FOR(i, 1, W) { // |
					   // H*i, []
			{
				VL a({ H*i,(H / 2) * (W - i),((H + 1) / 2) * (W - i) });
				ret = min(ret, *max_element(ALL(a)) - *min_element(ALL(a)));
			}
			{
				VL a({ H*i,H*((W - i) / 2), H*((W - i + 1) / 2) });
				ret = min(ret, *max_element(ALL(a)) - *min_element(ALL(a)));
			}
		}

		return ret;
	};


	LL ans = f(H, W);
	swap(H, W);
	ans = min(ans, f(H, W));
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = "";
			while ((input = Console.ReadLine()) != null)
			{
				var cards = input.Split(',').Select(i => int.Parse(i)).ToArray();
				Array.Sort(cards);

				var num = new int[14];
				for (int i = 0; i < cards.Length; i++)
					num[cards[i]]++;

				if (num.Contains(4))
					Console.WriteLine("four card");
				else if (num.Contains(3) && num.Contains(2))
					Console.WriteLine("full house");
				else if (straight(cards))
					Console.WriteLine("straight");
				else if (num.Contains(3))
					Console.WriteLine("three card");
				else if (num.Count(i => i == 2) == 2)
					Console.WriteLine("two pair");
				else if (num.Count(i => i == 2) == 1)
					Console.WriteLine("one pair");
				else
					Console.WriteLine("null");
			}
		}
		static bool straight(int[] cards)
		{
			if (cards.SequenceEqual(new int[] { 1, 10, 11, 12, 13 }))
				return true;
			for (int i = 1; i <= 9; i++)
				if (cards.SequenceEqual(Enumerable.Range(i, 5).ToArray()))
					return true;
			return false;
		}
	}
}

Measured memory_bytes: 6212
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<int> A(N), B(N);
	REP(i, N - 1) cin >> B[i];
	B[N - 1] = (100000000);
	A[0] = B[0];
	REP(i, N - 1) {
		A[i + 1] = min(B[i], B[i + 1]);
	}
	int sum = 0;
	REP(i, N) sum += A[i];
	cout << sum << endl;

	return 0;
}


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

int main(){
  int N, a, b, f;
  cin >> N;
  a = N;
  while(a >= 10){
    b = a % 10;
    a = (a - b) / 10;
    f += b;
  }
  f += a;
  if(N % f == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int X, Y, Z, K;
	cin >> X >> Y >> Z >> K;
	vector<ll> A(X), B(Y), C(Z);
	for(int i=0;i<X;i++){
		cin >> A[i];
	}
	for(int i=0;i<Y;i++){
		cin >> B[i];
	}
	for(int i=0;i<Z;i++){
		cin >> C[i];
	}
	vector<ll> AB;
	for(int i=0;i<X;i++){
		for(int j=0;j<Y;j++){
			AB.push_back(A[i] + B[j]);
		}
	}
	sort(AB.rbegin(),AB.rend());
	sort(C.rbegin(),C.rend());
	vector<ll> ans;
	for(int i=0;i<K;i++){
		for(int j=0;j<K;j++){
			if(j >= Z || i >= X * Y) continue;
			ans.push_back(AB[i] + C[j]);
		}
	}
	sort(ans.rbegin(),ans.rend());
	for(int i=0;i<K;i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 43112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] s = str.split(" ");

		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		if(a > -1000){
			if(b < 1000){
				if(a < b){
					System.out.println("a < b");
				}else if ( a == b){
					System.out.println("a == b");
				}else{
					System.out.println("a > b");
				}
			}
		}
	}
}

Measured memory_bytes: 24432
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n = ni()
    c = ns()
    r = c.count('R')
    print(r - c[:r].count('R'))
    return

solve()


Measured memory_bytes: 9484
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

ll n,a,b,p[100010]={},d[100010]={},s;
vector<ll> v[100010],c[100010];

void init(ll i=1,ll pe=0,ll D=0){
  p[i]=pe;d[i]=D++;
  fr(j,v[i].size()){
    if(v[i][j]!=pe){
      init(v[i][j],i,D);
      c[i].pb(v[i][j]);
    }
  }
}

ll cnt(ll i=1){
  if(i==s) return 0;
  ll e=1;
  fr(j,c[i].size()) e+=cnt(c[i][j]);
  return e;
}

int main(){
  cin>>n;
  fr(i,n-1){cin>>a>>b;v[a].pb(b);v[b].pb(a);}
  init();
  s=n;
  fr(i,(d[n]-1)/2) s=p[s];
  cout<<(cnt()>n/2?"Fennec":"Snuke")<<endl;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int N = 605;
int n,k;
int ok[N];
int to[N];
ll mem[N][N];
ll g[N];
int p[N];
int ct = 0;
ll dp(int l, int r){
    if (l == r) return 0;
    if (mem[l][r] != -1) return mem[l][r];
    for (int i = l; i <= r; i++){
        if (to[i] != 0 && to[i] < l || to[i] > r) return mem[l][r] = 0;
    }
    int x = p[r]-p[l-1];
    int z = ct-x;
    mem[l][r] = g[x];
    //printf("x %d g[x] %lld g[z] %lld\n",x,g[x],g[z]);
    for (int k = l+1; k < r; k++){
       // printf("- %lld*%lld = %lld\n",dp(l,k),g[p[r]-p[k]],(dp(l,k)*g[p[r]-p[k]])%mod);
        mem[l][r] -= (dp(l,k)*g[p[r]-p[k]])%mod;
        mem[l][r] %= mod;
    }
    mem[l][r] = (mem[l][r]%mod + mod)%mod;
    //printf("%d %d %lld\n",l,r,mem[l][r]);
    return mem[l][r];
}
int main(){
    scanf("%d%d",&n,&k);
    g[0] = 1;
    for (int i = 2; i <= 2*n; i+=2){
        g[i] = g[i-2]*(i-1)%mod;
    }
    for (int i = 0,a,b; i < k; i++){
        scanf("%d%d",&a,&b);
        to[a] = b;
        to[b] = a;
        ok[a] = ok[b] = 1;
    }
    for (int i = 1; i <= 2*n; i++){
        p[i] += p[i-1]+(1-ok[i]);
    }
    ct = p[2*n];
    ll ans = 0;
    memset(mem,-1,sizeof(mem));
    for (int i = 1; i <= 2*n; i++){
        for (int j = i; j <= 2*n; j++){
            int CT = ct-(p[j]-p[i-1]);
            ans += dp(i,j)*g[CT];
            //printf("%d %d %lld*%lld\n",i,j,dp(i,j),g[CT]);
            ans %= mod;
        }
    }
    printf("%lld ",(ans+mod)%mod);

}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int N = 1e2+9;
const int K = 1e5+9;
const ll MOD = 1e9+7;

ll n, k;
ll a[N];
ll dp[N][K]; // (child, candie)
ll sum[N][K]; // (child, candie)

ll mod(ll n) {
    n %= MOD;
    if(n < 0)  n += MOD;
    return n;
}

ll addmod(ll &a, ll b) {
    return a = mod( mod(a) + mod(b) );
}

int main() {
    cin >> n >> k;
    for(int i = 1; i <= n; i++)  cin >> a[i];

    for(int ch = 1; ch <= n; ch++) {
        for(int ca = 0; ca <= k; ca++) {
            if(ch == 1)  dp[ch][ca] = (a[ch] >= ca);
            if(ca == 0)  dp[ch][ca] = 1;
        }
    }

    for(int ch = 2; ch <= n; ch++) {
        sum[ch-1][0] = dp[ch-1][0];
        for(int ca = 1; ca <= k; ca++) {
            addmod(sum[ch-1][ca], sum[ch-1][ca-1] + dp[ch-1][ca]);
        }

        for(int ca = 1; ca <= k; ca++) {
            ll right = sum[ch-1][ca];
            ll left = (ca - a[ch] - 1 < 0) ? 0LL : sum[ch-1][ca-a[ch]-1];
            addmod(dp[ch][ca], right - left);
        }
    }

    cout << dp[n][k] << endl;
}

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

int main() {
	
	int n; cin >> n;
	string ans = "No";
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <=100; j++) {
			if (4 * i + 7 * j == n) {
				ans = "Yes";
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3600
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


def solve(N, M, A, B, C, ab):
    A = [0] + A
    B = [0] + B
    C = [0] + C
    for i in range(M + 1):
        if len(A) == N + 1 or len(C) == N + 1:
            return i
        if ab:
            if A[-1] < B[-1]:
                A.append(B.pop())
            else:
                B.append(A.pop())
        else:
            if C[-1] < B[-1]:
                C.append(B.pop())
            else:
                B.append(C.pop())
        ab = not ab
    return IINF


while True:
    N, M = list(map(int, sys.stdin.readline().split()))
    if N == M == 0:
        break
    _, *A = list(map(int, sys.stdin.readline().split()))
    _, *B = list(map(int, sys.stdin.readline().split()))
    _, *C = list(map(int, sys.stdin.readline().split()))

    s1 = solve(N, M, A, B, C, True)
    s2 = solve(N, M, A, B, C, False)
    ans = min(s1, s2)
    if ans <= M:
        print(ans)
    else:
        print(-1)



Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		if(Character.isUpperCase(a.charAt(0))) {
			prtln('A');
		} else {
			prtln('a');
		}
		sc.close();
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


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

int main(){
  int A, B;
  cin >> A >> B;
  cout << max(A-2*B, 0) << endl;
}

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

bool sosu[1000005];

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    for (int i = 2; i < 1000001; i++){
        if(sosu[i])continue;
        for (int j = i+i; j < 1000001; j+=j){
            sosu[j] = true;
        }
    }

    vector<int> a(N);
    rep(i, N){
        a[i] = A[i];
    }
    bool check = true;
    for (int i = 2; i < 1001; i++){
        if(!sosu[i]){
            int cnt = 0;
            for (int j = 0; j < N; j++){
                if(a[j] % i == 0){
                    cnt++;
                    a[j] /= i;
                }
            }
            if(cnt > 1){
                check = false;
            }
        }
    }


    vector<int> test(1000005);
    rep(i, N){
        if(a[i] != 1){
            test[a[i]]++;
        }
    }

    rep(i, 1000001){
        if(test[i] > 1){
            check = false;
        }
    }

    if(check){
        cout << "pairwise coprime" << endl;
        return 0;
    }

    int now = A[0];
    for (int i = 1; i < N; i++){
        now = __gcd(now, A[i]);
    }
    if(now == 1){
        cout << "setwise coprime" << endl;
    } else {
        cout << "not coprime" << endl;
    }


    return 0;
}

Measured memory_bytes: 15932
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline LL Read()
{
	LL x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	LL k = Read(), a = Read(), b = Read();
	if (a >= k)
		return puts("1"), 0;
	if (a <= b)
		return puts("-1"), 0;
	return printf("%lld\n", 2 * ((k - b - 1) / (a - b)) + 1), 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 100

main(){
  int n, a[N], i, j, key;
  scanf("%d", &n);
  for(i =  0;i < n;i++){
    scanf("%d", &a[i]);
  }
  for(i = 1;i < n;i++){
    for(j = 0;j < n-1;j++){ 
      printf("%d ", a[j]); 
    }
    printf("%d\n", a[n-1]); 
    key = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > key){
      a[j+1] = a[j];
      j--;
      a[j+1] = key;
    }
  }
  for(j = 0;j < n-1;j++){ 
    printf("%d ", a[j]); 
  } 
  printf("%d\n", a[n-1]);
  return 0;
}

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

using namespace std;

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    
    long long ans=n/(a+b)*a;
    n%=(a+b);
    if(n<a) ans+=n;
    else ans+=a;
    cout << ans << endl;
}

Measured memory_bytes: 764
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 5, mod = (int) 0;
int a[N];
int main() {
	int n;
	cin >> n;
	for (int j = 0; j < n; ++j) {
		cin >> a[j];
	}
	int cur = 0, res = 0;
	while (cur < n) {
		++res;
		++cur;
		while (cur < n && a[cur] == a[cur - 1]) ++cur;
		int d = a[cur - 1] < a[cur];
		while (cur < n - 1 && ((a[cur] < a[cur + 1]) == d || a[cur] == a[cur + 1])) 
			++cur;
		++cur;
	}
	cout << res << endl;

}



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

int main() {
  long long X;
  long long c=100;
  int count=0;
  cin >>X ;

while(true){
    if(c>=X){
      break;
    }
    c= c+c*0.01;
    count++;
}

cout << count << endl;
return 0;
}


Measured memory_bytes: 3636
h,w = map(int, input().split())
a = [None]*h
for i in range(h):
    a[i] = list(input())

valid_h=[]
valid_w=[]

for i in range(h):
    flg=False
    for j in range(w):
        if a[i][j] =="#":
            flg=True
    if flg:
        valid_h.append(i)

for j in range(w):
    flg=False
    for i in range(h):
        if a[i][j] =="#":
            flg=True
    if flg:
        valid_w.append(j)

ans=[]
for i in range(h):
    if not i in valid_h:
        continue

    tmp=[]
    for j in range(w):
        if j in valid_w:
            tmp.append(a[i][j])
    ans.append(tmp)

for a in ans:
    print(*a,sep="")

Measured memory_bytes: 42864
Max = 10 ** 100
st = input()
val = [0] * len(st)
ls = [0] * len(st)
pos = 0
for i in range(len(st)-1):
	if st[i] == st[i+1]:
		continue
	else:
		if st[i] == 'R':
			for j in range(pos, i):
				ls[j] = i - j
		else:
			for j in range(i, pos, -1):
				ls[j] = j - pos
		pos = i + 1
if st[i] == 'R':
	for j in range(pos, len(st)):
		ls[j] = i - j
else:
	for j in range(len(st)-1, pos, -1):
		ls[j] = j - pos
for i in range(len(st)):
	temp = (Max - ls[i]) % 2
	if temp == 1:
		ls[i] += 1
	if st[i] == 'L':
		val[i - ls[i]] += 1
	else:
		val[i + ls[i]] += 1
print(*val, sep = " ")

Measured memory_bytes: 10224
from sys import stdin
n = int(stdin.readline().rstrip())
s = str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

rnum = s.count("R")
gnum = s.count("G")
bnum = s.count("B")

ans = rnum * gnum * bnum

for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j - i
        if k<n:
            if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                ans -= 1

print(ans)


Measured memory_bytes: 9128
#ユークリッドの互除法( A < B　とし, O(logA))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

N,X = map(int,input().split())

#3個以上の最大公約数を求める必要がある
# res=0 と初期化して、res=gcd(res,x[i])と更新する
# gcd(a,b,c,....) → gcd(gcd(gcd(a,b),c),...) 
res = 0
x = list(map(int,input().split()))

for i in range(N):
    res = gcd(res,abs(x[i] - X))

print(res)



Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, cnt, ans;
string s;

int main() {
	fastio; cin >> n >> s;
	FOR(i, 0, n-1) if (s[i] == 'R') cnt++;
	FOR(i, 0, cnt-1) if (s[i] == 'W') ans++;
	cout << ans;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
const int N=4e6+5;
char s[N],t[N];
int nxt[N],ans,g[N];
int main()
{
	scanf("%s%s",s+1,t+1);
	int a=strlen(s+1),b=strlen(t+1);
	for(;a<b*2;a*=2)
		for(int i=1;i<=a;i++)s[i+a]=s[i];
	for(int i=1;i<=a;i++)s[i+a]=s[i];
	a*=2;
	for(int i=1;i<=b;i++)
	{
		int j=i;
		while(j>1&&t[nxt[j-1]]!=t[i])j=nxt[j-1]-1;
		nxt[i]=nxt[j-1]+1;
	}
	for(int i=1,j=1;i<=a;i++)
	{
		while(j>1&&s[i]!=t[j])j=nxt[j-1];
		if(s[i]==t[j])j++;
		if(j==b+1)ans=max(ans,g[i]=g[i-b]+1);
	}
	printf("%d",ans>=a/b-1?-1:ans);
}

Measured memory_bytes: 23040
N,K = map(int,input().split())
A = list(map(int,input().split()))

def f(n):
    now = 0
    for i in range(N):
        now += (A[i]-1)//x
    if now <= K:
        return True
    else:
        return False

l = 0; r = 10**10
while r-l > 1:
    x = (l+r)//2
    if f(x):
        r = x
    else:
        l = x
print(r)

Measured memory_bytes: 30856
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;

const int maxn=2e5+5;

ll A[maxn],lis[maxn];
int N,ln,H[maxn];

int main(){
	scanf("%d",&N);lis[++ln]=A[0];
	for(int i=1;i<=N;i++){
		scanf("%lld",&A[i]);
		A[i]+=A[i-1];lis[++ln]=A[i];
	}
	sort(lis+1,lis+ln+1);
	ln=unique(lis+1,lis+ln+1)-lis-1;
	for(int i=0;i<=N;i++){
		A[i]=lower_bound(lis+1,lis+ln+1,A[i])-lis;
	}
	ll ans=0;
	for(int i=0;i<=N;i++){
		ans+=H[A[i]];H[A[i]]++;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 4096
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char stdibuf[2500015];
uint32_t stdibufl;

bool arr[101];

uint32_t nextpint(void){ char c=stdibuf[stdibufl++]; while(c<'0'||'9'<c) c=stdibuf[stdibufl++]; uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=stdibuf[stdibufl++]; } return x; }
void printint(uint32_t x){ if(x<0){x=-x; putchar_unlocked('-');}else if(x==0){putchar_unlocked('0');} int d=0; char s[10]; while(x){ s[d]='0'+x%10; x/=10; d++; } for (int i=d-1; i>=0; i--) putchar_unlocked(s[i]); putchar_unlocked('\n'); }

uint32_t h[100000];
uint8_t is[100000];

int main(void){
	read(0, stdibuf, 2500014);
	uint32_t n=nextpint();
	uint32_t m=nextpint();
	for(uint32_t i=0; i<n; i++){
		h[i]=nextpint();
	}
	for(uint32_t i=0; i<m; i++){
		uint32_t a=nextpint()-1;
		uint32_t b=nextpint()-1;
		if(h[a]<=h[b]) is[a]=1;
		if(h[a]>=h[b]) is[b]=1;
	}
	uint32_t ans=0;
	for(uint32_t i=0; i<n; i++){
		ans+=is[i];
	}
	printint(n-ans);
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w,k; cin>>h>>w>>k;
	vector<string>c(h); for(auto&&i:c)cin>>i;
	int ans=0;
	for(int i=0;i<(1<<h);++i){
		for(int j=0;j<(1<<w);++j){
			vector<string>tmp=c;
			for(int l=0;l<h;++l){
				if(i&(1<<l)){
					for(int m=0;m<w;++m){
						if(tmp.at(l).at(m)=='#'){
							tmp.at(l).at(m)='.';
						}
					}
				}
			}
			for(int l=0;l<w;++l){
				if(j&(1<<l)){
					for(int m=0;m<h;++m){
						if(tmp.at(m).at(l)=='#'){
							tmp.at(m).at(l)='.';
						}
					}
				}
			}
			int sum=0;
			for(auto&&l:tmp){
				sum+=count(l.begin(),l.end(),'#');
			}
			if(sum==k)++ans;
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 3656
import scala.io.StdIn.readInt

object Main extends App {
  def replace(i:Char) = i match {
    case '4' => '5'
    case '5' => '7'
    case '6' => '8'
    case '7' => '9'
    case x => x
  }

  def scan(n:Int,b:Long,p:Long):String = {
    val (m,r) = (n/8, n%8)
    if(m==0) (b + r*p).toString.map(c => replace(c))
    else scan(m, b+r*p, p*10)
  }

  Iterator.continually(readInt).takeWhile( _ != 0 ).foreach { n=>
    println(scan(n,0,1))
  }
}

Measured memory_bytes: 70164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = sc.nextLong(),w = sc.nextLong();
		long s1 = 0, s2 = 0, s3 = 0;
		long min = Long.MAX_VALUE;
		for (int i = 1; i < w; i++) {
			s1 = i*h;
			s2 = h/2*(w-i);
			s3 = (h+1)/2*(w-i);
			min = Math.min(min, Math.max(Math.max(s1,s2),s3)-Math.min(Math.min(s1,s2),s3));
			s2 = (w-i)/2*h;
			s3 = (w-i+1)/2*h;
			min = Math.min(min, Math.max(Math.max(s1,s2),s3)-Math.min(Math.min(s1,s2),s3));
		}
		for (int i = 1; i < h; i++) {
			s1 = i*w;
			s2 = w/2*(h-i);
			s3 = (w+1)/2*(h-i);
			min = Math.min(min, Math.max(Math.max(s1,s2),s3)-Math.min(Math.min(s1,s2),s3));
			s2 = (h-i)/2*w;
			s3 = (h-i+1)/2*w;
			min = Math.min(min, Math.max(Math.max(s1,s2),s3)-Math.min(Math.min(s1,s2),s3));
		}
		System.out.println(min);
		sc.close();
	}
}

Measured memory_bytes: 22100
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

n , x ,y = inp
p ((n+x-1)/x)*y


Measured memory_bytes: 14400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
bool a[150];
int main(){
    int n,k;cin >> n >> k;
    for(int i=1;i<=k;i++){
        int x;cin >> x;
        while(x--){
            int t;cin >> t;
            a[t]=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)if(!a[i])ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
/*input
6
30 10 60 10 60 50
*/

#include <bits/stdc++.h>
#define pb(x) push_back(x);
#define in(y) insert(y);
#define tt(t) while(t--)
#define int long long int
#define itr ::iterator it;
#define ll long long
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define si set<int>                      
#define msi map<string, int>
#define lines printsf("\n")
#define ff(n) for(int i=0;i<n;i++)
#define fors(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
const int MOD = 998244353;
int n, W;
int dp[103][100010];
vi wet,val;
int solve(int pos,int curW){
	if(pos>=n) return -99999999999LL;
	if(pos==n-1) return 0;
	if(curW>W) return -99999999999LL;
	if(curW==W) return 0;
	if(dp[pos][curW]!=-1) return dp[pos][curW];
	int ret = max(curW+wet[pos+1]<=W?solve(pos+1,curW+wet[pos+1])+val[pos+1]:0,solve(pos+1,curW));
	return dp[pos][curW]=ret;
}
signed main(){
	//ff(1000000-1) dp[i]=-1;
	ff(102){
		fors(j,0,100009){
			dp[i][j]=-1;
		}
	}
	cin>>n>>W;
	wet.resize(n); val.resize(n);
	ff(n){
		cin>>wet[i]>>val[i];
	}
	int ans = max(solve(0,0),solve(0,wet[0])+val[0]);
	cout<<ans;
}



Measured memory_bytes: 80128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

int main() {

	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	vector<ll> answer, answer2;
	answer.push_back(n);

	ll index = n;
	bool flag, flag2;
	flag2 = true;
	while (index > m) {
		flag = false;
		index -= m;
		for (ll i = 0; i < m; i++)
		{
			if (s[index + i] == '0') {
				// ok
				index = index + i;
				answer.push_back(index);
				flag = true;
				break;
			}
		}
		if (!flag) {
			flag2 = false;
			break;
		}
	}
	answer.push_back(0);

	if (flag2) {
		ll l = answer.size()-1;
		for (ll i = 0; i < l; i++)
		{
			answer2.push_back(answer[l - 1 - i] - answer[l - i]);
		}
		for (ll i = 0; i < l; i++)
		{
			cout << answer2[i];
			if (i == l - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}


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

int main() {
  string s;
  cin >> s;

  string ans = "";

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') ans.push_back('0');
    else if (s[i] == '1') ans.push_back('1');
    else if (ans != "") ans.pop_back();
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

import           Control.Exception (assert, evaluate)
import           Data.List         (foldl')
import           Data.Sequence     (Seq, ViewL ((:<), EmptyL), viewl, (|>))

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  evaluate $ assert (length s == n) ()
  q <- readLn
  ks <- take q . map read . words <$> getLine
  putStr . unlines . map (show . (\k -> f k s)) $ ks

f :: Int -> String -> Int
-- f k = dmc . foldl' g (initialState k)
f k = dmc . foldl' g initialState . defer k
  where
    g :: State -> (Char, Maybe Char) -> State
    g state (c, c') = (countIn c (maybe id countOut c' state))
    -- g state c = (countIn c (maybe id countOut c' state)) { queue = queue' }
    --   where
    --     (c', queue') = append (queue state) c

data State =
  State
  --- { queue :: FixedSizeQueue Char
  { d     :: !Int
  , m     :: !Int
  , dm    :: !Int
  , dmc   :: !Int
  }

defer :: Int -> [a] -> [(a, Maybe a)]
defer n xs = zip xs $ replicate n Nothing ++ map Just xs

-- initialState :: Int -> State
-- initialState n = State { queue = fixedSizeQueue n, d = 0, m = 0, dm = 0, dmc = 0 }
initialState :: State
initialState = State { d = 0, m = 0, dm = 0, dmc = 0 }

countIn :: Char -> State -> State
countIn 'D' count = count { d = d count + 1 }
countIn 'M' count = count { m = m count + 1, dm = dm count + d count }
countIn 'C' count = count { dmc = dmc count + dm count }
countIn _   count = count

countOut :: Char -> State -> State
countOut 'D' count = count { d = d count - 1, dm = dm count - m count }
countOut 'M' count = count { m = m count - 1 }
countOut _   count = count

data FixedSizeQueue a = FixedSizeQueue Int (Seq a)

fixedSizeQueue :: Int -> FixedSizeQueue a
fixedSizeQueue n = FixedSizeQueue n mempty

append :: FixedSizeQueue a -> a -> (Maybe a, FixedSizeQueue a)
append (FixedSizeQueue n q) x =
  let
    q' = q |> x
  in
    if length q' <= n
      then (Nothing, FixedSizeQueue n q')
      else case viewl q' of
             EmptyL   -> error "sequence must have more than n elements"
             y :< q'' -> (Just y, FixedSizeQueue n q'')


Measured memory_bytes: 145788
import std.stdio,std.string,std.algorithm,std.conv;

void main(){
    readln;
    auto a=readln.chomp.split.to!(ulong[]);
    ulong[ulong] l;
    foreach(x;a)
        l[x]++;
    ulong sum;
    foreach(x;l.values)
        sum+=x*(x-1)>>1;
    foreach(x;a)
        (sum-(l[x]-1)).writeln;
}

Measured memory_bytes: 26896
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

int solve()
{
    int N, K;

    std::cin >> N >> K;

    unordered_set<int> us;
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;

        for (int j = 0; j < d; ++j) {
            int snu;
            cin >> snu;

            us.insert(snu);
        }
    }

    return N - us.size();
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  ll X[N];
  ll ans = 0;
  for (int i=0; i<N; i++)
    cin >> X[i];
  for (int i=1; i<N; i++) {
    if ((X[i]-X[i-1])*A < B)
      ans += (X[i]-X[i-1])*A;
    else
      ans += B;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024