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

vector<vector<int>> is_connected;
vector<int> node_sum;
int n,q;

void add_to_child(int node,int parent){
	for(int i=0;i<(int)is_connected[node].size();i++){
		int tar = is_connected[node][i];
		if(tar == parent){continue;}
		node_sum[tar] += node_sum[node];
		add_to_child(tar,node);
	}
}
int main(){
	cin >> n >> q;
	is_connected.resize(n);
	node_sum.resize(n);
	for(int i=0;i<n;i++) node_sum[i] = 0;
	int a,b;
	for(int i=0;i<n-1;i++){
		cin >> a >> b;
		is_connected[a-1].push_back(b-1);
		is_connected[b-1].push_back(a-1);
	}
	for(int i=0;i<q;i++){
		cin >> a >> b;
		node_sum[a-1] += b;
	}
	add_to_child(0,-1);
	for(int i=0;i<n;i++){
		cout << node_sum[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 23424
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    char c;
    cin >> c;
    vector<char> v{'a', 'e', 'i', 'o', 'u'};
    for (auto x : v)
    {
        if (c == x)
        {
            puts("vowel");
            return 0;
        }
    }
    puts("consonant");
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
  
bool isP(int x){
  if(x==0||x==1)return false;
  for(int i=2;i*i<=x;i++){
    if(x%i==0)return false;
  }
  return true;
}
  
int main(){
  int n,a,cnt=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    cnt+=isP(a);
  }
  cout<<cnt<<endl;
}



Measured memory_bytes: 3092
n=int(input())
D={}
a_list=list(map(int,input().split()))
for i in a_list:
    if not i in D:
        D[i]=1
    else:
        D[i]+=1
l1=0
l2=0
for i in D:
    if D[i]>=2:
        if D[i]<4:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
        else:
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
            if i>l1:
                temp=l1
                l1=i
                l2=max(temp,l2)
            else:
                l2=max(i,l2)
print(l1*l2)


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

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);

    rep(i,N){
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());

    int min = 0;
    int count = 0;
    rep(i, N){
        if (min < vec.at(i)){
            min = vec.at(i);
            count += 1;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const LL MOD = 1000000007LL;
using namespace std;

int main() {
	set<int> s;
	rep(i, 3) {
		int a;
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void) {
	int i;
	int N, M;
	int a, b;
	int *roads;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	M = atoi(ch);

	roads = (int *)calloc(N, sizeof(int));

	for(i = 0; i < M; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		a = atoi(ch);
		ch = strtok(NULL, " ");
		b = atoi(ch);
		roads[a - 1] += 1;
		roads[b - 1] += 1;
	}
	for(i = 0; i < N; i += 1) {
		printf("%d\n", roads[i]);
	}

	free(roads);
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
ll S[202020];
ll L[202020][3];
ll R[202020];
ll dp[202020][5];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	dp[0][1]=dp[0][2]=dp[0][3]=dp[0][4]=1LL<<60;
	FOR(i,N) {
		cin>>A[i];
		dp[i+1][0]=dp[i][0]+A[i];
		dp[i+1][1]=min({dp[i][0],dp[i][1]})+((A[i]==0)?2:A[i]%2);
		dp[i+1][2]=min({dp[i][0],dp[i][1],dp[i][2]})+(1-A[i]%2);
		dp[i+1][3]=min({dp[i][0],dp[i][1],dp[i][2],dp[i][3]})+((A[i]==0)?2:A[i]%2);
		dp[i+1][4]=min({dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4]})+A[i];
	}
	cout<<min({dp[N][0],dp[N][1],dp[N][2],dp[N][3],dp[N][4]})<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

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

Measured memory_bytes: 256
# UnionFind
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(1000000)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,q=map(int,input().split())
uf=UnionFind(n)
for _ in range(q):
  t,u,v=map(int,input().split())
  if t==0:
    uf.unite(u,v)
  else:
    print(uf.root_same(u,v)+0)

Measured memory_bytes: 13316
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  int dp[n+1];
  dp[0] = 1;
  dp[1] = 1;
  for(int i = 2; i <= n; i++) {
    dp[i] = dp[i-1] + dp[i-2];
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 3100
#include <cstdio>
using namespace std;
typedef long long ll;
const int mod=1000000007;
ll mod_pow(ll x,ll n){
  ll res=1;
  if(n==0) return 1;
  if(n>0){
  res=mod_pow(x,n/2);
    if(n%2==0){
      res=(res*res)%mod;
    }
    else{
      res=(((res*res)%mod)*x)%mod;
    }
  }
  return res;
}
int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  printf("%d\n",mod_pow(n,m));
  return 0;
}

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

int main(){
  int N,M;
  
  int A[110];
  
  float ALL = 0.0f;
  
  cin>>N>>M;
  
  for(int i = 0;i < N;i++){
    
    cin>>A[i];
    
    ALL += A[i];
  
  }
  
  ALL /= 4 * M;
  
  int res = 0;
  
  for(int i = 0;i < N;i++){
    
   if(ALL <= A[i]){
     res++;
   }
  
  }
  
  if(res >= M){
    cout<<"Yes";
  }else{
    cout<<"No";
  
  }
  
  return 0;


}

Measured memory_bytes: 3592
#include <iostream>
#include <cassert>
#include <random>
#include <cstdlib>

#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int get_ans(const string& s) {
	int ans = 0;
	for (int j = 1; j < s.length(); ++j) {
		if (s[j] == s[j - 1]) {
			++ans;
			++j;
		}
	}
	return ans;
}

int main() {
	string s;
	cin >> s;
	int n = s.length();
	int k;
	cin >> k;
	string t = "";
	const int N = 40;
	if (k <= N + 10) {
		for (int j = 0; j < k; ++j) {
			t += s;
		}
		cout << get_ans(t) << endl;
		return 0;
	}
	for (int i = 0; i < N; ++i) {
		t += s;
	}
	long long ans1 = get_ans(t);
	t += s;
	long long ans2 = get_ans(t);
	t += s;
	long long ans3 = get_ans(t);
	t += s;
	long long ans4 = get_ans(t);
	assert(ans4 - ans2 == ans3 - ans1);
	long long start = ans1;
	int cur = N;
	long long diff = ans3 - ans1;
	int left = k - cur;
	cur += (left / 2) * 2;
	long long res = start + (left / 2LL) * diff;
	if (cur == k) {
		cout << res << endl;
	} else {
		cout << res + ans2 - ans1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<stdio.h>

long long calcce(long long pt[]){
  if(pt[0]==pt[1]&&pt[1]==pt[2]&&pt[2]==pt[3]){return 4;}
  if(pt[0]==pt[2]&&pt[1]==pt[3]){return 2;}
  return 1;
}

long long cha[1024][4];
long long ispt(long long tg,long long hash){
  if(cha[tg][0]==hash){return 1;}
  if(cha[tg][1]==hash){return 1;}
  if(cha[tg][2]==hash){return 1;}
  if(cha[tg][3]==hash){return 1;}
  return 0;
}

long long calc(long long cnt[]){
  long long i,j,k,l,res=0,dt;
  long long pj,pk,pl;
  //for(i=0;i<16;i++){printf("[%lld]",cnt[i]);}printf("\n");
  for(i=1;i<16;i+=2){//if((i&1)==0){continue;}
    if(cnt[i]==0){continue;}
    dt=cnt[i];cnt[i]--;
    pj=dt;
    for(j=0;j<16;j++){if((j&2)==0){continue;}
      if(cnt[j]==0){continue;}
      dt*=cnt[j];cnt[j]--;
      pk=dt;
      for(k=0;k<16;k++){if((k&4)==0){continue;}
        if(cnt[k]==0){continue;}
        dt*=cnt[k];cnt[k]--;
        pl=dt;
        for(l=8;l<16;l++){//if((l&8)==0){continue;}
          if(cnt[l]==0){continue;}
          dt*=cnt[l];cnt[l]--;
          res+=dt;
          cnt[l]++;
          dt=pl;
        }
        cnt[k]++;
        dt=pk;
      }
      cnt[j]++;
      dt=pj;
    }
    cnt[i]++;
  }
  return res;
}

int main(){
  //printf("%lld\n",(1ll<<10) + (2ll<<20) + (3ll<<30));
  srand(0);
  long long n,i,j,k,l,m,f,ce,res=0,tf,mem;
  long long c[512][4];
  long long jt[4],kt[4];
  long long md[4][4];
  long long cnt[16]={0};
  long long nha,mha[4];
  scanf("%lld",&n);
  //n=400;
  for(i=0;i<n;i++){
    nha=0;
    for(j=0;j<4;j++){
      scanf("%lld",&c[i][j]);
      //c[i][j]=rand()%4;
      nha|=(c[i][j]<<(10*j));
    }
    for(j=0;j<4;j++){
      cha[i][j]=nha;
      mem=(nha&((1ll<<10)-1));
      //printf("[%lld]<%lld>",cha[i][j],mem);
      nha>>=10;
      nha|=(mem<<30);
    }//printf("\n");
  }
  for(i=0;i<n;i++){
    for(j=0;j<4;j++){jt[j]=c[i][j];}
    for(j=i+1;j<n;j++){
      for(k=0;k<4;k++){
        for(l=0;l<4;l++){
          kt[l]=c[j][(4+k-l)&3ll];
        }
        ce=1;
        for(l=0;l<4;l++){
          md[l][0]=jt[l];
          md[l][1]=jt[(l+3)&3ll];
          md[l][2]=kt[(l+3)&3ll];
          md[l][3]=kt[l];
          mha[l]=(md[l][0]|(md[l][1]<<10)|(md[l][2]<<20)|(md[l][3]<<30));
          //printf("<%lld %lld %lld %lld : %lld>\n",md[l][0],md[l][1],md[l][2],md[l][3],mha[l]);
          ce*=calcce(md[l]);
        }
        for(l=0;l<16;l++){cnt[l]=0;}
        tf=0;
        for(l=i+1;l<n;l++){
          if(l==j){continue;}
          f=0;
          for(m=0;m<4;m++){
            if(ispt(l,mha[m])==1){f|=(1ll<<m);}
          }
          //printf("%lld\n",f);
          tf|=f;
          cnt[f]++;
        }
        if(tf!=15){continue;}
        res+=ce*calc(cnt);
      }
    }
  }
  printf("%lld\n",res);
  return 0;
}


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

struct block{int w,s;long long v;};
bool cmp(block a,block b){
  return a.w+a.s<b.w+b.s;
}
long long ans,dp[20001];

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

int main(){
  int n;cin>>n;
  vector<block> a(n);
  for(int i=0;i<n;i++){
    int w,s,v;cin>>w>>s>>v;
    a[i]={w,s,v};
  }
  sort(a.begin(),a.end(),cmp);
  for(int i=0;i<n;i++)
    for(int j=a[i].s;j>=0;j--)chmax(dp[j+a[i].w],dp[j]+a[i].v);
  for(int i=0;i<20001;i++)chmax(ans,dp[i]);
  cout<<ans<<endl;
}


Measured memory_bytes: 384
n = int(input())
L = list(map(int, input().split()))
count = 1
for i in range(len(L)):
  a = L[i]
  if a % 2 == 0:
    if a % 3 != 0 and a % 5 != 0:
    	count *= 0
if count == 0:
  print("DENIED")
else:
  print('APPROVED')

Measured memory_bytes: 38256
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll gcd(ll a, ll b) {//最大公約数
	if (a < b)swap(a, b);
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	if (a < b)swap(a, b);
	return (a / gcd(a, b))*b;
}

int main() {

	int h, w, d;
	cin >> h >> w >> d;
	vector<pi> v(h*w+1);
	vector<ll> ruizyouwa(h*w+1);
	
	rep(i, h) {
		rep(j, w) {
			int a;
			cin >> a;
			v[a] = mp(i + 1, j + 1);
		}
	}

	ruizyouwa[1] = 0;

	for (int i = d + 1; i < h*w+1; i++)ruizyouwa[i] = ruizyouwa[i - d] + abs(v[i].first - v[i-d].first) + abs(v[i].second - v[i-d].second);

	int q;
	cin >> q;
	rep(i, q) {
		int l, r;
		cin >> l >> r;
		pr(ruizyouwa[r] - ruizyouwa[l]);
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> dp(n+1,vector<int>(n+1,0));
    for(int i=n-1;i>0;i--){
        for(int j=i-1;j>-1;j--){
            if(s[i]==s[j]){
                dp[i][j]=dp[i+1][j+1]+1;
            }
            if(j+dp[i][j]==i+1){
                dp[i][j]=0;
            }
        }
    }
    int ans=0;
    rip(i,n,0){
        rip(j,n,0){
            ans=max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
}

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

int main(void) {
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        cin >> t.at(i);
    }
    sort (t.begin(), t.end());

    ll count_n = 0, timer = t.at(0), bus = 0;
    for (ll i = 0; i < n; i++) {
        if (t.at(i) - timer <= k) {
            count_n++;
        } else {
            timer = t.at(i);
            bus++;
            count_n = 1;
        }
        if (i == n - 1) {
            bus++;
            break;
        }
        if (c == count_n) {
            timer = t.at(i+1);
            bus++;
            count_n = 0;
        }
    }

    cout << bus << endl;
}

Measured memory_bytes: 1024
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[SZ(s)-1] == 's') cout << s << "es";
    else cout << s << "s"; 
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int n,k; cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h.at(i);

    vector<int> dp(n,1e9);
    dp.at(0) = 0;
    for(int i = 1; i < n; i++){
        int cost = 1e9;
        int point = i-1;
        while(point >= 0 && i - point <= k){
            int cost_now;
            cost_now = dp.at(point) + abs(h.at(point) - h.at(i));
            cost = min(cost_now,cost);
            point--;
        }
        dp.at(i) = cost;
    }
    
    cout << dp.at(n-1) << endl;
    return 0;   
}


Measured memory_bytes: 1024
n,m=list(map(int,input().split()))

par=[i for i in range(n)]
# ro=dict()
#
# for i in range(n):
#     ro[i]=1

def root(i):
    if par[i]==i:
        return i
    else:
        a=root(par[i])
        par[i]=a
        return a

def unite(x,y):
    rx=root(x)
    ry=root(y)
    if rx!=ry:
        par[rx]=ry
        # ro[ry]+=ro[rx]
        # ro[rx]=0

for i in range(m):
    a,b=list(map(int,input().split()))
    unite(a-1,b-1)

ans=set()

for i in range(n):
    rt=root(i)
    ans.add(rt)

# from collections import Counter as cnt
#
# bb=ro.values()
# ans=dict(cnt(ro.values()))

print(len(ans)-1)

Measured memory_bytes: 20832
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
const int inf=1<<28;
int N=17;
struct node{
	int c1,k1,c2,k2;
	node() {c1=c2=-inf;}
};
struct trnode{
	int lc,rc;
	node c;
}tr[6000010];int root=0,tot=0;
int a[300010];
node operator + (node c1,node c2)
{
	node ans;
	if(c1.c1>c2.c1)
	{
		ans.c1=c1.c1;ans.k1=c1.k1;
		if(c1.c2>c2.c2) ans.c2=c1.c2,ans.k2=c1.k2;
		else ans.c2=c2.c2,ans.k2=c2.k2;
		if(c2.k1!=ans.k1&&c2.c1>ans.c2) ans.c2=c2.c1,ans.k2=c2.k1;
	}
	else
	{
		ans.c1=c2.c1;ans.k1=c2.k1;
		if(c1.c2>c2.c2) ans.c2=c1.c2,ans.k2=c1.k2;
		else ans.c2=c2.c2,ans.k2=c2.k2;
		if(c1.k1!=ans.k1&&c1.c1>ans.c2) ans.c2=c1.c1,ans.k2=c1.k1;
	}
	return ans;
}
int n;
void insert(int &x,int c,int d,int v,int num)
{
	if(!x) x=++tot;
	if(d==-1) {node t;t.c1=v;t.k1=num;t.c2=-inf;tr[x].c=tr[x].c+t;return;}
	int op=(c&(1<<d))?1:0;
	if(op) insert(tr[x].lc,c,d-1,v,num);
	else insert(tr[x].rc,c,d-1,v,num);
	tr[x].c=tr[tr[x].lc].c+tr[tr[x].rc].c;
}
bool flag=false;
int merge(int x1,int x2,int d)
{
	int x=++tot;
	if(d!=-1) tr[x1].c=tr[tr[x1].lc].c+tr[tr[x1].rc].c;
	if(d!=-1) tr[x2].c=tr[tr[x2].lc].c+tr[tr[x2].rc].c;
	//if(x==30) printf("merge:%d %d %d %d %d\n",x1,x2,tr[x1].c.c1,tr[x2].c.c1,d);
	if(!x1||!x2) tr[x]=tr[x1+x2];
	else if(d==-1) tr[x].c=tr[x1].c+tr[x2].c;
	else
	{
		tr[x].lc=merge(tr[x1].lc,tr[x2].lc,d-1);
		tr[x].rc=merge(tr[x1].rc,tr[x2].rc,d-1);
		tr[x].c=tr[tr[x].lc].c+tr[tr[x].rc].c;
	}
	/*if(x==30)
	{
		printf("merge:%d %d\n",tr[x].c.c1,tr[x].c.c2);
		printf("%d %d\n",tr[x].lc,tr[x].rc);
		printf("%d %d %d %d\n",tr[tr[x].lc].c.c1,tr[tr[x].lc].c.c2,tr[tr[x].rc].c.c1,tr[tr[x].rc].c.c2);
	}*/
	return x;
}
void dfs(int x,int d)
{
	if(!x||d==-1) return;
	dfs(tr[x].lc,d-1);dfs(tr[x].rc,d-1);
	tr[x].lc=merge(tr[x].lc,tr[x].rc,d-1);
	tr[x].c=tr[tr[x].lc].c+tr[tr[x].rc].c;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<1<<n;i++) scanf("%d",&a[i]),insert(root,i,N,a[i],i);//,printf("%d %d\n",i,tot);
	/*int x=root;
	for(int i=N;i>=0;i--)
	{
		int c=(4&(1<<i))?1:0;
		if(c) x=tr[x].lc;
		else x=tr[x].rc;
		printf("%d %d %d %d %d %d\n",c,x,tr[x].c.c1,tr[x].c.c2,tr[tr[x].rc].c.c1,tr[tr[x].rc].c.c2);
	}	
	x=root;
	for(int i=N;i>=0;i--)
	{
		int c=(4&(1<<i))?1:0;
		if(c) x=tr[x].lc;
		else x=tr[x].rc;
		printf("%d %d %d %d %d %d\n",c,tr[x].rc,tr[x].c.c1,tr[x].c.c2,tr[tr[x].rc].c.c1,tr[tr[x].rc].c.c2);
	}
	printf("tot:%d\n",tot);*/
	dfs(root,N);
	for(int i=1;i<(1<<n)-1;i++)
	{
		int x=root,ans=-inf,k=i+1;
		for(int j=N;j>=0;j--)
		{
			int c=(k&(1<<j))?1:0;
			if(c) ans=max(ans,tr[tr[x].rc].c.c1+tr[tr[x].rc].c.c2),x=tr[x].lc;
			else x=tr[x].rc;
			//printf("ans:%d %d\n",i,ans);
		}
		printf("%d\n",ans);
	}
	printf("%d",tr[root].c.c1+tr[root].c.c2);
}

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

const int mod = 1e9 + 7;

struct combination {
    const int MAX = 510000;
    const int MOD;
    vector<long long> fac, finv, inv;

    combination(int mod) :MOD(mod) {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    long long COM(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

int main() {
    ll s;
    cin >> s;
    ll n = s / 3;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    combination com(mod);
    ll ans = 0;
    for (ll i = 1;i <= n;++i) {
        ll val = s - 3 * i;
        ans += com.COM(val + i - 1, val);
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15056
#C問題
N = int(input())
A = []
f = 0
s = 0
for i in range(N):
    a = int(input())
    if a >= f:
        s = f
        f = a
    elif a >= s:
        s = a
    A.append(a)

for i in range(N):
    if A[i] == f:
        print(s)
    else:
        print(f)

Measured memory_bytes: 12532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int l, r, d; 
	while (scanf("%d%d%d", &l, &r, &d) != EOF) {
		int i;
		int cnt = 0;
		for (i = l; i <= r; i ++) {
			if (i % d == 0) {
				cnt ++;
			}
		}
		printf("%d\n", cnt);
	}
	return (0);
}


Measured memory_bytes: 1704
import Foundation
 
let input_line = readLine()!
 
let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let N = Int(split[0])!
let K = Int(split[1])!
 
if K == 1 {
    print(0)
} else  {
    print(N - K)
}

Measured memory_bytes: 7908
#include<bits/stdc++.h>
using namespace std;
const int N=50005,M=1e6+5;
int n,m,q,mo,a[N],b[N],c[N],gg[N*6],i,j,k,z,x,s,t,r,g;
bool bb[2][M];
int gfa(int x){return gg[x]==x?x:gg[x]=gfa(gg[x]);}
inline void uni(int x,int y){gg[gfa(x)]=gfa(y);}
inline bool ask(int x,int y){return gfa(x)==gfa(y);}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m>>q>>mo;
	for(i=1;i<=n*6+6;++i)gg[i]=i;
	for(i=1;i<=m;++i)cin>>a[i]>>b[i]>>c[i],g=__gcd(g,abs(c[i]-c[1]));g?0:g=mo;mo=__gcd(mo,3*g);z=c[1]%g;
	for(i=1;i<=m;++i)for(c[i]%=mo,x=c[i]/g,j=0;j<2;++j)for(k=0;k<3;++k)
		uni(a[i]*6+j*3+k,b[i]*6+(1-j)*3+(k*2+x)%3),uni(b[i]*6+j*3+k,a[i]*6+(1-j)*3+(k*2+x)%3);
	for(i=0;i<2;++i)for(j=z*(i+1)%mo;!bb[i][j];bb[i][j]=1,j=j*4%mo);
	for(;q--;){
		bool ans=0;
		cin>>s>>t>>r;r%=mo;
		for(i=0;i<2;++i)for(j=0;j<3;++j)if(ask(t*6,s*6+i*3+j) && bb[i][(z+r+(3-j)*g)%mo])
			ans=1;
		cout<<(ans?"YES":"NO")<<'\n';
	}
	return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>
#include <string.h>
#define rep(i, a) for(int i = 0; i < a; ++i)

int main(void) {
  char s[1200], t[1200];
  int q, i, j, a, b;
  scanf("%s", s);
  scanf("%d", &q);
  rep(i, q) {
    scanf("%s %d %d", t, &a, &b);
    if(t[2] == 'i') {
      for(j = a; j <= b; ++j) printf("%c", s[j]);
      printf("\n");
    } else if(t[2] == 'v') {
      char d[1200];
      for(j = a; j <= b; ++j) d[j - a] = s[j];
      for(j = a; j <= b; ++j) s[j] = d[b - j];
    } else if(t[2] == 'p') {
      char p[1200];
      scanf("%s", p);
      for(j = a; j <= b; ++j) s[j] = p[j - a];
    }
  }
  return 0;
}


Measured memory_bytes: 2616
#include<iostream>
#include <string>

using namespace std;

int main(void)
{
	int k;
	string s;

	cin >> k;
	cin >> s;

	if (s.length() <= k)
	{
		cout << s << endl;
	}
	else
	{
		cout << s.substr(0, k) << "..." << endl;
	}

	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int acc = 0;
  int penalty = 0;
  vector<int> acc_arr(N);
  vector<int> penalty_arr(N);
  
  for(int i=0; i<M; i++){
    int p;
    string S;
    cin >> p >> S;
    if(acc_arr.at(p-1) != 1 && S == "WA"){
      penalty_arr.at(p-1) += 1;
      //penalty += 1;
    }else if(acc_arr.at(p-1) != 1 && S == "AC"){
      acc += 1;
      penalty += penalty_arr.at(p-1);
      acc_arr.at(p-1) = 1;
    }
  }
  cout << acc << " " << penalty << endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
N = int(input())
a = list(map(int, input().split()))

b = [None] * (N + 1)
for i, x in enumerate(a):
    b[x] = i

ans = 0
l_idx = list(range(N + 1))
r_idx = list(range(N + 1))
for i, p in reversed(list(enumerate(b))[1:]):
    l, r = l_idx[p], r_idx[p]
    ans += i * (p - l + 1) * (r - p + 1)
    l_idx[r + 1] = l
    r_idx[l - 1] = r

print(ans)


Measured memory_bytes: 58024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<pll> A(N);
    rep(i,N) {
        ll t,d; cin >> t >> d;
        A[i] = {d,t};
    }

    sort(all(A)); reverse(all(A));
    vector<ll> B = {0}, C = {0};
    set<ll> dic;
    ll type = 0;
    ll ans = 0;
    rep(i,N) {
        ll t,d;
        tie(d,t) = A[i];
        if (i < K) {
            if (dic.count(t)) {
                B.emplace_back(d);
            } else {
                ans += d;
                dic.emplace(t);
                type++;
            }
        } else {
            if (!dic.count(t)) {
                C.emplace_back(d);
                dic.emplace(t);
            }
        }
    }
    ll S = B.size()-1;
    ll T = C.size()-1;
    rep(i,S) {
        B[i+1] += B[i];
    }
    rep(i,T) {
        C[i+1] += C[i];
    }
    ll val = 0;
    int k = min(K - type,T);
    for (ll i = 0; i <= k; i++) {
        ll qwe = 0;
        qwe += C[i];
        qwe += B[S-i];
        chmax(val,qwe+(type+i)*(type+i));
    }

    cout << ans + val << endl;
}


Measured memory_bytes: 7032
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

for i in range(n-1):
    if a[i+1] == a[i]+1:
        b.append(c[a[i]-1])

print(sum(b))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    cin >> N;
    auto a = InputVec(N);
    map<pair<ll,ll>,ll> m;
    for (int i = 0; i < N; ++i) {
        ll A = i + 1;
        ll B = a[i];
        if(A > B){
            m[make_pair(A,B)]++;
        }else{
            m[make_pair(B,A)]++;
        }
    }
    auto beg = m.begin();
    auto end = m.end();
    ll count = 0;
    for (auto j = beg; j != end; ++j) {
        if(j->second == 2){
            count++;
        }
    }
    cout << count << endl;

}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()//a=97 z=122 A=65 Z=90
{
 long long int a,l=0;
 char c;
 cin>>a;
 int b[110];
 while(a)
 {
     b[l++]=a%26;
     if(b[l-1]==0) a-=1;
     a/=26;
 }
 l-=1;
 for(int i=l;i>=0;i--)
    if(b[i]==0) cout<<"z";
 else { c='a'+b[i]-1; cout<<c;}
    }


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

int main() {
  int N ;
  cin >> N ;
  string s;
  cin >> s;
  for(int i=0;i<s.size();i++){
    int x = (char)s.at(i);
    x += N;
    if(x>90)
      x-=26;
    
    cout << (char)x ;
  }
}

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

using namespace std;
int n,m,k,i,j,x,y,a[500005];
int tree[2000005];
queue <int>q[500005];
struct queries{
int l,r,poz,sol;
}v[500005];
inline bool cmp1(queries a,queries b)
{
    return a.l<b.l;
}
inline bool cmp2(queries a,queries b)
{
    return a.poz<b.poz;
}
inline void update(int nod,int st,int dr,int poz)
{
    if(st==dr)
        tree[nod]=1;
    else{
        int mij=(st+dr)>>1;
        if(poz<=mij)update(2*nod,st,mij,poz);
        else update(2*nod+1,mij+1,dr,poz);
        tree[nod]=tree[2*nod]+tree[2*nod+1];
    }
}
inline int query(int nod,int st,int dr,int l,int r)
{
    if(l<=st&&dr<=r)
        return tree[nod];
    else {
        int mij=(st+dr)>>1,x1=0,x2=0;
        if(l<=mij)x1=query(2*nod,st,mij,l,r);
        if(mij<r)x2=query(2*nod+1,mij+1,dr,l,r);
        return x1+x2;
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(i=1;i<=n;i++)
        {
            cin>>a[i];
            if(q[a[i]].size()==0)
                update(1,1,n,i);
            q[a[i]].push(i);

        }
    for(i=1;i<=m;i++)
    {
         cin>>v[i].l>>v[i].r;
         v[i].poz=i;
    }
    sort(v+1,v+m+1,cmp1);
    j=1;
    for(i=1;i<=m;i++)
    {
        while(j<v[i].l)
        {
            q[a[j]].pop();
            if(!q[a[j]].empty())
                update(1,1,n,q[a[j]].front());
            j++;
        }
        v[i].sol=query(1,1,n,v[i].l,v[i].r);
    }
    sort(v+1,v+m+1,cmp2);
    for(i=1;i<=m;i++)
        cout<<v[i].sol<<'\n';
    return 0;
}


Measured memory_bytes: 355152
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}

//ifstream f(".in");
//ofstream g(".out");

struct Line {
  ll a, b;
  ll valAt(ll x) {
    return a * x + b;
  }
};

bool intersectsEarlier(const Line &curr, const Line &last, const Line &to_intersect) {
  return (curr.b - to_intersect.b) * (to_intersect.a - last.a) <=
         (last.b - to_intersect.b) * (to_intersect.a - curr.a);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif

  ll n, c;
  cin >> n >> c;
  vector<ll> h(n + 2);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }

  vector<Line> dq;
  int first = 0, sz = 1, last = 0;
  dq.push_back({-2 * h[1], h[1] * h[1]});
  for (int i = 2; i <= n; ++i) {
    ll x = h[i];
    while (sz >= 2 && dq[first].valAt(x) >= dq[first + 1].valAt(x)) {
      --sz;
      ++first;
    }

    ll curr_dp = dq[first].valAt(x) + x * x + c;

    if (i == n) {
      cout << curr_dp << '\n';
      break;
    }

    Line curr = {-2 * x, curr_dp + x * x};

    while (sz >= 2 && intersectsEarlier(curr, dq[last], dq[last - 1])) {
      dq.pop_back();
      --last;
      --sz;
    }

    dq.push_back(curr);
    ++sz;
    ++last;
  }

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}


Measured memory_bytes: 7792
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {

    int ans = 0;
    while (a.any!(e => e > 0)) {
        for (int i = 0; i < a.length; i++) {
            if (a[i] == 0) continue;

            int x = a[i];
            int last = i;
            for (int j = i + 1; j < a.length; j++) {
                if (a[j] == 0) break;
                x = min(x, a[j]);
                last = j;
            }

            for (int j = i; j <= last; j++) {
                a[j] -= x;
            }
            ans += x;
            break;
        }
    }
    return ans;

}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 256
import sys
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

k = int(input())
a = [int(i) for i in range(1, 10)]

heapify(a)
while len(a):
    tmp = heappop(a)
    keta = len(str(tmp))
    one = tmp % 10
    k -= 1
    for i in range(0, 10):
        if abs(one - i) <= 1:
            heappush(a, tmp * 10 + i)
    if k == 0:
        print(tmp)
        exit()


Measured memory_bytes: 82804
a = int(input())
kk = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 49, 54, 56, 63, 64, 72, 81}
if a in kk:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int a, b; cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;

    long double n, m, k, i, j, x, y, s=0, h, f=0;
    ll p=0;
    cin>>n>>m;
    for(i=0; i<n; i++){
        cin>>x>>y;
        h=sqrt((x*x) + (y*y));
        if(h<=m)p++;
    }
    cout<<p<<endl;
    return 0;
}




Measured memory_bytes: 3736
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n][2];
        for (int i = 0; i < n; i++) {
            a[i][0] = sc.nextLong();
            a[i][1] = sc.nextLong();
        }
        long ans = 0L;
        for (int i = n-1; i >= 0; i--) {
            if((a[i][0] + ans)% a[i][1] != 0)
            ans += a[i][1] - ((a[i][0] + ans)% a[i][1]);
        }
        System.out.println(ans);
        sc.close();
    }

}


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

int dfs(int r, vector<vector<bool>>& v) {
    int res = 0;
    if(r == v.size()) {
        for(int i=0; i<v[0].size(); ++i) {
            int cnt = 0;
            for(int j=0; j<r; ++j) {
                cnt += v[j][i];
            }
            res += max(cnt, r-cnt);
        }
        return res;
    }
    res = max(res, dfs(r+1, v));
    for(int i=0; i<v[r].size(); ++i) {
        v[r][i] = !v[r][i];
    }
    res = max(res, dfs(r+1, v));
    return res;
}

int main() {
    int r, c;
    while(cin >> r >> c, r) {
        vector<vector<bool>> v(r, vector<bool>(c));
        for(int i=0; i<r; ++i) {
            for(int j=0; j<c; ++j) {
                int a;
                cin >> a;
                v[i][j] = a;
            }
        }
        cout << dfs(0, v) << endl;
    }
}


Measured memory_bytes: 3004
#include<iostream>
using namespace std;
int main(){
    int i,x;
    cin>>x;
    for(i=1;i<=x;i++){
        if(i%3==0){
            cout<<" "<<i;    
        }else if(i%10==3){
            cout<<" "<<i; 
        }else{
            int temp = i;
            while(0<temp){
                temp/=10;
                if(temp%10==3){
                    cout<<" "<<i;
                    break;
                }
            }
        }   
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

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

  sort(t.begin(), t.end(), greater<int>());

//  for (int i=0; i<N; i++)
//   cout << t.at(i);
  int d = 0;
  for (int i=0; i<N; i++){
    if (i%2 != 0){
      d -= t.at(i); 
    } else {
      d += t.at(i);
    } 
  }

  cout << d;
  
}


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

def digit_sum(n, b):
    res = 0
    while n > 0:
        res += n % b
        n //= b
    return res

def main():
    n = int(input())
    s = int(input())
    ans = -1

    if n < s:
        ans = -1

    elif n == s:
        ans = n + 1

    else:
        key = []
        start, first = n, 1

        for i in range(1, n):
            first = digit_sum(n, start)
            end = start - n // i // (i + 1)
            if start == end+1:
                judge = start
                break

            while end > 1:
                if digit_sum(n, end) == i * (start - end) + first:
                    end -= 1
                    continue
                break
            next_start = end
            value = digit_sum(n, start)
            end = value + (start - end - 1) * i
            key.append((start, value, end, i, first))
            judge = start
            start = next_start
            if start == 1:
                break

        for i in range(2, judge + 1):
            sub = digit_sum(n, i)
            if sub == s:
                ans = i
                break
        else:
            for index, start, end, i, first in reversed(key):
                if end < s or s < start:
                    continue
                if (s - start) % i:
                    continue
                ans = index - (s - first) // i
                break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 116420
#include <iostream>

int main() {
    int A,B,C;
    std::cin >> A >> B >> C;

    int base = C % A;
    int amari;
    int i=1;
    bool ok =false;
    do{
        amari = (B*i + C ) % A;
        i++;
        if(amari == 0){
            ok = true;
        }
    }
    while(amari != 0 && amari != base);

    if(ok){
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }
    return 0;
}

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))


int main()
{
    int tst;
//
//    cin >> tst;
//
//    while(tst--)
//    {
//
//    }

//int a,b,i,j,k,l,m,n;
ll a,b,i,j,k,l,m,n;

cin >> n;
 m = (n+1000-1)/1000;
m = m*1000 - n;

//int ar[n+10];
//ll ar[n+10];
//for(i=0;i<n;i++)cin >>ar[i];

cout << m << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  
  vector<bool> flag_w(W,false);
  vector<bool> flag_h(H,false);
  vector<vector<char>> grid(H, vector<char>(W));

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> grid.at(i).at(j); 
      if ( grid.at(i).at(j) == '#' ){
        flag_h.at(i) = true;
        flag_w.at(j) = true;
      }
    }
  }

  for (int i=0; i<H; i++){
    if(flag_h.at(i) == true){
      for (int j=0; j<W; j++){
        if(flag_w.at(j) == true){
          cout << grid.at(i).at(j);
       }
      }
    cout << endl;
    }
  }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main(void){
    char *bit = (char *)calloc(128 * 1000 * 1000 , sizeof(char)); // 8 * 128000こ
    int N,tmp;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
        int index = tmp / 8;
        if(bit[index] & (1 << (tmp % 8))){
            printf("NO\n");
            exit(0);
        }
        bit[index] |=  ( 1 << (tmp % 8));
    }
    printf("YES\n");
    return 0;
}


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

#define maxn 100010

using namespace std ;
typedef long long ll ;

ll N,A,B ;
ll h[maxn] ;

bool check(int k) {
	ll C = A-B ;
	ll total = B*k ;
	ll t = 0 ;
	for(int i=0; i<N; i++) {
		if(h[i]<=total) continue ;
		if( (h[i]-total) %C==0)
			t += (h[i]-total) / C ;
		else t += (h[i]-total) / C + 1;
	}
	if(t<=k) return true ;
	return false ;

}

int main(void){
	scanf("%lld%lld%lld",&N,&A,&B) ;
	ll max = 0 ;
	for(int i=0; i<N; i++) {
		scanf("%lld",&h[i]) ;
		if(h[i]>max) max = h[i] ;
	}

	ll l = 0, r = max / B + 1 ;
	ll mid ;
	while(l<r) {
		mid = (l+r)/2 ;
		if(check(mid)) {
			r = mid ;
			
		} else {
			l = mid + 1 ;
		}
	}
	printf("%lld\n",l) ;

	return 0 ;
}

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

int main(){
  int h,w,n;
  cin >> h >> w;
  cin >> n;
  vector<int>a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  vector<vector<int>>ans(h,vector<int>(w+1));

  
  int color=0;
  for(int i=0; i<h; i++){
    if(i%2==0){
     for(int j=0; j<w; j++){
       if(a[color]==0) color++;
       a[color]--;
       ans[i][j]=color+1;
     } 
    }
    
    else {
     for(int j=w-1; j>=0; j--){
       if(a[color]==0) color++;
       a[color]--;
       ans[i][j]=color+1;
     }
    }

  }
  
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
     cout << ans[i][j] << " "; 
   }
    cout << endl;
  }
  
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
//#include <algorithm>
using namespace std;

int main()
{
	string s;
	
	cin>>s;
	if(s=="Sunny")
		cout<<"Cloudy";
	if(s=="Cloudy")
		cout<<"Rainy";
	if(s=="Rainy")
		cout<<"Sunny";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    //cout.precision(10);
    //int ok=0;
    ll h,w;
    cin>>h>>w;
    ll ans=w*(h/2);
    if(w==1||h==1)ans=1;
    else if(h%2){
        if(w%2==0)ans+=w/2;
        else ans+=w/2+1;
    }
    cout<< ans <<endl;
}

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

using namespace std;

#define ll long long




void solve() {

	string a, b;
	cin >> a >> b;
	int cnt = 0;
	for(int i = 0; i < a.length(); i++) {
		if(a[i] != b[i]) {
			cnt++;
		}
	}
	cout << cnt;

	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	solve();

	return 0;
}

Measured memory_bytes: 3816