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

int match(string a){
    if(a == "AC"){
        return 1;
    }else{
        return 0;
    }
}

int main(){
    int n,m;
    cin >> n >> m;
    string result[m];
    int wa = 0;
    int ac = 0;
    vector<bool> sub_ac(100000,0);//acしてるかどうか
    //WAなら0,ACなら1を入れることにする
    vector<int> wa_temp(100000,0);//ACするまでカウンター
    /*
        ACしたらその問題のいままでのWAがカウントされる
    */
    for(int i=0;i<m;i++){//入力と測定同時にやる
        int t;
        cin >> t >> result[i] ;
        if(!sub_ac[t] && match(result[i]) == 0){//ACしてない、かつ今回もWAだった
            wa_temp[t]++;
        }else if(!sub_ac[t] && match(result[i]) == 1){//ACしていない、かつ今回はACした
            sub_ac[t] = true;
            ac++;
            wa += wa_temp[t];
        }
    }
    std::cout << ac << " " << wa << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 6144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin>>n;
  ll temp=n;
  unordered_map<ll, ll> m;
  while(n%2==0)
  {
    m[2]++;
    n/=2;
  }
  for(ll i=3;i*i<=temp;i+=2)
  {
    while(n%i==0)
    {
      m[i]++;
      n/=i;
    }
  }
  if(n>2)
    m[n]++;
  ll ans=0;
  for(auto i:m)
  {
    ll b=i.second;
    //cout<<i.first<<" "<<i.second<<endl;
    ans+=ll(-1+sqrt(1+8*b))/2;
    //cout<<ans<<endl;
  }
  cout<<ans;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

int main(void){
    int H,W;
    cin>>H>>W;
    int ANS=0;
    char c[30][30];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>c[j][i];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(c[j][i]=='#') continue;
            int ans[30][30];
            for(int f=0;f<H;f++){
        for(int g=0;g<W;g++){
            ans[g][f]=999999;
        }
    }
            bool reached[30][30]={};
            queue<int> qx;
            queue<int> qy;
            int sx=j;
            int sy=i;
            qx.push(sx);
            qy.push(sy);
            int nowx,nowy;
            reached[sx][sy]=true;
            ans[sx][sy]=0;
            while(!qx.empty()){
                nowx=qx.front();
                nowy=qy.front();
                qx.pop();
                qy.pop();
                for(int k=0;k<4;k++){
                int nx=nowx+vx[k];
                int ny=nowy+vy[k];
                if(nx>=0&&ny>=0&&nx<W&&ny<H&&(!reached[nx][ny])&&c[nx][ny]=='.'){
                    reached[nx][ny]=true;
                    ans[nx][ny]=ans[nowx][nowy]+1;
                    qx.push(nx);
                    qy.push(ny);
                }
        }
    }
    for(int f=0;f<H;f++){
        for(int g=0;g<W;g++){
            if(ans[g][f]==999999) continue;
            ANS=max(ANS,ans[g][f]);
        }
    }
    }
    }
    cout<<ANS<<endl;
}


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


void solve(long long N, long long A, long long B){
    long long answer = 0;
    if(A == 0) {
        cout << answer << endl;
        return ;
    }

    answer = long(N / (A + B) ) * A;
    long long  mod = N % ( A+ B);
    long long b_m = mod - A;
    if(b_m <= 0) {
        answer += mod ;
        cout << answer << endl;
    }else {
        answer += A;
        cout << answer << endl;
    }
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll x, y, n, d;
  while (cin >> n >> d) {
    int ans = 0;
    while (n--) {
      cin >> x >> y;
      if (x * x + y * y <= d * d) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}

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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}

// Paste snippets here!!

//

void solve(long long N, long long K) {
  if(N%K==0) cout << 0 << endl;
  else cout << 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  long long K;
  std::cin >> K;
  solve(N, K);
  return 0;
}


Measured memory_bytes: 3620
Sa=list(input())
Sb=list(input())
Sc=list(input())

str_dct={'a':Sa, 
         'b':Sb, 
         'c':Sc}

ref_str=Sa[0]
for counter in range(10**6):
    temp_ref=str_dct[ref_str].pop(0)
    
    if len(str_dct[temp_ref]) ==0:
        print(temp_ref.upper())
        break
    
    ref_str=temp_ref

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    rep(i, s.size()) {
        if(i%2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
        else if(i%2 == 1 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
unordered_map<int, int> freq;
long long res;
int n, x;
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        res += freq[i - x];
        ++freq[x + i];
    }
    cout << res;
    PLEC
}


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

using namespace std;

struct Unionfind {
    vector<int> par;
    vector<int> rank;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        else {
            if (rank[x] < rank[y]) par[x] = y;
            else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }
    }

    bool issame(int x, int y) { return root(x) == root(y); }
};

int main(){
  int n,q;
  cin>>n>>q;
  Unionfind uf;
  uf.init(n);
  for(int i=0;i<q;i++){
    int query,a,b;
    cin>>query>>a>>b;
    if(query==0)uf.unite(a,b);
    else cout<<(uf.issame(a,b)?1:0)<<endl;
  }
}

Measured memory_bytes: 4756
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		String X = nextString();
		String Y = nextString();

		String ans = "=";

		if(X.compareTo(Y)<0){
			ans="<";
		}else if(X.compareTo(Y)>0){
			ans=">";
		}
		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;
    vector<int> deli(N);
    rep(i, N) cin >> deli[i];

    ll ans = 0;
    rep(i, N) {
        repd(j, i + 1, N) {
            ans += (deli[i] * deli[j]);
        }
    }

    cout << ans << endl;
    return 0;
}

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

const int MOD = (int)1e9+7;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  int ans=0;
  int check=0;
  for(int i=1;i<N;i++){
    if(check==0){
      if(A.at(i)>A.at(i-1)) check=1;
      else if(A.at(i)<A.at(i-1))  check=-1;
      if(check!=0)  ans++;
    }
    else if(check==1 && A.at(i)<A.at(i-1))  check=0;
    else if(check==-1 && A.at(i)>A.at(i-1)) check=0;
  }
  if(check==0)  ans++;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <utility>
#include <string>

using namespace std;

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

  pair<float, string> p[10];

  for(int i = 0; i < N; ++i){
    cin >> p[i].first >> p[i].second;
  }

  float sum = 0;
  for(int i = 0; i < N; ++i){
    if(p[i].second[0] == 'J')
      sum += p[i].first;
    else if(p[i].second[0] == 'B')
      sum += p[i].first * 380000.0;
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
n,p = list(map(int,input().split())); s = [int(i) for i in input()]

ans = 0

if p == 2 or p == 5:
    for i in range(n):
        if s[i]%p == 0:
            ans += i+1
    print(ans)
    
else:
    s = s[::-1]
    res = [0] * p
    arr = [0] * n
    tmp = 0
    for i in range(n):
        tmp += s[i]*pow(10,i,p)
        tmp %= p
        arr[i] = tmp
    for i in arr:
        res[i] += 1
    for i in res:
        ans += i*(i-1)
    ans //= 2
    ans += res[0]
        
    print(ans)

Measured memory_bytes: 12364
#include <iostream>

int main()
{
	long move_count[5];
	long n;
	std::cin >> n;

	auto min_index = 0;
	for (auto i = 0; i < 5; i++)
	{
		std::cin >> move_count[i];

		if (i == 0) continue;
		if (move_count[i] < move_count[min_index])
		{
			min_index = i;
		}
	}

	long min = 0;

	for (auto i = 0; i < 5; i++)
	{
		if (i == min_index)
		{
			if (n < move_count[i])
			{
				min++;
			}
			else
			{
				if (n % move_count[i] != 0)
				{
					min++;
				}
				min += n / move_count[i];
			}
		}
		else
		{
			min++;
		}
	}

	std::cout << min;
}


Measured memory_bytes: 256
// START OF TEMPLATE CODE
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define funoredered_map __fast_unordered_map

template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair< double, double >;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vvi = vector<vi>;

constexpr int inf = 0x3f3f3f3f;
constexpr double eps = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll powmod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// END OF TEMPLATE CODE

int main()
{
    buff(); 
    ll n, x;
    cin >> n >> x;
    vector<ll> v(x);
    for(auto& k : v) cin >> k;
    ll tot = accumulate( all(v), 0ll, [&] (const ll a, const ll b) { return a + b; } );
    if( tot >= n ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

void Solution()
{
    int n;
    
    cin>>n;
    
    long sum = 1;
    
    for(int i = 1; i <= n; i++)
    {
        sum = sum * i;
    }
    
    cout << sum << endl;
    
    return;
}

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

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<functional>
using namespace std;
int n,res;
int A[20];
bool solve(int i,int m){
    if (m == 0)
        return true;
    if (i >= n)
        return false;
    res = solve(i + 1, m) || solve(i + 1, m - A[i]) ;  
    return res;
}
   

int main(){
    int a,m,q;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a;
        A[i]=a;
    }
    cin>>m;
   
    for (int i=0;i<m;i++){
        cin>>q;
        if(solve(0,q)==true)
            cout<<"yes"<<endl;
        else  cout<<"no"<<endl;
    }
    return 0;
}




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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
vector<ll> A;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  std::cin >> s;
  if (s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3656
s=str(input())
a=list("zyxwvutsrqponmlkjihgfedcba")
a=a[::-1]
#print(a)


if "zyxwvutsrqponmlkjihgfedcba"==s:
    print(-1)
    exit()


if len(s)==26:
    s=s[::-1]#後ろから見ていく
    for i in range(len(s)):
        for j in range(i+1):
            #print(i,j,s[i],s[j])
            if s[i]<s[j]:#xyzの降順の流れが切れたところを変える
                s=s[::-1]
               # print(s)
                print(s[:-(i+1)]+s[-(j+1)])
                exit()
else:
    for i in a:
        if i not in s:
            s+=i
            break
    print(s)



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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int N;
bool ok(VI& xs, int d){
  for(int i=0;i<d;++i)
	for(int j=i;j+d<N;j+=d)
	  if(xs[j] != xs[j+d])
		return false;
  return true;
}

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

  cin >> N;
  VI xs(N); REP(i,N) cin >> xs[i];

  int ans = 0;
  for(int d=1;d*d<=N;++d){
	if(N%d == 0){
	  if(ok(xs,d)) ans = max(ans, N/d);
	  if(ok(xs,N/d)) ans = max(ans, d);
	}
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <set>
#include <string>
#define MAX 1000000001

using namespace std;
#define ll long long

int s[100001];
int a=0;
bool check(int mid){
    return s[mid]<=a;
}


int binary_search(int ok,int ng){
    while(abs(ok-ng)>1){
        int mid= (ok+ng)/2;
        if(check(mid))ok=mid;
        else ng=mid;
    }
    return ok;

}
int main(){
    int n,m;
    int ans=0;
    cin >> n;
    for(int i=0; i<n;i++){
        cin>>s[i];
    }
    cin>>m;
    for(int i=0; i<m;i++){
        cin>>a;
        if (s[binary_search(0,n)]==a){
            ans++;
        }
    }
    cout <<ans<<endl;
    return 0;
}



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

#define maxn 200005
#define mod 1000000007

typedef pair<int, int> P;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++)
        printf("x");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int A,B,M;
  cin>>A>>B>>M;
  int amin=1000000;
  int bmin=1000000;
  int a[A];
  int b[B];
  int x,y,c;
  int answer=0;
  for (int i=0;i<A;i++){
      cin>>a[i];
      amin=min(amin,a[i]);

  }
  for (int i=0;i<B;i++){
      cin>>b[i];
      bmin=min(bmin,b[i]);

  }
  answer=amin+bmin;
  for (int i=0;i<M;i++){
      cin>>x>>y>>c;
      answer=min(answer,(a[x-1]+b[y-1]-c));
  }
  cout<<answer<<endl;}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;

int main(){
  ll h;
  cin >> h;
  ll ans = 0;
  ll exp = 1;
  
  REP(i,MAX){
    ans += exp;
    exp *= 2;
    if(h == 1) break;
    h = floor(h/2);
  }
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long x,a,b;
    cin>>x>>a>>b;
    long long diff=a-b;
    if(diff>=0){
        cout<<"delicious\n";
    } else if(diff<0 && abs(diff)<=x){
        cout<<"safe\n";
    } else{
        cout<<"dangerous\n";
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if int(h) == 0 and int(w) == 0:break
    for i in range(h):
        for j in range(w):
            if i==0 or i==h-1 or j==0 or j==w-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int flag=1;
	while(1){
		if(a<=0||c<=0) break;
		if(flag){
			c-=b;
			flag=0;
		}
		else{
			a-=d;
			flag=1;
		}
	}
	if(a>0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}



Measured memory_bytes: 3652
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  str s;
  cin >> s;
  ll n = s.length();
  str ans = "yes";
  for(ll i = 0; i < n-1; i++){
    for(ll j = i+1; j < n; j++){
      if(s[i]==s[j]) ans = "no";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//2018.09.21 4min

#include <iostream>
using namespace std;

int main() {

    int n;
    cin >> n;
    int a[n];
    int i;
    int f=0;

    for(i=0;i<n;i++){
        cin >> a[i];
        f+=a[i]-1;
    }

    cout << f << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ll R, C, Q;
    while (cin >> R >> C >> Q, R) {
        vector<ll> a(Q), b(Q), order(Q);
        for (int i = 0; i < Q; i++) {
            cin >> a[i] >> b[i] >> order[i];
        }
        vector<bool> used_a(R, 0), used_b(C, 0);
        ll r = 0, c = 0, res = 0;
        for (int i = Q-1; i >= 0; i--) {
            if (a[i] == 0) { // ???
                if (!used_a[b[i]]) {
                    used_a[b[i]] = 1;
                    r++;
                    if (order[i] == 1) {
                        res += C - c;
                    }
                }
            } else {         // ???
                if (!used_b[b[i]]) {
                    used_b[b[i]] = 1;
                    c++;
                    if (order[i] == 1) {
                        res += R - r;
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4056
#include<stdio.h>
int main(){
  int i,x,n,a,j,b;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    a=10;
  //CHEK_NUM
    if(i%3==0){
      printf(" %d",i);
    }
    else if(i%10==3){
      printf(" %d",i);
    }
    else{
      for(j=0;j<4;j++){
        b=i/a;
        if(b%10==3){
          printf(" %d",i);
          break;
        }
        a=a*10;
      }
    }
  }
      printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

const int mod = 1e9 + 7;
void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}
int mul (int a, int b) {
	return (ll) a * b % mod;
}

int main() {
	string k; cin >> k;
	const int n = k.size();
	int d; cin >> d;
	vector < vector < int > > dp (d, vector < int > (2));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		vector < vector < int > > dp_new (d, vector < int > (2));
		for (bool already_smaller : {false, true}) {
			int end = k[i] - '0';
			if (already_smaller) end = 9;
			for (int next_digit = 0; next_digit <= end; next_digit++) {
				bool smaller = already_smaller || (next_digit < end);
				for (int current_sum = 0; current_sum < d; current_sum++) {
					add_self (dp_new[(current_sum + next_digit) % d][smaller], dp[current_sum][already_smaller]);
				}
			}
		}
		dp = dp_new;
	}
	cout << (dp[0][0] + dp[0][1] - 1 + mod) % mod << endl;
	return 0;
}



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

int n,m;
vector<bool>visited(50);
vector<vector<bool>>graph(50,vector<bool>(50));

void dfs(int v){
  visited.at(v)=true;
  for(int v2=0;v2<n;v2++){
    if(graph[v][v2]!=true){
      continue;
    }
    if(visited[v2]==true){
      continue;
    }
    dfs(v2);
  }
}


int main() {
  cin >>n>>m;
  vector<int>a(m);
  vector<int>b(m);
  for(int i=0;i<m;i++){
    cin >>a.at(i)>>b.at(i);
    a.at(i)--;
    b.at(i)--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  int ans=0;
  for(int i=0;i<m;i++){
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
    bool all_visited=true;
    for(int j=0;j<n;j++){
      visited.at(j)=false;
    }
    dfs(0);
    for(int j=0;j<n;j++){
      if(visited[j]!=true){
        all_visited=false;
      }
    }
    if(all_visited==false){
      ans++;
    }
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  cout <<ans;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  bool c = true;
  for (int i = 1; i < 1010; ++i){
	if (i * 8 / 100 == a && i * 10 / 100 == b){
		cout << i << "\n";
		c = false;	
		break;	
	}
  }
  if (c){
	cout << -1 << "\n";
  }
return 0;
}


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

int main(){
	int n;
	int step[35];

	step[0]=0;
	step[1]=1;
	step[2]=2;
	step[3]=4;

	for(int i=1;i<30;i++){
		step[i+3]=step[i+2]+step[i+1]+step[i];
	}
	while(cin>>n){
		if(n==0)return 0;
		if(step[n]%3650==0){
			cout<<step[n]/3650<<endl;
		}else{
			cout<<step[n]/3650+1<<endl;	
		}
	}
	return 0;
} 

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793238;
const LL inf64 = 1000000111111222222;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 100007;


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int x; cin >> x;
	int last = 1800;
	int kyu = 1;
	while (1) {
		if (x >= last) {
			cout << kyu << endl;
			break;
		}
		last -= 200;
		kyu++;
	}
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

string s;
ll n;

int main(){
    cin >> s;
    n = s.size();

    ll ans = 0;
    string ss = "";
    rep(i,n){
        if(s[i]=='x') continue;
        else{
            ss.pb(s[i]);
        }
    }

    string ss2 = ss;
    reverse(all(ss2));

    if(ss != ss2){
        cout << -1 << endl;
        return 0;
    }

    int l,r;
    l = 0;
    r = n-1;
    while(l<r){
        if(s[l] == 'x' and s[r] == 'x'){
            l++;
            r--;
        }else if(s[l] == 'x' and s[r] != 'x'){
            ans++;
            l++;
        }else if(s[l] != 'x' and s[r] == 'x'){
            ans++;
            r--;
        }else{
            l++;
            r--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
int main() {
  int n,m;
  std::cin>>n>>m;

	int ans = (n*(n - 1)) / (2 * 1) + (m*(m - 1)) / (2 * 1);

	std::cout << ans << std::endl;
  return 0;
}

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

using namespace std;
using ll = long long;

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

    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for (auto &e : a)
        cin >> e;
    for (int _ = 0; _ < q; _++) {
        ll x;
        cin >> x;

        ll ans = 0;
        ll sum = 0;
        ll r = 0;

        for (int l = 0; l < n; l++) {
            while (r < n && sum + a[r] <= x) {
                sum += a[r];
                r++;
            }

            ans += (r - l);

            if (l == r) {
                r++;
            } else {
                sum -= a[l];
            }
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3632
loop{
  a, op, b =  STDIN.gets.split(' ')
  a = a.to_i
  b = b.to_i

  case op
  when "+"
   puts a + b

  when "-"
  puts a - b
 
  when "*" 
   puts a * b

  when "/" 
   puts a / b
  
  else  
       
   break

  end

}

Measured memory_bytes: 8684
n = int(input())
li = list(map(int,input().split()))

ans = 0
li.sort()



for i in range(n-1):
    if i == 0:
        ans = (li[i] + li[i+1]) / 2
    else:
        ans = (li[i+1] + ans)/2

        
print(ans)
    

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>

using namespace std;
using sushi = pair<int, long>;
int N, K;
class SushiDesc
{
public:
    bool operator()(pair<int, long> n1, pair<int, long> n2)
    {
        return n1.second > n2.second;
    }
};
class SushiAsc
{
public:
    bool operator()(pair<int, long> n1, pair<int, long> n2)
    {
        return n1.second < n2.second;
    }
};
int main()
{
    cin >> N >> K;
    vector<sushi> items;
    map<int, int> type_count;
    for (int i = 0; i < N; i++)
    {
        int t, d;
        cin >> t >> d;
        items.push_back(make_pair(t, d));
        // type, point
        type_count[t] = 0;
    }
    sort(items.begin(), items.end(), [](sushi a, sushi b) -> int {
        return a.second < b.second;
    });
    priority_queue<sushi, vector<sushi>, SushiDesc> selected;
    priority_queue<sushi, vector<sushi>, SushiAsc> not_selected;
    long max_point = 0;
    long types = 0;
    for (int i = 0; i < N; i++)
    {
        auto item = items.back();
        if (i < K)
        {
            selected.push(item);
            if (type_count[item.first]++ == 0)
            {
                types++;
            }
            max_point += item.second;
        }
        else
        {
            not_selected.push(item);
        }
        items.pop_back();
    }
    max_point += types * types;
    // cout << max_point << endl;
    long prev = max_point;
    for (;;)
    {
        if (not_selected.empty())
        {
            goto finish;
        }
        auto item = not_selected.top();
        not_selected.pop();
        if (type_count[item.first] != 0)
            continue;
        sushi old_item;
        for (;;)
        {
            if (selected.empty())
            {
                goto finish;
            }
            old_item = selected.top();
            selected.pop();
            if (type_count[old_item.first] == 1)
                continue;
            type_count[old_item.first]--;
            break;
        }
        // cout << "remove " << old_item.first << "/" << old_item.second << " and insert " << item.first << "/" << item.second << endl;
        types++;
        type_count[item.first]++;
        // cout << max_point << " " << prev - old_item.second + item.second + types * types - (types - 1) * (types - 1) << endl;
        max_point = max(max_point, prev = prev - old_item.second + item.second + types * types - (types - 1) * (types - 1));
    }
finish:

    cout << max_point << endl;
    return 0;
}


Measured memory_bytes: 9072
import java.io.*;
import java.util.*;

public class Main {

	static long m = (long) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int s = scn.nextInt();
		System.out.println(s >= n ? "unsafe" : "safe");
	}

	static class Scanner {

		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 32556
#include <iostream>
using namespace std;
int main(){
    int r,d ,x,A[200];
    cin>>r>>d>>x;
    A[0]=x;
    for(int i=0; i<10;i++){
            A[i+1]=A[i]*r-d;
            cout<<A[i+1]<<endl;
            A[200]+=(A[i+1]);

    }
        return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

[A, B, K] = [int(i) for i in input().split()]

minimum = min(A, B)
maximum = max(A, B)

divers = []
# 小さいほうの約数を求める
for i in range(1, minimum+1):
    if minimum % i == 0:
        divers.append(i)

common_divers = []
# 公約数を求める
for i in divers:
    if maximum % i == 0:
        common_divers.append(i)
#print(common_divers)

# K番目を出力する
print(common_divers[-K])


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

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

namespace mod {
    long long pow(long long a, long long x, long long p) {
        long long res = 1;
        while(x > 0) {
            if( x % 2 != 0) {
                res = (res * a) % p;
            }
            a = (a * a) % p;
            x /= 2;
        }
        return res;
    }

    long long inverse(long long a, long long p) {
        //calculates the modular multiplicative of a mod m.
        //(assuming p is prime).
        return pow(a, p-2, p);
    }

    long long factorial(long long a, long long p) {
        long long fact = 1;
        for (long long i=2; i<=a; i++) {
            fact *= i;
            fact %= p;
        }
        return fact;
    }
}

void solve(long long N, long long K){
    ll sum = 0;
    vector<ll> cnt(K+1);
    rrep(gcd,1,K+1) {
        cnt[gcd] = mod::pow(K / gcd, N, MOD);
        rep(j,2, K/gcd+1) {
            cnt[gcd] += MOD;
            cnt[gcd] -= cnt[gcd * j];
            cnt[gcd] %= MOD;
        }
        sum += gcd * cnt[gcd];
        sum %= MOD;
    }
    cout << sum << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

int main(){
    string s;
    cin >> s;
    queue<char> q;
    bool ch[s.length()];
    ch[s.length()-1]=true;
    LL ans=0;
    for(int i=0;i<pow(2,s.length()-1);i++){
        fill(ch,ch+s.length()-1,false);
        for(int j=0;j<s.length();j++){
            if((1&i>>j)==1) ch[j]=true;
        }
        for(int j=0;j<s.length();j++){
            q.push(s[j]);
            if(ch[j]) q.push('+');
        }
        string st;
        while(q.size()){
            char a=q.front();
            q.pop();
            if(a=='+'){
                ans+=stoll(st);
                st="";
            }
            else st=st+a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L



int main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (auto& x : A) cin >> x;
    long long ans = 0;
    sort(A.begin(), A.end());
    for (int i = 0;i < N; i++) {
        for (int j = i +1; j < N; j++) {
            int start = j + 1;
            long long sum = A[i] + A[j] -1;
            auto it = upper_bound(A.begin(), A.end(), sum);
            int dist = distance(A.begin(), it);
            ans += max(0, dist - start);

        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;

int main(void) {
  int N, W;
  cin >> N >> W;
  ll w[110], v[110];
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }

  ll dp[110][100001];
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= W; j++) dp[i][j] = 0;
  }
  for (int i = 0; i < N; i++) {
    for (int wSum = 0; wSum <= W; wSum++) {
      if (wSum - w[i] >= 0) {
        dp[i + 1][wSum] = max(dp[i + 1][wSum], dp[i][wSum - w[i]] + v[i]);
      }
      dp[i + 1][wSum] = max(dp[i + 1][wSum], dp[i][wSum]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 80384
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long a,b,c,d,x[4],mx;
	scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
	x[0]=a*c;
	x[1]=a*d;
	x[2]=b*c;
	x[3]=b*d;
	mx=-1000000000000000000;
	for(int i=0;i<4;i++){
		if(mx<x[i]) mx=x[i];
	}
	printf("%lld\n",mx);
	return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<string>
using namespace std;
int main(){
  int N;
  cin>>N;
  double ans=0;
  for(int i;i<N;i++){
    double a;
    string b;
    cin>>a>>b;
    if(b=="JPY"){
      ans+=a;
    }
    else{
      ans+=a* 380000.0;
    }
  }
  cout<<ans;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  = 3.141592653589793238463;
const int N = 1e5+10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}


// Main Code

int main()
{
	int l;
	cin>>l;
	int ll = l;
	int r = log2(l);
	int cnt = 0;
	rep(i, 1, r+1)
	{
		cnt+= 2;
	}
	ll -= (1 << r);
	int curr = (1 << r);
	while(ll > 0)
	{
		int temp = log2(ll);
		cnt++;
		curr = curr + (1 << temp);
		ll -= (1 << temp);
	}

	cout<<r+1<<" "<<cnt<<endl;

	rep(i, 1, r+1)
	{
		cout<<i<<" "<<i+1<<" "<<(1<<(i-1))<<endl;
		cout<<i<<" "<<i+1<<" "<<0<<endl;
	}
	l -= (1 << r);
	curr = (1 << r);
	while(l > 0)
	{
		int temp = log2(l);
		cout<<temp+1<<" "<<r+1<<" "<<curr<<endl;
		curr = curr + (1 << temp);
		l -= (1 << temp);
	}
}


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

int main(void) {
  string N;
  int K;
  cin >> N >> K;
  int m = N.length();
  // 0 確定，1 未確定
  vector<vector<vector<long long>>> dp(
      m + 1, vector<vector<long long>>(K + 1, vector<long long>(2, 0)));
  dp[1][0][0] = 1;
  dp[1][1][0] = N[0] - '0' - 1;
  dp[1][1][1] = 1;
  for (int i = 2; i <= m; i++) {
    int top = N[i - 1] - '0';
    for (int j = 0; j <= K; j++) {
      // 0を選ぶ
      if (top == 0) {
        dp[i][j][0] += dp[i - 1][j][0];
        dp[i][j][1] += dp[i - 1][j][1];
      } else {
        dp[i][j][0] += dp[i - 1][j][0] + dp[i - 1][j][1];
      }

      if (j == 0) continue;
      // 0以外を選ぶ
      // N以下が確定する時
      for (int k = 1; k < top; k++) {
        dp[i][j][0] += dp[i - 1][j - 1][1];
      }
      //未確定
      if (top != 0) {
        // topを選んでまだ未確定で続く
        dp[i][j][1] += dp[i - 1][j - 1][1];
      }

      for (int k = 1; k < 10; k++) {
        dp[i][j][0] += dp[i - 1][j - 1][0];
      }
    }
  }

  cout << dp[m][K][0] + dp[m][K][1] << endl;
  return 0;
}


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

using namespace std;

long long inf=1000000007;
vector<vector<long long>> grid(8,vector<long long>(8));//0=ok,1=queen,2=ng

void fill(long long y,long long x){
	long long i=y,j=x;
	while(i!=0 && j!=0){
		i--;
		j--;
		grid.at(i).at(j)=2;
	}

	i=y,j=x;
	while(i!=7 && j!=7){
		i++;
		j++;
		grid.at(i).at(j)=2;
	}

	i=y,j=x;
	while(i!=0 && j!=7){
		i--;
		j++;
		grid.at(i).at(j)=2;
	}

	i=y,j=x;
	while(i!=7 && j!=0){
		i++;
		j--;
		grid.at(i).at(j)=2;
	}

	i=0,j=x;
	while(i!=8){
		if(i!=y) grid.at(i).at(j)=2;
		i++;
	}

	i=y,j=0;
	while(j!=8){
		if(j!=x) grid.at(i).at(j)=2;
		j++;
	}
}

int main(){
	long long n;
	cin>>n;
	for(long long i=0;i<n;i++){
		long long x,y;
		cin>>y>>x;
		grid.at(y).at(x)=1;
		fill(y,x);
	}

	vector<long long> vec={0,1,2,3,4,5,6,7};
	vector<vector<long long>> ori=grid;

	do{
		grid=ori;
		bool flag=true;
		for(long long i=0;i<8;i++){
			if(grid.at(i).at(vec.at(i))!=2){
				grid.at(i).at(vec.at(i))=1;
				fill(i,vec.at(i));
			}else{
				flag=false;
				break;
			}
		}

		if(flag){
			for(long long i=0;i<8;i++){
				for(long long j=0;j<8;j++){
					if(grid.at(i).at(j)==1) cout<<'Q';
					else cout<<'.';
				}
				cout<<endl;
			}

			return 0;
		}
	}while(next_permutation(vec.begin(),vec.end()));

	return 0;
}



Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int main(){
	long long int a, b, k;
	cin >> a >> b >> k;
	if (a > k)
		cout << a - k << " " << b;
	else if (a + b < k)
		cout << 0 << " " << 0;
	else
		cout << 0 << " " << b - k + a;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int N, K;

int main() {
    cin >> N >> K;
    vector<int> x(N), y(N);
    vector<pair<int, int>> p(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        p[i] = make_pair(x[i], y[i]);
    }
    long long ans = 4e18;
    sort(x.begin(), x.end()); sort(y.begin(), y.end());
    for (int l = 0; l < N - 1; l++) {
        for (int r = l + 1 ; r < N; r++) {
            for (int s = 0; s < N - 1; s++) {
                for (int n = s + 1; n < N; n++) {
                    int cnt = 0;
                    for (int i = 0; i < N; i++) {
                        if (x[l] <= p[i].first &&
                            x[r] >= p[i].first &&
                            y[s] <= p[i].second &&
                            y[n] >= p[i].second) {
                            cnt++;
                        }
                        if (cnt == K) break;
                    }
                    if (cnt == K) {
                        ans = min(ans, 1LL * (x[r] - x[l]) * (y[n] - y[s]));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=1000005;
#define M 1000000007
#define double long double
#define init(arr,val) memset(arr,val,sizeof(arr))
#define BINF 1000000000001
const int LG = 22;




#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
    


    int n,k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x >= k) ans++;
    }
    cout << ans;





    

return 0;  
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int i,j;

	for(i = 1;i < 10;i++){
		for(j = 1;j < 10;j++){
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	
    return 0;
}

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

int N, K;
int a[110];
bool dp[110000];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> a[i];
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j < N; j++)
			if (i - a[j] >= 0)
				dp[i] |= !dp[i - a[j]];
	}
	if (dp[K]) cout << "First\n";
	else cout << "Second\n";
	return 0;
}

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

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

isSearched = [None] + [False] * n

distance = [None] + [-1] * n

def bfs(u):
    d = 0
    isSearched[u] = True
    distance[u] = d
    edge = [u]
    while edge:
        q = list(edge)
        edge = []
        d += 1
        for c_e in q:
            for n_e in adj[c_e]:
                if not isSearched[n_e]:
                    isSearched[n_e] = True
                    edge.append(n_e)
                    distance[n_e] = d


bfs(1)

for i, x in enumerate(distance[1:], start=1):
    print(i, x)

Measured memory_bytes: 7756
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int s;
    cin >> s;
    vector<int> b;
    if(s == 1 || s == 2){
        cout << '4' << endl;
        return 0;
    }
    b.pb(s);
    while(1){
        if(s%2 == 0){
            b.pb(s/2);
            s = s/2;
        }else{
            b.pb(3*s+1);
            s = 3*s+1;
        }
        if(s == 1){
            break;
        }
    }
    cout << b.size()+1 << endl;
}

Measured memory_bytes: 256