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

int main(){
  int N,Q;
  cin>>N>>Q;
  string S;
  cin>>S;
  
  for(int i=0;i<N-1;i++){
    if(S.at(i)=='A' && S.at(i+1)=='C'){
      S.at(i)='o';
    }
    else{
      S.at(i)='x';
    }
  }
  S.at(N-1)='x';
  
  vector<int>sum(N+1);
  sum.at(0)=0;
  for(int i=1;i<N+1;i++){
    if(S.at(i-1)=='o')
      sum.at(i)=sum.at(i-1)+1;
    else
      sum.at(i)=sum.at(i-1);
  }
  
  
  
  for(int i=0;i<Q;i++){
    int l,r;
    cin>>l>>r;
    cout<< sum.at(r-1) - sum.at(l-1) <<endl;
  }
  
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
if ( N % findSumOfDigits(N) == 0 ) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


LL yhaa(LL x, LL n, LL mod){
    if (n == 0){
        return 1;
    }
    if (n%2 == 0){
        LL t = (yhaa(x,n/2, mod)) % mod;//偶数の時は半分
        return (t*t) % mod;
    }
    return (x * yhaa(x, n-1, mod)) % mod;
}

LL nCk(LL n,LL k,LL m){
    int K = k;
    LL X = 1;
    for(int i = 0; i < K;i++){
        X = (X*(n-i)) % m;
    }
    LL Y = 1;
    for(int i = 1; i < K+1; i++){
        Y = (Y*i) % m;
    }
    LL YY = yhaa(Y,1000000005,m);
    return (X*YY) % m;

}


int main(){
    int n, a, b;
    cin >> n >> a >> b;
    long long int m = 1000000007;
    if (n == 2){
        cout << 0 <<endl;
    }
    else{
        LL all = yhaa(2,n,m);
        LL C_a = nCk(n,a,m);
        LL C_b = nCk(n,b,m);
        if((all - C_a - C_b - 1 ) % m > 0){
            cout << (all - C_a - C_b - 1 ) % m << endl;
        }
        else{
            cout << m + (all - C_a - C_b - 1 ) % m << endl;
        }
    }
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

class Edge {
public:
    ll t;
    ll w;
    Edge() {}
    Edge(ll t, ll w): t(t), w(w) {}
};

ll N, M;
vector<ll> G[MAX];
vector<ll> ans;
bool visited[MAX];
bool flag;
void dfs(ll u) {
    ans.push_back(u);
    visited[u]=true;
    
    for(ll i=0; i<G[u].size(); i++) {
        ll v=G[u][i];
        if(!visited[v]) {
            dfs(v);
            return;
        }
    }
    return;
}


int main(void) {
    cin >> N >> M;
    ll i;
    ll a, b;
    for(i=0; i<M; i++) {
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    dfs(1);
    reverse(ans.begin(), ans.end());
    ans.pop_back();
    dfs(1);
    
    prin(ans.size());
    for(i=0; i<ans.size(); i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 10100
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::string s; std::cin >> s;
    long long k; std::cin >> k;
    int n = s.size();
    bool same = true;
    for (int i = 0; i < n - 1; i++) same &= s[i] == s[i + 1];
    if (same) {
        std::cout << k*n / 2 << std::endl;
        return 0;
    }
    if (k <= 3) {
        std::string t;
        for (int i = 0; i < k; i++) t += s;
        long long ans = 0;
        for (int i = 0; i < k*n - 1; i++) {
            if (t[i] == t[i + 1]) {
                ans++;
                for (char c = 'a'; c <= 'z'; c++) {
                    if (c == t[i] || (i < k*n - 2 && c == t[i + 2])) continue;
                    t[i + 1] = c;
                    break;
                }
            }
        }
        std::cout << ans << std::endl;
        return 0;
    }
    std::string t = s + s + s;
    long long a = 0, b = 0, c = 0;
    long long cnt = 1;
    for (int i = 1; i < 3 * n; i++) {
        if (t[i] == t[i - 1]) cnt++;
        else {
            if (i < n) a += cnt/2;
            else if (i < 2*n) b += cnt/2;
            else c += cnt/2;
            cnt = 1;
        }
    }
    c += cnt / 2;
    std::cout << a + (k - 2)*b + c << std::endl;
    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for(int i=0; i<M; i++){
    cin >> a[i];
    cin >> b[i];
  }

  vector<int> sum(N);
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++){
          if(a[j]==i+1){
            sum[i]++;
          }

          if(b[j]==i+1){
            sum[i]++;
          }
    }
  }

  for(int i=0; i<N; i++){
    cout << sum[i] << endl;
  }
}


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

using namespace std;
typedef bitset<101> bset;

int main()
{
    int n;
    while(cin >> n, n)
    {
        bset r[n+1];
        for(int i=1; i<=n; i++)
        {
            int m;
            cin >> m;
            while(m--)
            {
                int p;
                cin >> p;
                r[i][p] = true;
            }
        }
        int k;
        cin >> k;
        bset mask;
        for(int i=0; i<k; i++)
        {
            int l;
            cin >> l;
            mask[l] = true;
        }
        vector<int> s;
        for(int i=1; i<=n; i++)
        {
            if((r[i] & mask) == mask) s.push_back(i);
        }
        cout << (s.size()==1 ? s[0] : -1) << endl;
    }

}

Measured memory_bytes: 3112
# frozen_string_literal: true

H, W = gets.chomp.split.map(&:to_i)

field = H.times.map do
  gets.chomp.split('')
end

def any?(field)
  field.each do |line|
    return true if line.find('.')
  end
  false
end

def count_start_to_goal(field, start_x, start_y, count = 0)
  queue = [[start_x, start_y, 0]]
  hash = {}

  until queue.empty?
    # p queue
    # queue = queue.uniq
    x, y, num = queue.shift
    field[y][x] = num
    next if hash[[x, y]]
    hash[[x, y]] = num
    count = num

    break unless any?(field)

    if x + 1 < field[0].size && field[y][x + 1] == '.'
      # test
      queue.push [x + 1, y, num + 1]
    end

    if x - 1 >= 0 && field[y][x - 1] == '.'
      # field[y][x - 1] = '#'
      queue.push [x - 1, y, num + 1]
    end

    if y + 1 < field.size && field[y + 1][x] == '.'
      # field[y + 1][x] = '#'
      queue.push [x, y + 1, num + 1]
    end

    if y - 1 >= 0 && field[y - 1][x] == '.'
      # field[y - 1][x] = '#'
      queue.push [x, y - 1, num + 1]
    end

  end

  count
end

def copy_field(field)
  tmp = []
  field.each do |line|
    tmp << line.dup
  end
  tmp
end

field.each_with_index do |line, index_y|
  line.each_with_index do |block, index_x|
    next unless block != '#'

    tmp = count_start_to_goal(copy_field(field), index_x, index_y)

    @max ||= tmp

    @max = tmp if tmp > @max
  end
end

puts @max


Measured memory_bytes: 2428
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define va vector<long long int> a 
#define vb vector<long long int> b
const ll M = 998244353;
const ll inf = 1e18+5;
const ll INF=INT_MAX;
using namespace std;
void fast(){cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);}
ll bs(ll arr[], ll l, ll r, ll x){
	ll mid=0;
    if (r >= l){
		if (arr[mid] == x) return mid; 
        if (arr[mid] > x) return bs(arr, l, mid - 1, x); 
        return bs(arr, mid + 1, r, x); 
    }
    return -1;
}
ll power(ll x,ul y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}
const int max1=500001;
pair<int,int>st[4*max1];
int arr[max1],arr1[max1];
void buildtree(int si,int ss,int se){
	if(ss==se){
        st[si].first=arr1[ss];
        st[si].second=arr1[ss];
		return;
	}
	int mid=ss+(se-ss)/2;
	buildtree(2*si,ss,mid);
	buildtree(2*si+1,mid+1,se);
	if(arr1[mid]>arr1[mid+1]) st[si].first=st[2*si].first+st[2*si+1].first;
    else st[si].second=st[2*si].second+st[2*si+1].second;
	
}
int query(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return INF;
	if(ss>=qs && se<=qe)
		return st[si].first;
	int mid=ss+(se-ss)/2;
	int l=query(2*si,ss,mid,qs,qe);
	int r=query(2*si+1,mid+1,se,qs,qe);
	return min(l,r);
}
int geteven(int si,int ss,int se,int qs,int qe){
	if(ss>qe || se<qs) //completely outside
		return 0;
	if(ss>=qs && se<=qe)
		return st[si].second;
	int mid=ss+(se-ss)/2;
	int l=geteven(2*si,ss,mid,qs,qe);
	int r=geteven(2*si+1,mid+1,se,qs,qe);
	return l+r;
}
int getodd(int si,int ss,int se,int qs,int qe){
	if(qs>se || qe<ss) //completely outside
		return 0;
	if(ss>=qs && se<=qe)
		return st[si].first;
	int mid=ss+(se-ss)/2;
	int l=getodd(2*si,ss,mid,qs,qe);
	int r=getodd(2*si+1,mid+1,se,qs,qe);
	return l+r;
}
void update(int si,int ss,int se,int qi,int newval){
	if(ss==se){
        if(arr[ss]%2==1) st[si]={0,1};
        else st[si]={1,0};
		arr[ss]=newval;
		return;
	}
	int mid=ss+(se-ss)/2;
	if(qi<=mid) update(2*si,ss,mid,qi,newval);
	else update(2*si+1,mid+1,se,qi,newval);
	st[si].first=st[2*si].first+st[2*si+1].first;
    st[si].second=st[2*si].second+st[2*si+1].second;
}

int main(){
	fast();
	// fastio;
    string s,t;
    cin>>s>>t;
    ll n =  s.length();
    ll m= t.length();
    string r;
    ll ans = INT_MAX,c=0;
    for(ll i=0;i<n-m+1;i++)
    {
         r=s.substr(i,m);
         for(ll j=0;j<m;j++)
         {
             if(r[j]!=t[j])
             c++;
         }
         ans=min(ans,c);
         c=0;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define LL long long
#define re register
#define SIZE 105
using namespace std;
template <typename T>
inline void read(T &x)
{
	int f;char c;
	x=0,f=0,c=getchar();
	while(c<'0' && '9'<c)	f|=(c=='-'),c=getchar();
	while('0'<=c && c<='9')	x=(x<<3)+(x<<1)+c-48,c=getchar();
	x=f?-x:x;
}
int n,W;
int w[SIZE];
LL v[SIZE];
LL dp[10000005],ans=0;
int main()
{
	read(n);read(W);
	for(re int i=1;i<=n;++i)
		read(w[i]),read(v[i]);
	for(re int i=1;i<=n;++i)
		for(re int j=W;j>=1;--j)
			if(j-w[i]>=0)
				dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
			else
				break;
	for(re int i=1;i<=W;++i)
		ans=max(ans,dp[i]); 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define mod2 998244353
#define space 200005
//<<fixed << setprecision(9)

int dsu[space];
int cnt[space];
int parent(int x)
{
    if(dsu[x]==x)return x;
    return dsu[x]=parent(dsu[x]);
}
ll merge(int u,int v)
{
    u=parent(u);
    v=parent(v);
    if(u==v)return 0;

    ll ans=(ll)cnt[u]*cnt[v];
    cnt[u]+=cnt[v];
    dsu[v]=u;
    return ans;
    
}
int main()
{
    int n,i,j,t;
    boost;
    
    int m;
    cin>>n>>m;
    rep(i,1,n+1)
    {
        dsu[i]=i;
        cnt[i]=1;
    }
    pii arr[m];
    rep(i,0,m)
    {
        cin>>arr[i].F>>arr[i].S;
    }
    vector<ll> ans;
    ans.pb((ll)n*(n-1)/2);
    for(i=m-1;i>=1;i--)
    {
        ans.pb(ans.back()-merge(arr[i].F,arr[i].S));
    }
    reverse(ans.B,ans.E);
    
    for(auto z:ans)cout<<z<<"\n";


    return 0;
}



Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int len;
bool flag=true;
string s1,s2;

int main(){
	cin>>s1;
	len=s1.length();
	s2=s1;
	for(int i=0;i<len;i++){
		s2[i]=s1[len-i-1];
		if(s2[i]=='b') s2[i]='d';
		else if(s2[i]=='d') s2[i]='b';
		else if(s2[i]=='p') s2[i]='q';
		else if(s2[i]=='q') s2[i]='p';
	}
	for(int i=0;i<len;i++)
		if(s1[i]!=s2[i]) flag=false;
	if(flag) printf("Yes");
	else printf("No");
	return 0;
}

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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

ll calculateMod(ll n, ll expo, ll modSeed){
  ll ret = 1;
  rep(i, expo){
    ret *= n;
    ret = ret%modSeed;
  }
  return ret;
}

int main(){
    ll X,K,D;
    cin >> X >> K >>D;

    X = abs(X);
    ll straight = min(K, X /D);
    K -= straight;
    X -= straight * D;

    if(K%2==0){
      printl(X);
    }else{
      printl(D-X);
    }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+50;

ll n,cnt;

int main(){
    scanf("%lld",&n);
    if(n&1){
        puts("0");
        return 0;
    }
    n/=2;
    while(n){
        cnt+=n/5;
        n/=5;
    }
    printf("%lld\n",cnt);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

struct Dinic {
  struct Edge {
    int u, v;
    long long cap, flow;
    Edge() {}
    Edge(int u, int v, long long cap): u(u), v(v), cap(cap), flow(0) {}
  }; 
  int N;
  vector<Edge> E;
  vector<vector<int>> g;
  vector<int> d, pt;
  
  Dinic(int N): N(N), E(0), g(N), d(N), pt(N) {}

  void AddEdge(int u, int v, long long cap) {
    if (u != v) {
      E.emplace_back(Edge(u, v, cap));
      g[u].emplace_back(E.size() - 1);
      E.emplace_back(Edge(v, u, 0));
      g[v].emplace_back(E.size() - 1);
    }
  }

  bool BFS(int S, int T) {
    queue<int> q({S});
    fill(d.begin(), d.end(), N + 1);
    d[S] = 0;
    while(!q.empty()) {
      int u = q.front(); q.pop();
      if (u == T) break;
      for (int k: g[u]) {
        Edge &e = E[k];
        if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
          d[e.v] = d[e.u] + 1;
          q.emplace(e.v);
        }
      }
    }
    return d[T] != N + 1;
  }

  long long DFS(int u, int T, long long flow = -1) {
    if (u == T || flow == 0) return flow;
    for (int &i = pt[u]; i < g[u].size(); ++i) {
      Edge &e = E[g[u][i]];
      Edge &oe = E[g[u][i]^1];
      if (d[e.v] == d[e.u] + 1) {
        long long amt = e.cap - e.flow;
        if (flow != -1 && amt > flow) amt = flow;
        if (long long pushed = DFS(e.v, T, amt)) {
          e.flow += pushed;
          oe.flow -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }

  long long MaxFlow(int S, int T) {
    long long total = 0;
    while (BFS(S, T)) {
      fill(pt.begin(), pt.end(), 0);
      while (long long flow = DFS(S, T))
        total += flow;
    }
    return total;
  }
};
int main(){
	ios_base::sync_with_stdio(0);
	long long q,m,k,h,ans=0,sum=0,p,x,y;
	cin>>n;
	Dinic d(105);
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]>=0) {
			sum+=a[i];
			d.AddEdge(0,i,a[i]);
		}
		else{
			d.AddEdge(i,102,-a[i]);
		}
	}
	for(int i=1;i<=n;++i)
		for(int j=2*i;j<=n;j+=i)
			d.AddEdge(j,i,1e18);
	cout<<sum-d.MaxFlow(0,102);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int p[20];
int q[20];
int cost[1<<15];
int dp[1<<15];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	b--;
	int sz=0;
	int h=0;
	for(int i=0;i<a;i++){
		int d,e;
		scanf("%d",&d);
		for(int j=0;j<d;j++){
			h=i;
			scanf("%d",&e);
			p[sz]=i;
			q[sz]=e;
			sz++;
		}
	}
	bool jimei=true;
	for(int i=0;i<sz;i++)if(p[i])jimei=false;
	if(jimei){
		printf("0\n");return 0;
	}
	for(int i=0;i<(1<<sz);i++)dp[i]=999999999;
	dp[0]=0;
	for(int i=0;i<(1<<sz);i++){
		int w=0;
		for(int j=0;j<sz;j++)if(i&(1<<j))w+=q[j];
		if(w<=c)cost[i]=1;
		else cost[i]=999999999;
	}
	for(int i=0;i<(1<<sz);i++){
		for(int j=(1<<sz)-1-i;j;j=((j-1)&((1<<sz)-1-i))){
			dp[i+j]=min(dp[i+j],dp[i]+cost[j]);
		}
	}
	int ret=0;
	int now=0;
	for(int i=a-1;i;i--){
		for(int j=0;j<sz;j++){
			if(p[j]==i)now+=(1<<j);
		}
		ret+=dp[now]*2;
	}
	if(h>=b)ret-=b;
	else ret+=b-h-h;
	printf("%d\n",ret);
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int N = 200005;
int n, s[N];
int las[N], nex[N];
int ans = 0, dp[N];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", s+i);
		nex[las[s[i]]] = i;
		las[s[i]] = i;
	}
	dp[1] = 1;
	for(int i = 1; i < n; ++i) {
		dp[i + 1] = (dp[i + 1] + dp[i]) % mod;
		if(nex[i] != i+1) dp[nex[i]] = (dp[nex[i]] + dp[i]) % mod;
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 3328
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register LL 
#define RC register char
#define ed putchar('\n') 
#define space putchar(' ')
#define Pair pair<LL,LL>
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;

template <typename tp> inline void read(tp & x)
{
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0' && c<='9') {x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    x*=f;
}

template <typename Tp> inline void print(Tp x) 
{
    if(x<0) x=-x,putchar('-'); 
    if(x>9) print(x/10); 
    putchar(x%10+'0'); 
} 

int n;
int a[1000005];
int temp;

int main()
{
	read(n);
	for(RI i=1;i<=n;++i)
		read(a[i]),temp^=a[i];
	if(!temp)
		puts("Yes");
	else
		puts("No");
	return 0;
}

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

int main(){
	string s;
  	cin>>s;
  	int cnt = 0;
  	for(auto i:s){
      if(i == 'R') cnt++;
    }
  	if(s[0] == 'R' && s[2]=='R') {
            if(s[1] == 'R') cout<<"3"<<endl;
            else cout<<1<<endl;
  	}
  	else cout<<cnt<<endl;

  	return 0;
}


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

typedef long long ll;

ll o[65],z[65];

bool checkbit(ll N,int pos)
{
    return (bool)(N & (1LL<<pos));
}

int main()
{
    //freopen("in.txt","r", stdin);
    //freopen("out.txt","w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    ll n,x,m = 1e9+7;

    cin>>n;

    for(int i=0; i<n; i++)
    {
        cin>>x;
        for(int j=0; j<=61; j++)
        {
            if(checkbit(x,j))   o[j]++;
            else                z[j]++;
        }
    }

    ll ans = 0;

    for(ll i=0; i<=61; i++)
        ans = (ans+((((o[i]*z[i])%m)*((1LL<<i)%m))%m))%m;

    cout<<ans<<endl;

    return 0;
}


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

int main() {
  int A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;
  vector<int> vec = {A, B, C, D, E};
  int min = (A - 1) % 10;
  int mini = 0;
  for (int i = 1; i < 5; i++) {
    if ((vec[i] - 1) % 10 < min) {
      min = (vec[i] - 1) % 10;
      mini = i;
    }
  }
  int a, b, c, d, e;
  a = ((A - 1) / 10 + 1) * 10;
  b = ((B - 1) / 10 + 1) * 10;
  c = ((C - 1) / 10 + 1) * 10;
  d = ((D - 1) / 10 + 1) * 10;
  e = ((E - 1) / 10 + 1) * 10;
  vector<int> fun = {a, b, c, d, e};
  cout << a + b + c + d + e - fun[mini] + vec[mini] << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
x = {1:'+', -1:'-'}

for i in x:
    for j in x:
        for k in x:
            ans = [int(s[0]), i*int(s[1]), j*int(s[2]), k*int(s[3])]
            if sum(ans) == 7:
                print('{}{}{}{}{}{}{}=7'.format(s[0], x[i], s[1], x[j], s[2], x[k], s[3]))
                break
        else:
            continue
        break
    else:
        continue
    break

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

using namespace std;

const int N = 409;

int n;
long long dp[N][N];

int main() 
{
    cin >> n;
    long long s = 0;
    for (int i=1; i<=n; i++)
    {
        cin >> dp[i][i];
        s += dp[i][i];
    }
    
    for (int i=1; i<=n; i++)
        for (int j=i+1; j<=n; j++)
            dp[i][j] = 0;
    for (int len = 2; len <= n; len++)
    {
        for (int i=1; i<=n-len+1; i++)
        {
            int j = i + len - 1;
            long long cur = 1e18;
            long long sum = dp[j][j];
            for (int t = i; t<j; t++)
            {
                sum += dp[t][t];
                cur = min(cur, dp[i][t] + dp[t+1][j]);
            }
            dp[i][j] += cur + sum;
        }
    }
    cout << dp[1][n] - s;
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

using namespace std;

int main(){
	int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	int A[n][m],B[m][l];
	long long int C[n][l];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			C[i][j] = 0;
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < l; j++){
			scanf("%d",&B[i][j]);
		}
	}

	for(int i = 0; i < n; i++){
		for(int k = 0; k < l; k++){
			for(int j = 0; j < m; j++){
				C[i][k] += A[i][j]*B[j][k];
			}
		}
	}

	for(int i = 0; i < n; i++){
		for(int j = 0; j < l-1; j++){
			printf("%lld ",C[i][j]);
		}
		printf("%lld\n",C[i][l-1]);
	}
}


Measured memory_bytes: 2864
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {

	int num, hitPoint;
	cin >> num >> hitPoint;
	vector<int> throwDamage;
	int maxShakeDamage=0;

	for (int i = 0; i < num; ++i) {
		int s, t;
		cin >> s >> t;
		throwDamage.push_back(t);
		if (maxShakeDamage < s) maxShakeDamage = s;
	}

	sort(throwDamage.begin(), throwDamage.end(), std::greater<int>());

	int turn=0;
	int index = 0;
	while (hitPoint > 0) {
		if (maxShakeDamage > throwDamage[index]) {
			hitPoint -= maxShakeDamage;
		}
		else {
			hitPoint -= throwDamage[index];
			index++;
		}
		turn++;
	}

	cout << turn;
	system("pause");
	return 0;
}



Measured memory_bytes: 1008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ","
#define de(x) cout << #x << "=" << x << endl
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define lowbit(x) x&(-x)
const int N = 20000;
const int M = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    ll dx=abs(b-a);
    ll dv=v-w;
    if (dx==0) cout<<"YES";
    else if (dv<0) cout<<"NO";
    else if (t*dv>=dx) cout<<"YES";
	else cout<<"NO"; 
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
const int mod=1e9+7; 

int main()
{
//	freopen("input.txt","r",stdin);//设置 cin scanf 这些输入流都从 test.in中读取
    
    ll n,q;
    cin>>n>>q;
    int ans=0;
    while(n--)
    {
    	ll x,y;
    	cin>>x>>y;
    	if(q*q>=x*x+y*y) ans++;
	}
	cout<<ans;
    
	return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=10e9+7;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    ll N;
    cin>>N;
    ll h[N];
    rep(i,N) cin>>h[i];
    ll dp[100009];
    dp[0]=0;
    dp[1]=ABS(h[0]-h[1]);
    for(ll i=0;i<N-2;i++){
        dp[i+2]=min(dp[i]+ABS(h[i]-h[i+2]),dp[i+1]+ABS(h[i+1]-h[i+2]));
    }
    cout<<dp[N-1]<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f,g,h,i,j;
    cin>>a;
    vector<pair<long long int,long long int> >v;
    long long int ans=a-1,sum=0;
    for(i=1;i<=1000010;i++)
    {
        if(a%i==0)
        {
            ans=min(ans,i+a/i-2);
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
N, M = [int(n) for n in input().split(" ")]
R = []
for _ in range(M):
    R.append([int(n) - 1 for n in input().split(" ")])


class UnionFind:
    def __init__(self, n):
        self.par = []
        for i in range(n):
            self.par.append(i)

    def root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.root(self.par[x])
        return self.par[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx != ry:
            self.par[rx] = ry


unionfind = UnionFind(N)
for r in R:
    unionfind.unite(r[0], r[1])

ss = [unionfind.root(n) for n in range(N)]

aaa = list(set(ss))

print(len(aaa) - 1)
    




Measured memory_bytes: 31224
//AcFreak

#include<bits/stdc++.h>
#define  lint long long int 
#define MOD (lint )(1e9+7)
using namespace std;

int main()
{
      int a,b;
      cin>>a>>b;
      
      if(a>8 ||b>8)
      cout<<":("<<endl;
      else
      cout<<"Yay!"<<endl;
      return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long count = 0;
  for(int i = 1; i <= n; i++) {
    if(i % 3 != 0 && i % 5 != 0) {
      count += i;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;
public class Main
{
	public static int a[];
	public static String b[];
	public static boolean judge;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int I=in.nextInt();
		while(I-->0)
		{
			a=new int[9];
			b=new String[9];
			int p[]=new int[9];
			String p2[]=new String[9];
			judge=false;
			boolean use[]=new boolean[9];
			for(int i=0;i<9;i++)
				a[i]=in.nextInt();
			for(int i=0;i<9;i++)
				b[i]=in.next();
			make_perm(0,p,p2,use);
			System.out.println(judge ? 1:0);
		}
	}

	static void make_perm(int n,int p[],String p2[],boolean use[])
	{
		if(judge)
			return;
		if(n==9)
			check(p,p2);
		else 
		{
			for(int i=0;i<9;i++)
			{

				if(use[i]) 
					continue;
				p[n]=a[i];
				p2[n]=b[i];
				use[i] = true;
				make_perm(n+1,p,p2,use);
				use[i] = false;
			}
		}
	}

	static void check(int p[], String p2[])
	{
		if(((p[0]+1==p[1]&&p[1]+1==p[2])||(p[0]==p[1]&&p[1]==p[2]))
				&&((p[3]+1==p[4]&&p[4]+1==p[5])||(p[3]==p[4]&&p[4]==p[5]))
				&&((p[6]+1==p[7]&&p[7]+1==p[8])||(p[6]==p[7]&&p[7]==p[8])))
		{
			if(p2[0].equals(p2[1])&&p2[1].equals(p2[2])
					&&p2[3].equals(p2[4])&&p2[4].equals(p2[5])
					&&p2[6].equals(p2[7])&&p2[7].equals(p2[8]))
				judge=true;
			else
				return;
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 26560
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))

n, k = map(int, input().split())

temp = [0] * n
for i in range(k):
    d = int(input())
    l = list(map(int, input().split()))
    for j in l:
        temp[j-1] += 1


ans = 0
for i in temp:
    if (i == 0):
        ans += 1

print (ans)



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

int main(){
    int n;
    cin >> n;
    vector<P>ba(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
    ba[i].first = b;
    ba[i].second = a;
    }
    sort(ba.begin(), ba.end());
    int sum = 0;
    rep(i,n){
        sum += ba[i].second;
        if(sum > ba[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int n, y;
    scanf("%d%d", &n, &y);
    y /= 1000;
    fore(tens, 0, n)
        fore(fives, 0, n - tens) {
            int ones = n - tens - fives;
            if (tens * 10 + fives * 5 + ones == y) {
                printf("%d %d %d", tens, fives, ones);
                exit(0);
            }
        }
    printf("-1 -1 -1");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n,a,b;
    cin >> n >> a >> b;
    print(min(n*a,b));
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

int main(void){
    int K, N, ans=0;
    std::cin >> K >> N;
    std::vector<int> A(N);

    for (int i = 0; i<N; ++i){
        std::cin >> A.at(i);
    }

    ans = A.at(0) + K - A.at(N-1);

    for (int i=1; i<N; ++i){
        int tmp = A.at(i) - A.at(i-1);
        if (tmp > ans) ans = tmp;
    }

    ans = K - ans;

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3984
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var a = ReadLine();
            var b = new int[4];
            var Re = "No";

            b = StrinCharArrayIntArray(a);

            if (b[0] == b[1] && a[1] == a[2]) {
                Re = "Yes";
            }else if(a[1] == a[2] && a[2] == a[3]) {
                Re = "Yes";
            }


            Console.WriteLine(Re);
            ReadLine();
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StrinCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s; cin >> s;
	
	int ans1 = s.size();
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '0') continue;
		ans1 = std::min(ans1, std::max(std::min(i + 1, (int)s.size() - i), std::max(i, (int)s.size() - i - 1)));
	}
	
	int ans2 = s.size();
	for(int i = 0; i < s.size(); i++){
		if(s[i] == '1') continue;
		ans2 = std::min(ans2, std::max(std::min(i + 1, (int)s.size() - i), std::max(i, (int)s.size() - i - 1)));
	}
	
	cout << std::max(ans1, ans2) << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
   long int H, A, i, count=0;
   scanf("%ld %ld",&H, &A);
   for(i=0; ;i++)
   {
       H=H-A;
       count++;
       if(H<=0)
       {
           break;
       }
   }
   printf("%ld",count);
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
int n;string s;int k;
cin>>n>>s>>k;
char a=s[k-1];
for(char &x:s){
    if(x!=a)x='*';
}
cout<<s;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N,X,T;
  cin>>N>>X>>T;
  
  int a=(N+(X-1))/X;
  
  cout<<a*T<<endl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String n = sc.next();

		n = n.replace('9', '*');
		n = n.replace('1', '9');
		n = n.replace('*', '1');
		System.out.println(n);
	}
}


Measured memory_bytes: 21712
#include<stdio.h>

int main()
{
	while (1)
	{
		char num[1001];
		scanf("%s", num);
		if (num[0] == '0') break;
		int n, sum = 0;
		for (n = 0; num[n] != '\0'; n++)
		{
			sum += num[n] - '0';
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 968
from sys import stdin


def main():
    s = next_str()
    ans = []

    for v in s:
        if v == 'B':
            if len(ans) != 0:
                ans.pop()
        else:
            ans.append(v)

    print("".join(ans))


def next_str():
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    
    String s[]=new String[3];
    for(int i=0;i<3;i++){
      s[i]=sc.next();
    }
    for(int i=0;i<3;i++){
      System.out.print(s[i].charAt(0));
    }
    System.out.println("");
    
  }
}

Measured memory_bytes: 21588
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 1;
	rep(i, n) ans = min(ans + k, ans * 2);
	cout << ans << endl;
}


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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
#define FI first
#define SE second
const long mod = 1000000007;

int main(){
    int N;
    cin >> N;
    int x = 0;
    int y = 0;
    int time = 0;
    for(int i = 0;i < N;i++){
        int dummytime;
        int dummyx, dummyy;
        cin >> dummytime >> dummyx >> dummyy;
        int distance = abs(x-dummyx) + abs(y-dummyy);
        dummytime -= time;
//        cout << distance << "km per " << dummytime << " hour." << endl;
//        cout << "TEST1:" << distance << " <= " << dummytime << " ? TEST2:abs(" << dummytime << " - " << distance << ")%2 != 1?" << endl;
        if(distance > dummytime || abs(dummytime - distance)%2 == 1){
            cout << "No" << endl;
            ED
        }
        time += dummytime;
        x = dummyx;
        y = dummyy;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
l = max(A)+1
li = [0]*(l)
A.sort()

for a in A:
  if li[a] == 0:
    li[a] = 1
    for i in range(a*2, l, a):
      li[i] = 2
  elif li[a] == 1:
    li[a] = 2
print(li.count(1))


Measured memory_bytes: 105508
#python3
from collections import deque

def main():

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

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

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

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

Measured memory_bytes: 13024
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var P = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var result = 0;
            var min = int.MaxValue;
            for (int i = 0; i < N; i++)
            {
                if (P[i] <= min)
                {
                    min = P[i];
                    result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


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

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);

using namespace std;

const int maxn = (int) 1e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 

#define inf mod

typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        


vector<vi> mul(vector<vi> a, vector<vi> b){
  int n = sz(a), m = sz(a[0]), k = sz(b[0]);
  vector<vi> res (n, vi(k, 0));             
  forn(i, 0, n - 1)
    forn(j, 0, k - 1)
      forn(t, 0, m - 1)
        res[i][j] = (res[i][j] + (a[i][t] * 1ll * b[t][j]) % mod) % mod;
  return res;
} 
int n;
vector<vi> binpow(vector<vi> a, int b){
  vector<vi> res (n, vi(n, 0));
  forn(i, 0, n - 1) res[i][i] = 1;
  while(b){
    if(b & 1) res = mul(res, a);
    b >>= 1;
    a = mul(a, a);
  }
  return res;
}
int k;
main () {
  cin >> n >> k;
  vector<vi> dp(n, vi(n, 0));
  forn(i, 0, n - 1)
    forn(j, 0, n - 1)
      cin >> dp[i][j];
  dp = binpow(dp, k);
  int s = 0;
  forn(i, 0, n - 1)
    forn(j, 0, n - 1)
      s = (s + dp[i][j]) % mod;
  cout << s; 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];
  k--;
  n--;
  cout << (n + k - 1) / k << endl;

}

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

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

using namespace std;

const int maxn = 1234;
vector<int> edge[maxn * maxn], tmp[maxn * maxn];

/*
 2 -> 3 <- 1
 ^         | 
 |         |
  _ _ _ _ _

 2 -> 3    1
 ^         |  
 |         |
  _ _ _ _ _

topoSort to check cycle + longest path on the path, O(n^2)
*/
int color[maxn * maxn];
int dp[maxn * maxn];

bool dfs1(int u)
{
    if (color[u] == 2)
        return true;
    color[u] = 1; // visited
    for (auto v : edge[u])
    {
        if (color[v] > 0)
        {
            if (color[v] == 1)
                return false; // cycle
        }
        if (!dfs1(v))
        {
            return false;
        }
    }
    color[u] = 2;
    return true;
}

int dfs2(int u)
{
    if (dp[u])
    {
        return dp[u];
    }
    int cnt = 0;
    for (auto v : edge[u])
    {
        cnt = max(cnt, dfs2(v));
    }
    dp[u] = cnt + 1;
    return dp[u];
}
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j < n - 1; j++)
        {
            int a;
            cin >> a;
            tmp[i].push_back(a);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < n - 1; j++)
        {
            int r1 = i, c1 = tmp[i][j - 1];
            int r2 = i, c2 = tmp[i][j];
            if (r1 > c1)
                swap(r1, c1);
            if (r2 > c2)
                swap(r2, c2);
            int s = r1 * n + c1;
            int t = r2 * n + c2;
            edge[s].push_back(t);
        }
    }
    for (int i = 0; i < n * n; i++)
    {
        if (color[i] == 0 && !dfs1(i))
        {
            cout << "-1" << endl;
            exit(0);
        }
    }
    int ans = 0;
    for (int i = 0; i < n * n; i++)
    {
        ans = max(ans, dfs2(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 103168
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
long long func(int);
long long fib[45];
int main(void)
{
	int n,i;
	long long x;
	scanf("%d",&n);
	fib[0]=1;	fib[1]=1;
	for(i=2;i<=n;i++)	fib[i]=0;
	x=func(n);
	printf("%lld\n",x);
	return 0;
}
long long func(int nn)
{
	long long x;
	if(nn<2)	return fib[nn];
	else {
		if(fib[nn]==0)	{
			x=func(nn-1)+func(nn-2);
			fib[nn]=x;
			return x;
		}
		else return fib[nn];
	}
}	


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

int p[10001];
int main(void){
    rep(i, 10001) p[i] = 1;
    p[0] = p[1] = 0;
    for(int i=2; i<=10000; ++i) {
        if(p[i]==1) {
            for(int j=2; i*j <= 10000; ++j) p[i*j] = 0;
        }
    }

    int n;
    while(cin >> n) {
        int ans = 0;
        for(int i=1; i<=n; ++i) {
            if(p[i] == 1 && p[n-i+1] == 1) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1200
#include<stdio.h>
#define N 500002

int a[N];
int h;

void maxHeapify(int i){
  int l,r,largest,temp;
  l=2*i;
  r=2*i+1;
  
  if(l<=h&&a[l]>a[i]) largest=l;
  else largest=i;
  if(r<=h&&a[r]>a[largest]) largest=r;

  if(largest!=i){
    temp=a[i];
    a[i]=a[largest];
    a[largest]=temp;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  
  scanf("%d",&h);
  for(i=1;i<=h;i++) scanf("%d",&a[i]);
    
  for(i=h/2;i>=1;i--) maxHeapify(i);
  
  for(i=1;i<=h;i++) printf(" %d",a[i]);
  printf("\n");

  return 0;
}



Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
using namespace std;

char fld[1001][1001];
int dp[1001][1001];

int main(){
	int N;
	while(cin>>N,N){
		int ans=0;
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				if(i==0 || j==0){
					dp[i][j] = 0; continue;
				}
				cin>>fld[i][j];
				if(fld[i][j]!='.'){
					dp[i][j] = 0; continue;
				}
				dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
				if(fld[i-dp[i][j]][j-dp[i][j]]=='.') ans = max(ans,++dp[i][j]);
				else dp[i][j] = max(dp[i][j],1);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 6036
#include<bits/stdc++.h>
using namespace std;
int W[1000000], S[1000000];
int main(){
  int n; scanf("%d", &n);
  char s[1000000];
  scanf("%s", s);
  for(int i = 0; i < n; i++){
    //search -->
    W[i+1] = W[i];
    if(s[i] == 'W') W[i+1]++;
    //printf("%d\n", W[i+1]);
  }
 // puts("aaaaaaa");
  for(int i = n-1; i >=0;i--){
    //search <--
    S[i+1] = S[i+2];
    if(s[i] == 'E') S[i+1]++;
   // printf("%d\n", S[i+1]);
  }
  int ans = S[1]+W[1];
  for(int i = 1; i <= n; i++){
   // printf("%d %d\n", S[i+1], W[i-1]);
    ans = min(ans, S[i+1]+W[i-1]);
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 5760