akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define pi pair
#define ff first
#define ss second
#define vi vector
#define ump unordered_map
ll m =  1e9+7;
void solve(){
	ll n;
	cin >> n;
	ll count = 0;
	forn(i,1,n){
		count += (n-1)/i;
	}
	cout<<count;
}
int main()
{
	fast;
	// int test;
	// cin >> test;
	// while(test--){
		solve();
	// 	cout<<"\n";
	// }
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<cctype>
#include<climits>
#include<bitset>
#include<stack>

using namespace std;

typedef long long ll;

const int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int MAX = 21;
int W, H, fld[10][10];
int P, sx, sy;
map<pair<pair<int, int>, int>, int> memo;

inline int CountBit(int s)
{
	int res = 0;
	for (int i = 0; i < P; i++) res += (s >> i) & 1;
	return res;
}

inline bool IsInside(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}

inline bool CanDown(int x, int y, int s, int noBits)
{
	if (x == sx && y == sy && noBits == P) return true;
	if (fld[y][x] == -1) return false;
	return ((s >> fld[y][x]) & 1) == 0;
}

int DFS(int x, int y, int s)
{
	int cnt = CountBit(s);
	if (x == sx && y == sy && cnt == P) return 1;
	pair<pair<int, int>, int> state = make_pair(make_pair(x, y), s);
	if (cnt < MAX)
	{
		map<pair<pair<int, int>, int>, int>::iterator itr = memo.find(state);
		if (itr != memo.end()) return itr->second;
	}
	int sum = 0;
	for (int i = 0; i < 4; i++)
	{
		int nx = x + dx[i], ny = y + dy[i];
		while (IsInside(nx, ny) && !CanDown(nx, ny, s, cnt))
			nx += dx[i], ny += dy[i];
		if (!IsInside(nx, ny)) continue;
		sum += DFS(nx, ny, s | (1 << fld[ny][nx]));
	}
	if (cnt < MAX && !(cnt >= 16 && sum == 0)) memo[state] = sum;
	return sum;
}

signed main()
{
	while (cin >> W >> H, W || H)
	{
		memo.clear();
		P = 0;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> fld[i][j];
				if (fld[i][j] == 0) fld[i][j] = -1;
				else if (fld[i][j] == 1) fld[i][j] = P++;
				else sx = j, sy = i, fld[i][j] = -1;
			}
		}
		printf("%d\n", DFS(sx, sy, 0));
	}
	return 0;
}

Measured memory_bytes: 39544
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#include <cassert>
#include <numeric>
#define ll long long int
#define LL unsigned long long
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;



int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n), sum(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    sum[0] = a[0];
    rep(i,n-1) sum[i+1] = sum[i] + a[i+1];

    rep(i,n) {
        if(sum[i] == x){
            cout << i + 1 << endl;
            return 0;
        }else if(sum[i] > x) {
            cout << i << endl;
            return 0;
        }
    }
    cout << n - 1 << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;

long long f[110][100100];

void readint(int &num){
    char c;
    while(!isdigit(c=getchar()));
    num=c^48;
    while(isdigit(c=getchar())) num=(num<<3)+(num<<1)+(c^48);
}

int main(){
    int N,W;
    scanf("%d%d\n",&N,&W);
    for(int i=0;i<=N;i++) fill(f[i]+1,f[i]+N*1000+1,(long long)(1e18+0.5));

    f[0][0]=0;
    for(int i=1;i<=N;i++){
        int w,v;
        scanf("%d%d",&w,&v);
        for(int j=1;j<=N*1000;j++){
            f[i][j]=f[i-1][j];
            if(j>=v) f[i][j]=min(f[i][j],f[i-1][j-v]+w);
        }
    }

    int ans;
    for(int i=0;i<=N*1000;i++)
        if(f[N][i]<=W) ans=i;
    return printf("%d\n",ans)&0;
}

Measured memory_bytes: 80000
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
////////////////////////////////////////////////////////////////////////////////


int main(){
   
   int n,k;
   cin >> n >> k;
   set<int> s;
   int y;
   
   for(int i =0;i<k;i++) cin >> y,s.insert(y);
   int ans = 0;
   while(1){
	   
	   string x = to_string(n);
	   int f = 0;
	   for(auto i: x){
		   if( s.find(i -'0') != s.end()){
			   f =1;
			   break;
		   } 
		   
	   }
	   if( f== 1) n++;
	   else {
		   ans = n;
		   break;
	   }
	   
   }
   
   cout << ans << endl;
     
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;

int main() 
{
	int t;
	cin >> t;
	
	int s(0);
	while(s<t)
	{
		s++;
		
		int n,m;
		cin >> n >> m;
		
		int p;
		cin >> p;
		
		int a[16][16]={};	// 1ならxが× 2ならyが× 3ならどちらも×
		
		for(int i=0;i<p;i++){
			int x1,y1,x2,y2;
			cin >> x1 >> y1 >> x2 >> y2 ;
			if(x1==x2){	a[x1][max(y1,y2)]+=2;	} //y方向が×
			if(y1==y2){	a[max(x1,x2)][y1]+=1;	}} //x方向が×
						
		int dp[16][16]={};

		for(int i=0;i<n+1;i++){
			for(int j=0;j<m+1;j++)
			{
				if(i==0 && j==0){dp[i][j] = 1;}
				else if(i==0){if(a[i][j]==0 || a[i][j]==1)dp[i][j] = dp[i][j-1];else dp[i][j] = 0;}
				else if(j==0){if(a[i][j]==0 || a[i][j]==2)dp[i][j] = dp[i-1][j];else dp[i][j] = 0;}
				else
				{
					if(a[i][j]==0){dp[i][j] = dp[i-1][j]+dp[i][j-1];}
					else if(a[i][j]==1){dp[i][j] = dp[i][j-1];}
					else if	(a[i][j]==2){dp[i][j] = dp[i-1][j];}
					else if(a[i][j]==3){dp[i][j] = 0;}}}}
		
		if(dp[n][m]==0){
			cout << "Miserable Hokusai!" << endl;
		}
		else{
		cout << dp[n][m] << endl;
		} 
	}
	return 0 ;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll X;
  cin >> X;
  cout << ((X == 7 || X == 5 || X == 3) ? "YES" : "NO") << rt;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
int main(void){
    while(1){
        int ans = 0;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        for(int i = 0;i < n;i++) cin >> a[i];
        
        sort(a.begin(),a.end());
        for(int i = 0;i < n;i++){
            if(i == 0 || i == n-1) continue;
            ans += a[i];
        }
        cout << ans/(n-2) << endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;

int main()
{
    fast;
    
	ll n, t;
	cin>>n>>t;

	ll a[n],b[n];
	
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	
	b[n-1]=a[n-1];
	for(ll i=n-2;i>=0;i--)
	{
		b[i]=max(a[i],b[i+1]);
	}
	vector<ll>ans;
	
	for(ll i=0;i<n;i++)
	{
		ans.push_back(b[i]-a[i]);
	}
	
	sort(ans.begin(),ans.end());
	
	ll cnt=1;
	
	for(ll i=ans.size()-2;i>=0;i--)
	{
		if(ans[i]!=ans[i+1])	
		{
			break;
			
		}
		else
		cnt++;
	}
	
	cout<<cnt;




}



		
	
	
	
	


Measured memory_bytes: 5836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long n = scn.nextLong();
		long[] x = new long[5];
		x[0]=scn.nextLong();
		long min = x[0];
		for(int i = 1;i<5;i++) {
			x[i]=scn.nextLong();
			if(x[i]<min) {
				min=x[i];
			}
		}
		System.out.println((n-1)/min+5);
		scn.close();
	}
}

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

using namespace std;
using Graph = vector<vector<int>>;

int main() {

long long n,cn,cnt=0; cin >> n;

for (long long i = 1; i*i<=n-1; ++i)
{  
long long div = (n-1)/i;
   if ((n-1)%i==0&&i!=1)
   {
    cnt++; 
    //cout << "a" << i;
   }  
   if ((n-1)%div==0&&div!=1&&div!=i)
   {
    cnt++; 
    //cout << "ad" << div;
   }
}


for (long long i = 1; i*i <= n; ++i)
{
   if(n%i!=0) continue;
   cn = n;
   while(i!=1){
    if(cn%i==0)  cn=cn/i;
    else break;
   }
   if((cn-1)%i==0&&i!=1){
    cnt++;
    //cout << "i" << i;
   } 
   cn = n;
   long long div=n/i;
   if(div==i) continue;
   while(1){
    if(cn%div==0)  cn=cn/div;
    else break;
   }
   if((cn-1)%div==0){
    cnt++;
    //cout << "div" << div;
   } 
}


cout << cnt;
 return 0;

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  string s; cin >>s;
  int n = s.size();
  if (n == 1){
    int res = s[0] - '0';
    cout <<res <<endl;
    return 0;
  }

  bool ok = true;
  rep(i, n-1){
    if (s[i+1] != '9'){
      ok = false;
    }
  }

  if (ok){
    int res = 0;
    rep(i, n) res += s[i] - '0';
    cout <<res <<endl;
    return 0;
  }

  int res = s[0] - '1';
  res += (n-1) * 9;
  cout <<res <<endl;
  
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int r = sc.nextInt();
	    int D = sc.nextInt();
		int C = sc.nextInt();
	    int sum = 0;
		
		for(int i = 0; i <10; i++){
		sum = r * C - D;
		System.out.println(sum);
		C = sum;
		}
	}
}	

Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    int A[N];
    REP(i,N) cin >> A[i];
    vector<int> V;
    V.pb(A[0]);
    REPP(i,1,N){
        int left = -1,right = V.size(),tmp;
        while(right - left > 1){
            int mid = left + (right - left) / 2;
            if(mid == V.size()-1 && V[mid] >= A[i]){
                V.pb(A[i]);
                tmp = -1;
                break;
            }
            else if(V[mid] >= A[i]){
                left = mid;
            }
            else if(V[mid] < A[i]){
                right = mid;
                tmp = mid;
            }
        }
        if(tmp != -1) V[tmp] = A[i];
    }
    cout << V.size() << endl;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int MOD = inf + 7;
int dp[2019];
int dp1[2019];

string s;
int n , c , ans , i , j;
int32_t main(){
   fast;
   cin >> s;
   
   n = sz(s);
   dp[s[0] - '0']++;

   for(i=1 ; i<n ; i++){
      for(j=0 ; j<2019 ; j++) dp1[j] = 0;

      c = s[i] - '0';
      dp1[c]++;

      for(j=0 ; j<2019 ; j++){
         dp1[(j*10 + c)%2019] += dp[j];
      }
      ans += dp1[0];
      
      for(int j=0; j<2019 ; j++) dp[j] = dp1[j];
   }

   cout << ans;
}  


Measured memory_bytes: 3744
n,W = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]

dp = [[0]*(W+1) for _ in range(n+1)]

for i in range(n):
    w = li[i][0]
    v = li[i][1]
    for k in range(W+1):
        if  w>k:
            dp[i+1][k] = dp[i][k]
            continue
        dp[i+1][k] = max(dp[i][k-w]+v,dp[i][k])
print(dp[n][W])

Measured memory_bytes: 148656
from collections import Counter

n = int(input())
a = list(map(int, input().split()))

c = Counter(a)

result = 0
for num in c.keys():
    if num < c[num]:
        result += c[num] - num
    elif num > c[num]:  # numbers of appearance is less than the number. needs to delete all
        result += c[num]

print(result)

Measured memory_bytes: 18672
#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 500000;
int N;

int left(int i) { return i * 2; }
int rigth(int i) { return i * 2 + 1; }

int maxOf3Node (int data[], int base) {
  int l = left(base);
  int r = rigth(base);
  int leargest;
  if (l <= N && data[l] > data[base])
    leargest = l;
  else
    leargest = base;
  if (r <= N && data[r] > data[leargest])
    leargest = r;
  return leargest;
}

void maxHeapify(int data[], int i) {
  int leargest = maxOf3Node(data, i);
  if (leargest != i) {
    swap(data[leargest], data[i]);
    maxHeapify(data, leargest);
  }
}

void buildMaxHeap(int data[]) {
  for(int i =N/2; i>0; i--)
    maxHeapify(data, i);
}


int main() {
  int data[MAX + 1];
  cin >> N;
  for (int i = 1; i <= N; i++)
    cin >> data[i];

  buildMaxHeap(data);

  for (int i = 1; i <=N; i++) {
    cout << " " << data[i];
  }
  cout << endl;
}

Measured memory_bytes: 4956
s=input()
while len(s)>0:
    if s[-5:]=='dream' or s[-5:]=='erase':
        s=s[:len(s)-5]
        continue
    if s[-7:]=='dreamer':
        s=s[:len(s)-7]
        continue
    if s[-6:]=='eraser':
        s=s[:len(s)-6]
        continue
    print('NO')
    break
else:
    print('YES')


Measured memory_bytes: 3188
#include <stdio.h>

int main(){
    int N, A;
    int coinsisa;

    scanf("%d",&N);
    scanf("%d",&A);

    coinsisa=N%500;

    if(A>=coinsisa){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

return 0;
}


Measured memory_bytes: 128
number = gets.split.map do |x|
  x.to_i
end

counter = 0
sum = 0

for i in 1..number[0] do
  counter = 0
  j = i
    while j/10 != 0
      counter += j%10
      j /= 10
    end
  counter += j%10
  if counter >= number[1] and counter <= number[2]
    sum += i
  end
end

puts sum


Measured memory_bytes: 1788
#include<iostream>
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define pb(x) push_back(x)
#define gcd(a,b) __gcd(a,b)
#define all(v) v.begin(),v.end()
#define lcm(a,b) (a*b)/gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main()
{
  int n;
  cin>>n;
  int c0=0,c1=0,c2=0,c3=0;
  while(n--)
  {
  	string s;
  	cin>>s;
  	if(s=="AC")
  	{
  		c0++;
	  }
	  else if(s=="WA")
	  {
	  	c1++;
	  }
	  else if(s=="TLE")
	  {
	  	c2++;
	  }
	  else
	  {
	  	c3++;
	  }
  }
  cout<<"AC x "<<c0<<'\n';
   cout<<"WA x "<<c1<<'\n';
    cout<<"TLE x "<<c2<<'\n';
     cout<<"RE x "<<c3;
}


Measured memory_bytes: 3596
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 

const int N = 2e5 + 123;
const int M = 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int Sz = 501;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}

int n, k, dp[N], a[N], ans;
vector < int > g[N];

void dfs(int v = 1, int par = -1) {
  dp[v] = 0;
  for (auto to : g[v]) {
    dfs(to, v);
    dp[v] = max(dp[v], dp[to] + 1);
  }
  if (v == 1) return;
  if (dp[v] == k - 1 && par != 1) {
    ans++;
    //cout << "v = " << v << endl;
    dp[v] = -inf;
  } 
}
void solve() { 
  cin >> n >> k;
  for (int i = 1;i <= n;i++) {
    cin >> a[i];
    if (i > 1) g[a[i]].pb(i);
 //   if (i > 1) cout << a[i] << " " << i << endl;
  }
  ans = a[1] != 1;
  dfs(1);
  cout << ans << endl;
}

int main() {
  #ifdef wws
   freopen("in", "r", stdin);
  // freopen("out", "w", stdout);
  #endif 
  ios_base::sync_with_stdio(0);
  int tt = 1; 
  while(tt--) solve();
  return 0;
}

Measured memory_bytes: 15744
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nq=arr[0].split(" ").map(Number);
var s = arr[1];
var a=[0,0];
var cnt=0;
for(var i=1;i<s.length;i++){
   if(s[i]=="C" && s[i-1]=="A")cnt++;
   a.push(cnt);
}
var ans=[];
for(var i=2;i<nq[1]+2;i++){
   var lr=arr[i].split(" ");
   ans.push(a[lr[1]]-a[lr[0]]);
}
console.log(ans.join("\n"));

Measured memory_bytes: 34512
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll x, y;
	cin >> x >> y;
	ll ans = 0;
	while (x <= y) {
		ans++;
		x *=2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3608
N, K = list(map(int, input().split(" ")))
h = sorted(list(map(int, input().split(" "))))
h_ = sorted(set(h))
n = len(h_)
while n > 1:
    if h_[n//2] == K:
        print(len(h)-h.index(h_[n//2]))
        break
        
    elif h_[n//2] >= K:
        h_ = h_[:n//2]
    else:
        h_ = h_[n//2:]
    n = len(h_)
 
if n==1:
    if h_[0] < K: print(h[::-1].index(h_[0]))
    else: print(len(h)-h.index(h_[0]))


Measured memory_bytes: 11900
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}

/*
//深さ優先探索
void dfs(vector<vector<ll>> &gra,vector<bool> &seen, ll v){

	seen[v]=true;

	for(auto next : gra[v]){
		if(seen[next]){
			continue;
		}

		dfs(gra,seen,next);
	}
	
}
*/
const ll MOD=1000000007;

void solve(){

	ll n,m,c;
	cin>>n>>m>>c;
	vector<ll> b(m,0);
	vector<vector<ll>> a(n,vector<ll> (m,0));

	for(ll i=0;i<m;i++){
		cin>>b[i];
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			cin>>a[i][j];
		}
	}

	ll ans=0;
	for(ll i=0;i<n;i++){
		ll sum=0;
		for(ll j=0;j<m;j++){
			sum+=a[i][j]*b[j];
		}
		if(sum+c>0){
			ans++;
		}
	}
	
	cout<<ans<<endl;

}


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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	return n, as
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}
func resolve(n int, as []int) int {
	dp = make([][]int, len(as))
	for i := 0; i < len(as); i++ {
		dp[i] = make([]int, len(as))
		for j := 0; j < len(as); j++ {
			dp[i][j] = -1
			dp[i][j] = -1
		}
	}
	return _resolve(as, 0, len(as)-1)
}

var dp [][]int

func _resolve(as []int, l, r int) int {
	if dp[l][r] != -1 {
		return dp[l][r]
	}
	if l == r {
		dp[l][r] = as[l]
		return dp[l][r]
	}
	dp[l][r] = as[l] - _resolve(as, l+1, r)
	cand := as[r] - _resolve(as, l, r-1)
	if dp[l][r] < cand {
		dp[l][r] = cand
	}
	return dp[l][r]
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

typedef long long ll;

const int MAXN = 100005;

ll x[MAXN], v[MAXN], pref[MAXN], pref_max[MAXN], suf[MAXN], suf_max[MAXN];

ll n, C, res = 0;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> C;
	for (int i = 1; i <= n; i++)
		cin >> x[i] >> v[i];
	x[0] = 0, x[n + 1] = C;
	for (int i = 1; i <= n; i++)
	{
		pref[i] = pref[i - 1] + v[i] - (x[i] - x[i - 1]);
		pref_max[i] = max(pref[i], pref_max[i - 1]);
	}
	for (int i = n; i >= 1; i--)
	{
		suf[i] = suf[i + 1] + v[i] - 2 * (x[i + 1] - x[i]);
		suf_max[i] = max(suf[i], suf_max[i + 1]);
	}
	for (int i = 0; i <= n; i++)
		res = max(res, pref_max[i] + suf_max[i + 1]);
	for (int i = 1; i <= n; i++)
	{
		pref[i] = pref[i - 1] + v[i] - 2 * (x[i] - x[i - 1]);
		pref_max[i] = max(pref[i], pref_max[i - 1]);	
	}
	for (int i = n; i >= 1; i--)
	{
		suf[i] = suf[i + 1] + v[i] - (x[i + 1] - x[i]);
		suf_max[i] = max(suf[i], suf_max[i + 1]);	
	}
	for (int i = 0; i <= n; i++)
		res = max(res, pref_max[i] + suf_max[i + 1]);
	cout << res << endl;
	return 0;	
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5;

int a[maxn], dp[maxn];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i != n; ++i)
        scanf("%d", &a[i]);
    dp[1] = abs(a[0] - a[1]);
    for (int i = 2; i != n; ++i)
        dp[i] = min(
            dp[i - 1] + abs(a[i] - a[i - 1]),
            dp[i - 2] + abs(a[i] - a[i - 2]));
    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
 
N, K = mi()
A = li()

if K == 0:
    print(max(A))
    exit()

left = 0
right = max(A)
 
def count(num):
    cnt = 0
    for i in range(N):
        cnt += math.ceil(A[i] / num) - 1
    return cnt
'''
while True:
    mid = (left + right) // 2
    if mid == 0:
        print(1)
        break
    tmp = count(mid)
    if right - left <= 1:
        print(right)
        exit()
    elif tmp > K:
        left = mid
    else:
        right = mid
'''

def is_ok(arg):
    if count(arg) <= K:
        return True
    else:
        return False
    

def meguru_bisect(ng, ok):
    '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, right+1))

Measured memory_bytes: 30928
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))


int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll n,c,k;
ll a[100010];
int main(){
	scanf("%lld%lld%lld",&n,&c,&k);
	rep(i,0,n)scanf("%lld",a+i);
	sortup(a,n);
	
	ll ans=0;
	for(ll i=0;i<n;){
		ans++;
		ll t=i;
		while(t<n&&t-i<c&&a[t]<=a[i]+k)t++;
		i=t;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1788
#include <set>
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	set<int> a;
	set<int> b;

	for(int i=0;i<n;i++){
		int t; cin >> t;
		a.insert(t);
	}
	cin >> n;
	for(int i = 0; i < n;i++) {
		int t; cin >> t;
		b.insert(t);
	}

	int ans = 0;
	set<int>::iterator ita = a.begin();
	for (ita = a.begin();ita != a.end();ita++)
	{
		if (b.count(*ita) != 0) ans++;
	}
	cout << ans << endl;

	return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<string> word( N );
  vector<int> money( N, 1 );
  for ( int i = 0; i < N; i++ )
    cin >> word.at( i );  
  int M;
  cin >> M;
  vector<string> word2( M );
  vector<int> money2( M, -1 );
  for ( int i = 0; i < M; i++ )
    cin >> word2.at( i );
  word.insert(word.end(), word2.begin(), word2.end());
  money.insert(money.end(), money2.begin(), money2.end());
  int max = 0;
  int n;
  for ( int i = 0; i < N + M; i++ ) {
    string w = word.at( i );
    n = money.at( i );
    for ( int j = i + 1; j < N + M; j++ ) {
      if ( word.at( j ) == w )
        n += money.at( j );
    }
    if ( max < n )
      max = n;
  }
  cout << max << endl;  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;
typedef pair<int, int> P;
static const int INF = 1e9;
static const int SIZE = 100001;

struct edge
{
	int to, cost;
};

vector<edge> G[SIZE];
int d[SIZE];
int n;

void bfs(int v)
{
	for (int i = 0; i < n; ++i)
	{
		d[i] = INF;
	}
	d[v] = 0;
	priority_queue < P, vector<P>, greater<P> > pque;
	pque.push(P(0, v));
	while (!pque.empty())
	{
		P p = pque.top();
		pque.pop();
		int vertex = p.second;
		for (int i = 0; i < G[vertex].size(); ++i)
		{
			edge e = G[vertex][i];
			if (d[e.to] > d[vertex] + e.cost)
			{
				d[e.to] = d[vertex] + e.cost;
				pque.push(P(d[e.to], e.to));
			}
		}
	}
}

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;
	for (int i = 0; i < n - 1; ++i)
	{
		int s, t, w;
		cin >> s >> t >> w;
		edge e1, e2;
		e1.to = t;
		e2.to = s;
		e1.cost = e2.cost = w;
		G[s].push_back(e1);
		G[t].push_back(e2);
	}
	bfs(0);
	int maxDist = 0;
	int maxv = 0;
	for (int i = 1; i < n; ++i)
	{
		if (maxDist < d[i])
		{
			maxDist = d[i];
			maxv = i;
		}
	}
	bfs(maxv);
	maxDist = 0;
	for (int i = 0; i < n; ++i)
	{
		if (maxDist < d[i])
		{
			maxDist = d[i];
		}
	}
	cout << maxDist << endl;
}

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

Measured memory_bytes: 7992
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n,m=get_i
ans=array(n,1,"*")
if n==1 and m.zero?
  puts 0
else
m.times do|i|
  s,c=get_i
  s-=1
  if s>n
    ans=-1
    break
  elsif ans[s]=="*"
    ans[s]=c
  elsif ans[s]!=c
    ans=[-1]
    break 
  end 
end
ans[0]=1 if ans[0]=="*"
ans=[-1] if n!=1 and ans[0]==0
for i in 1..n-1
  if ans[i]=="*"
    ans[i]=0
  end
end
puts ans.join("")

end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int cmp(int x,int y){//使sort函数从大到小排序
    return x>y;
}
int main(){
    int n,a[100005],i;
    long long ansc=0,ansk=0;//ansc表示长方形的长，ansk表示长方形的宽。(一定要用long long!!!)
    bool use[100005]={0};//use数组用来判断第i根木棍是否已被使用。
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n,cmp);//排序
    for(i=1;i<=n;i++){
        if(a[i]==a[i-1]&&use[i-1]==0){//如果第i根木棍和第i-1根木棍长度一样且都没被使用
            if(ansc!=0){//如果ansc已经存储了值
                ansk=a[i];//存储宽的长度
                cout<<ansc*ansk;//输出面积
                return 0;
            }
            else {
                use[i-1]=1;//标注i-1已被使用
                use[i]=1;//标注i已被使用
                ansc=a[i];//存储宽的长度
            }
        }
    }
    cout<<ansc*ansk;//如果无法组成面积，可输出ansc*ansk。因为ansk一定为0，所以ansc*ansk=0。
    return 0;
}

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

int main(){
    int i, j, n, m, c, b[20];
    int cnt = 0;
    cin >> n >> m >> c;
    for(i = 0; i < m; i++){
        cin >> b[i];
    }
    for(j = 0; j < n; j++){
        int a, x = 0;
        for(i = 0; i < m; i++){
            cin >> a;
            x += a * b[i];
        }
        if(x + c > 0) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func PrimeFactorsMap(n int) map[int]int {
	pfs := map[int]int{}
	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2]++
		} else {
			pfs[2] = 1
		}
		//pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i]++
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		if _, ok := pfs[n]; ok {
			pfs[n]++
		} else {
			pfs[n] = 1
		}
	}

	return pfs
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(x, y int) int {

	return x * y / gcd(x, y)

}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

func main() {
	sc.Split(bufio.ScanWords)

	X := nextInt()
	l := 1
	i := 1
	for true {
		if X <= l {
			fmt.Println(i)
			return
		}
		l += (i + 1)
		i++
	}
}


Measured memory_bytes: 1776
import sys
from heapq import heappop, heappush

ans_l = []
T = int(input())
for t in range(T):
    N = int(input())
    left, right = [], []
    ans = 0
    for i in range(N):
        K, L, R = map(int, sys.stdin.readline().split())
        if L > R:
            ans += L
            left.append((K, L - R))
        elif L < R:
            ans += R
            right.append((K, R - L))
        else:
            ans += L
    # left
    pool = []
    pos = 1
    left.sort()
    cur = 0
    while cur < len(left):
        while cur < len(left) and left[cur][0] == pos:
            k, d = left[cur]
            heappush(pool, d)
            cur += 1
        while len(pool) > pos:
            d = heappop(pool)
            ans -= d
        pos += 1
            
    # right
    pool = []
    pos = N
    right.sort(reverse=True)
    cur = 0
    while cur < len(right):
        while cur < len(right) and right[cur][0] == pos:
            k, d = right[cur]
            heappush(pool, d)
            cur += 1
        while len(pool) > N - pos:
            d = heappop(pool)
            ans -= d
        pos -= 1

    ans_l.append(ans)


print(*ans_l, sep='\n')


Measured memory_bytes: 94540
//c
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
 
#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair
 
using namespace std;
 
static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;
 
int n, m;
int amat[500][500];
int vtx[500];
 
int solve(){
     
    queue<int> qu;
    qu.push(0);
     
    for(int i=0; i<n; ++i)
        vtx[i] = 0;
     
    while(!qu.empty()){
         
        int now = qu.front();
        qu.pop();
         
        for(int i=0; i<n; ++i){
             
            if(now != i && amat[now][i] != 0 && (vtx[i] < vtx[now] + amat[now][i]) ){
                vtx[i] = vtx[now] + amat[now][i];
                qu.push(i);
            }
        }
    }
     
    return vtx[n-1];
}
 
int main(){
     
    cin >> n >> m;
    CLR(amat);
     
    int a, b, c;
    for(int i=0 ; i<m; ++i){
        cin >> a >> b >> c;
        amat[a][b] = c;
    }
     
    cout << solve() << endl;
     
    return 0;   
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w,r;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n>>k;
    vl v(n),a(k+1,0);cin>>v;
    for(int i=1;i<=k;i++){
        x=0;y=0;
        fo(j,n){
            if(v[j]<=i)x++,y+=a[i-v[j]];
        }
        if(x>0&&y!=x)a[i]=1;
       //cout<<a[i]<<" "<<i<<" "<<x<<" "<<y<<el;
    }
    if(a[k])cout<<"First";
    else cout<<"Second";
    return 0;
}



Measured memory_bytes: 1024
n = int(input())
rl = []
bl = []
xs = [(-1,'',False)]*(2*n)
for _ in range(n):
    a,b = map(int, input().split())
    rl.append((a,b))
    xs[a] = (b,'r',False)


for _ in range(n):
    c,d = map(int, input().split())
    bl.append((c,d))
    xs[c] = (d,'b',False)

rl.sort(reverse=True)
bl.sort()

ans = 0
for rx,ry in rl:
    min_x,min_y = 10**5,10**5
    for x in range(rx,2*n):
        y,color,used = xs[x]
        if y > ry and color =='b' and not used and min_y > y:
            min_x = x
            min_y = y
    if min_x != 10**5:
        ans += 1
        xs[min_x] = (min_y,'b',True)

print(ans)

Measured memory_bytes: 69816
n,m=map(int,input().split())
S={}
for i in range(m):
    s,c=map(int,input().split())
    if s not in S:
        S[s]=c
    elif S[s]!=c:
        print(-1)
        exit()
    if n!=1 and s==1 and c==0:
        print(-1)
        exit()
    if n<s:
        print(-1)
        exit()

for i in range(0,1000):
    if len(str(i))==n:
        flag=True
        for j in S.keys():
            if int(str(i)[j-1])!=S[j]:
                flag=False
        if flag:
            print(i)
            exit()
print(-1)

Measured memory_bytes: 40432
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int n;
vector<ll> a;
vector<P> v;

ll mx = -10000000, mn = LINF;
ll mxi = 0, mni = 0;

int main(void) {
  cin >> n;
  rep(i, 0, n) {
    ll t;
    cin >> t;
    if (t>mx) {
        mx = t;
        mxi = i;
    }
    if (t<mn) {
        mn = t;
        mni = i;
    }
    a.pb(t);
  }


  if (abs(mx)>abs(mn)) {
      rep(i, 0, n) {
          if (i==mxi) continue;
          if (a[i]<0) {
              a[i] += a[mxi];
              v.pb(mp(mxi, i));
          }
      }
      rep(i, 0, n-1) {
          a[i+1] += a[i];
          v.pb(mp(i, i+1));
      }
  } else {
      rep(i, 0, n) {
          if (i==mni) continue;
          if (a[i]>0) {
              a[i] += a[mni];
              v.pb(mp(mni, i));
          }
      }
      for (int i=n-1; i>=1; i--) {
          a[i-1] += a[i];
          v.pb(mp(i, i-1));
      }

  }
  cout << sz(v) << "\n";
  for (auto x : v) printf("%d %d\n", x.first+1, x.second+1);
  
    return 0;
}



Measured memory_bytes: 256