akhauriyash/Code-Regression huggingface dataset:
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int comp(int x, int y, int i, int j){
	if(x==i) return (y<j)-(y>j); else return (x<i)-(x>i);
}

int n;
int a[300000][2];
bool bs(int x, int y){
	int l=0, r=n-1;
	while(l<=r){
		int m=(l+r)/2;
		if(comp(x, y, a[m][0], a[m][1])>=0) r=m-1; else l=m+1;
	}
	return comp(x, y, a[l][0], a[l][1])==0;
}
int bx[300000][2], by[300000][2];
int cx[300000], cy[300000];
int main(void){
	int h=nextint();
	int w=nextint();
	n=nextint();
	for(int i=0; i<n; i++){
		int x=nextint()-1;
		int y=nextint()-1;
		a[i][0]=x; bx[x][1]++; cx[x]++;
		a[i][1]=y; by[y][1]++; cy[y]++;
	}
	for(int x=0; x<h; x++) bx[x][0]=x;
	for(int y=0; y<w; y++) by[y][0]=y;
	rsorta_d32(a, n, 2, 1);
	rsorta_d32(a, n, 2, 0);
	rsorta_d32(bx, h, 2, 1);
	rsorta_d32(by, w, 2, 1);
	int ans=0;
	int H=0, W=0;
	for(int i=h-1; i>=0; i--){
		if(bx[i][1]!=bx[h-1][1]) break;
		H++;
	}
	for(int j=w-1; j>=0; j--){
		if(by[j][1]!=by[w-1][1]) break;
		W++;
	}
	if(H*W>n){
		int x=bx[h-1][0], y=by[w-1][0];
		int ans=cx[x]+cy[y];
		printf("%d\n", ans);
	}else{
		for(int i=h-1; i>=0; i--){
			if(bx[i][1]!=bx[h-1][1]) break;
			for(int j=w-1; j>=0; j--){
				if(by[j][1]!=by[w-1][1]) break;
				int x=bx[i][0], y=by[j][0];
				int now=cx[x]+cy[y];
				if(bs(x, y)){
					now--;
					if(now>ans) ans=now;
				}else{
					if(now>ans) ans=now;
					break;
				}
			}
		}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 14460
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;

vector<int> adj[210];
int match[210];
bool used[210];

bool dfs(int v)
{
	used[v] = true;

	for (int i = 0; i < adj[v].size(); i++)
	{
		int u = adj[v][i], w = match[u];

		
		if (w < 0 || (!used[w] && dfs(w)))
		{
			match[v] = u;
			match[u] = v;
			return true;
		}
		
	}
	return false;
}

int main()
{
	int n, a[110], b[110], c[110], d[110];

	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i];
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> c[i] >> d[i];
	}

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (a[i] < c[j] && b[i] < d[j])
			{
				adj[i].push_back(j + n);
				adj[j + n].push_back(i);
			}
		}
	}

	int res = 0;

	memset(match, -1, sizeof(match));

	for (int i = 1; i <= n; i++)
	{
		if (match[i] < 0)
		{
			memset(used, 0, sizeof(used));

			if (dfs(i))
			{
				res++;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	int n,x,t;
	cin>>n>>x>>t;
	if(n%x==0)cout<<n/x*t;
	else cout<<(n/x+1)*t;
	return;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    string input;
    cin >> input;
    string str;
    vector<int> x_num(0);

    int tmp=0;
    for(int i=0; i<input.size(); i++){
        if(input[i]=='x'){
            tmp++;
        }else{
            str.push_back(input[i]);
            x_num.push_back(tmp);
            tmp=0;
        }
    }
    x_num.push_back(tmp);

    int ans = 0;
    int num=str.size();
    for(int i=0; i<num/2; i++){
        if(str[i]!=str[num-1-i]){
            ans=-1;
            break;
        }
    }

    if(ans!=-1){
        num=x_num.size();
        for(int i=0; i<num/2; i++){
            ans+=abs(x_num[i]-x_num[num-1-i]);
        }
    }
    cout << ans << endl;

}

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

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int max = 0;
    int count = 0;
    int before = 0;
    int current = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> current;
        if (before < current)
        {
            if (count > max) max = count;
            count = 0;
        }
        else
        {
            count++;
        }
        before = current;
    }
    if (count > max) max = count;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
dp = [p[i] - (i+1) for i in range(n)]
#print(dp)
cnt = 0
for i in range(n-1):
    if dp[i] != 0:
        continue
    dp[i+1], dp[i] = dp[i]-1, dp[i+1]+1
    cnt += 1
if dp[n-1] == 0:
    for i in reversed(range(1,n)):
        if dp[i] != 0:
            continue
        dp[i], dp[i-1] = dp[i-1]-1, dp[i]+1 
        cnt += 1
print(cnt)
#print(dp)

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

using namespace std;

#define DEBUG

template <typename T1, typename T2>
inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
{
    return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::vector<T>& v)
{
    bool first = true;
    os << "[";
    for(unsigned int i = 0; i < v.size(); i++)
    {
        if(!first)
            os << ", ";
        os << v[i];
        first = false;
    }
    return os << "]";
}

template<typename T>
inline std::ostream &operator << (std::ostream & os, const std::set<T>& v)
{
    bool first = true;
    os << "[";
    for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
    {
        if(!first)
            os << ", ";
        os << *ii;
        first = false;
    }
    return os << "]";
}

template<typename T1, typename T2>
inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v)
{
    bool first = true;
    os << "[";
    for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
    {
        if(!first)
            os << ", ";
        os << *ii ;
        first = false;
    }
    return os << "]";
}

struct debugger
{
	bool first;

	debugger() {
		first = true;
	}

    template<typename T> debugger& operator , (const T& v)
    {
    	if (!first) cout << ", ";
        cout << v;
        first = false;
        return *this;    
    }
};

// Debug macro that prints out "expression: value" for clarity
#ifdef DEBUG
    #define debug(args...)          { cout << #args << ": "; (debugger()), args; cout << endl; }
#else
    #define debug(args...)
#endif

#define int long long

// Union-Find Disjoint-Sets data structure with path compresion and efficient union
// class UnionFind {
//     private:
//         vector<int> p, rank;
//     UnionFind(int n) {
//         rank.assign(n, 0);
//         for (int i = 0; i < n; i++) {
//             p[i] = i;
//         }
//     }
//     int findSet(int i) {
//         return (p[i] == i) : i ? (p[i] = findSet(i));
//     }
//     int unionSet(int i, int j) {
//         int x = findSet(i), y = findSet(j);
//         if (x != y) {
//             if (rank[x] < rank[y]) p[x] = y;
//             else {
//                 p[y] = x;
//                 if (rank[x] == rank[y]) rank[y]++;
//             }
//         }
//     }
// }

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    //final List<Long> list = new ArrayList<>();

    String s = sc.next();
    int count = 0;

    for(int i = 0; i < 4 ; i++){
        for(int j = i + 1; j < 4 ; j++){
            if(s.charAt(i) == s.charAt(j)){
                count++;
            }
        }
    }

    if(count == 2){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }

    
    






    

    



    
  

    


    


    

    
    
    



    





}
}

Measured memory_bytes: 35956
class UnionFind:
    def __init__(self, size):
        self.parent = [-1 for i in range(size)]#非負なら親ノード，負ならグループの要素数

    def root(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x]) #xをxの根に直接つなぐ
            return self.parent[x]

    def union(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False

        if self.parent[x] < self.parent[y]: #xの要素数がyの要素数より「小さい」とき
            x,y=y,x
        self.parent[x] += self.parent[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True

    def same(self, x, y):
        return self.root(x) == self.root(y)



n,m = list(map(int,input().split()))
p = list(map(lambda x: int(x)-1,input().split()))

uf = UnionFind(n)
for i in range(m):
    x,y=list(map(int,input().split()))
    uf.union(x-1,y-1)

ans = 0
for i in range(n):
    if uf.same(i,p[i]):
        ans += 1

print(ans)

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

const int N = 1000005;

int n;
char s[N];

tuple<int, int, int> brackets[N];

int main() {
  scanf("%d", &n);

  int sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    int len = strlen(s);

    int mini = 0, maxi = 0, cur = 0;
    for (int j = 0; j < len; ++j) {
      if (s[j] == '(') ++cur;
      else if (s[j] == ')') --cur;

      mini = min(mini, cur);
      maxi = max(maxi, cur);
    }

    brackets[i] = make_tuple(-mini, cur, maxi);
    sum += cur;
  }

  if (sum != 0) return 0 * printf("No\n");

  sort(brackets, brackets + n);

  int cur = 0;
  for (int i = 0; i < n; ++i) {
    int delta, mini, maxi;
    tie(mini, delta, maxi) = brackets[i];

    if (delta < 0) continue;
    if (mini > cur) return 0 * printf("No\n");
    cur += delta;
  }

  sort(brackets, brackets + n, [](tuple<int, int, int> p, tuple<int, int, int> q) {
    int a, b, c;
    int d, e, f;
    tie(a, b, c) = p;
    tie(d, e, f) = q;
    return a + b < d + e;
  });
  reverse(brackets, brackets + n);

  for (int i = 0; i < n; ++i) {
    int delta, mini, maxi;
    tie(mini, delta, maxi) = brackets[i];

    if (delta >= 0) continue;
    if (mini > cur) return 0 * printf("No\n");
    cur += delta;
  }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 15380
#include<iostream>
using namespace std;
#include<cstdlib>
#include<string>
#include<sstream>

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

int main()
{
    string s[101];
    int top = 0;
    int a, b;
    while(cin >> s[top]){
        if(s[top] == "EOF") break;
        if(s[top][0] >= '0'){
            top++;
            continue;
        }else{
            a = atoi(s[top - 2].c_str());
            b = atoi(s[top - 1].c_str());
            if(s[top] == "+") s[top - 2] = IntToString(a + b);
            if(s[top] == "*") s[top - 2] = IntToString(a * b);
            if(s[top] == "-") s[top - 2] = IntToString(a - b);
            top--;
        }
    };

    cout << s[top - 1] << endl;

    return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		
		if(Character.isUpperCase(A.charAt(0))){
			System.out.println("A");
		}
		else {
			System.out.println("a");
		}

	}
}


Measured memory_bytes: 26908
#include<bits/stdc++.h>
using namespace std;
using pr=pair<int,int>;
struct edge{int to,cost;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	edge init({(int)2e9,(int)2e9});
	vector<edge>mn(n+1,init); mn.at(1).to=-1,mn.at(1).cost=0;
	vector<vector<int>>g(n+1);
	for(int i=0;i<m;++i){
		int a,b; cin>>a>>b;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	priority_queue<pr,vector<pr>,greater<pr>>q;
	q.push({0,1});
	while(q.size()){
		pr tmp=q.top(); q.pop();
		int nw=tmp.second,spend=tmp.first;
		if(spend>mn.at(nw).cost)continue;
		for(auto&&i:g.at(nw)){
			if(spend+1<mn.at(i).cost){
				edge t({nw,spend+1});
				mn.at(i)=t;
				q.push({spend+1,i});
			}
		}
	}
	cout<<"Yes\n"s;
	for(int i=2;i<=n;++i)cout<<mn.at(i).to<<"\n"s;
}

Measured memory_bytes: 11184
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

int main(int argc, char* argv[]){
	int A, B, C, K;

	scanf("%d %d %d %d", &A, &B, &C, &K);

	int y;
	if(A >= K){
		y = K;
	}else if(A+B >= K){
		y = A;
	}else if(A+B+C >= K){
		y = A - (K-A-B);
	}else {
		y = A-C;
	}
	printf("%d\n", y);

	return 0;
}





Measured memory_bytes: 3864
a=-1,A=65,d;char*N="GKSOCNWLDFVTBRXHAJUPEMQI",*E="PHLTIDOXQAGWECSUMBKVJFNR",*R="BCDAFGHEJKLINOPMRSTQVWXU",s[9];main(c){for(;c-48&&scanf("%s",s);a+=d/4+1)(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0,d=(c==78?d=N[d]:c==69?d=E[d]:c==82?d=R[d]:c==83?d=N[N[N[d]-A]-A]:c==87?d=E[E[E[d]-A]-A]:d+A)-A,d=c==76?d=R[R[R[d]-A]-A]-A:d;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int H[N];
    REP(i, N){
        cin >> H[i];
    }

    int ans = 1, res = 0;
    REP(i, N-1){
        res = max(res, H[i]);

        if(H[i+1] >= res){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int n, m, d[100005], f = 1;
vector<pair<int, int>> e[100005] = {};

void dfs(int v) {
	for (int i = 0; i < e[v].size(); i++) {
		int a, b;
		a = e[v][i].first;
		b = e[v][i].second;
		if (d[a] == INF) {
			d[a] = d[v] + b;
			dfs(a);
		}
		else {
			if (d[a] - d[v] != b) {
				f = 0;
			}
		}
	}
}

int main()
{
	for (int i = 0; i < 100000; i++) {
		d[i] = INF;
	}
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--; r--;
		e[l].push_back({ r, k });
		e[r].push_back({ l, -k });
	}

	for (int i = 0; i < n; i++) {
		if (d[i] == INF && !e[i].empty()) {
			d[i] = 0;
			dfs(i);
		}
	}

	if (f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 12032
#include<stdio.h>
int main()
{
	int q,w;
	while(scanf("%d %d",&q,&w)!=EOF)
	{
		int sum=q*w;
		int num=(q+w)*2;
		printf("%d %d\n",sum,num); 
	}
	
	
	
	
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq;
    int n;
    string str;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin>>str;
        for (int j=0;j<str.size();j++) {
            int hoge = str.at(j)-48;
            deq.emplace_back(hoge);
        }
        sort(deq.begin(),deq.end());
        int min = 10000000*deq[0]+1000000*deq[1]+100000*deq[2]+10000*deq[3]+1000*deq[4]+100*deq[5]+10*deq[6]+1*deq[7];
        sort(deq.begin(),deq.end(),greater<int>());
        int max = 10000000*deq[0]+1000000*deq[1]+100000*deq[2]+10000*deq[3]+1000*deq[4]+100*deq[5]+10*deq[6]+1*deq[7];
        cout<<max-min<<endl;
        deq.clear();
    }
}



Measured memory_bytes: 3176
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n;
int p[100000];
int pos[100001];


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

	cin >> n;
	rep(i, n)cin >> p[i];
	rep(i, n)pos[p[i]] = i;

	set<int> idxs;

	long long ans = 0;
	for (int i = n; i >= 1; i--) {
		int idx = pos[i];
		int a = -1, b = -1, c = n, d = n;

		auto it = idxs.upper_bound(idx);
		if (it != idxs.end()) {
			c = *it;
			auto it2 = it;
			++it2;
			if (it2 != idxs.end()) {
				d = *it2;
			}
		}
		if (it != idxs.begin()) {
			--it;
			b = *it;
			if (it != idxs.begin()) {
				--it;
				a = *it;
			}
		}
		if (b != -1) {
			ans += (long long)(b - a) * (c - 1 - idx + 1) * i;
		}
		if (c != n) {
			ans += (long long)(idx - (b + 1) + 1) * (d - c) * i;
		}

		idxs.insert(idx);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 5760
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a;
    cin >> a;
    if(a%2 == 0){
        cout << a;
    }
    else
    {
        cout << a*2;
    }
    
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t[110000][2];
priority_queue<P> q1;

int main(){
	int n,m;
	int i,j,k;
	LL a,b,c;
	LL s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t[i][0]>>t[i][1];
		q1.push(make_pair(t[i][0]+t[i][1],i));
	}
	for(i=0;i<n;i++){
		a=q1.top().second,q1.pop();
		if(i%2==0)s+=t[a][0];
		else s-=t[a][1];
	}
	cout<<s<<endl;
}

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

import sys

for line in sys.stdin:
    a, b, c, d, e, f = map(float, line.split())
    print "%.3f %.3f" %(round(b*f-c*e)/(b*d-a*e)+0, (c*d-a*f)/(b*d-a*e)+0)

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


int main(){
	int n,q; cin >> n >> q;
	dsu d(n);
	
	while(q--) {
		int t, u, v; cin >> t >> u >> v;
		if(t == 0) {
			d.merge(u, v);
		}else {
			if(d.same(u, v)) {
				cout << "1\n";
			}else cout << "0\n";
		}
	}



	
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0 ; i<n ; i++){cin>>v[i];}
    int l=0 , r=0 , sum=0;
    for(int i=0 ; i<n-1 ; i++)
    {
        if( v[i] >= v[i+1] )
        {
            r++;
        }
        else
        {

            sum=max( sum , r-l );
            l=i+1;
            r=i+1;
        }
    }
    cout<<max(sum , r-l)<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int n,m;
int pw[16];

const int N=14350000;
const int INF=12345679;

int dp[N];

int main()
{
    pw[0]=1;
    for(int i=1; i<16; ++i) pw[i] = pw[i-1]*3;

    while(scanf(" %d %d", &n, &m),n)
    {
        int start = 0;
        rep(i,3)
        {
            int a;
            scanf(" %d", &a);
            while(a--)
            {
                int c;
                scanf(" %d", &c);
                --c;
                start += i*pw[c];
            }
        }

        fill(dp,dp+N,INF);
        dp[start]=0;
        queue<int> que;
        que.push(start);
        while(!que.empty())
        {
            int s = que.front();
            que.pop();

            int pos[15];
            vector<int> big(3,-1);
            int t=s;
            rep(i,n)
            {
                pos[i]=t%3;
                t/=3;

                big[pos[i]]=i;
            }

            int ns;
            if(big[0]>=0)
            {
                // 0->1
                if(big[0]>big[1])
                {
                    ns = s+pw[big[0]];
                    if(dp[ns]>dp[s]+1)
                    {
                        dp[ns] = dp[s]+1;
                        que.push(ns);
                    }
                }
            }

            if(big[1]>=0)
            {
                // 1->0
                if(big[1]>big[0])
                {
                    ns = s-pw[big[1]];
                    if(dp[ns]>dp[s]+1)
                    {
                        dp[ns] = dp[s]+1;
                        que.push(ns);
                    }
                }

                // 1->2
                if(big[1]>big[2])
                {
                    ns = s+pw[big[1]];
                    if(dp[ns]>dp[s]+1)
                    {
                        dp[ns] = dp[s]+1;
                        que.push(ns);
                    }
                }

            }

            if(big[2]>=0)
            {
                // 2->1
                if(big[2]>big[1])
                {
                    ns = s-pw[big[2]];
                    if(dp[ns]>dp[s]+1)
                    {
                        dp[ns]=dp[s]+1;
                        que.push(ns);
                    }
                }
            }
        }

        int ans = min(dp[0],dp[pw[n]-1]);
        if(ans > m) ans=-1;
        printf("%d\n", ans);
    }

    return 0;
}

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

const int nm = 5000;
int n, k, p[nm], c[nm], step[nm];
ll ans = -1e9;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> p[i];
		--p[i];
	}
	for (int i = 0; i < n; ++i)
		cin >> c[i];

	//
	for (int x = 0; x < n; ++x) {
		ll m = -1e9, temp = 0;

		fill(step, step + n, -1);
		int y = x, t = 0, r;
		step[y] = 0;
		for (int i = 1; i <= k; ++i) {
			y = p[y];
			temp += c[y];
			if (step[y] < 0) {
				step[y] = i;
				m = max(m, temp);
			} else {
				t = i - step[y];
				r = k - i;
				break;
			}
		}

		if (t) {
			ll loop = 0;
			for (int i = 0; i < t; ++i) {
				loop += c[y];
				y = p[y];
			}
			if (loop > 0) {
				int times = max((r - t) / t, 0);
				temp += loop * times;
				r -= t * times;
				m = max(m, temp);
				for (int i = 0; i < r; ++i) {
					y = p[y];
					temp += c[y];
					m = max(m, temp);
				}
			}
		}

		ans = max(ans, m);

	}

	cout << ans << endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int N;
	string S;
	cin >> N;
	cin >> S;
	string ans;
	int d = 0;
	if (N % 2 == 1) ans = "No";
	else {
		for (int i = 0; i < N / 2; i++) {
			if (S[i] == S[i + (N / 2)])d++;
		}
		if (d == N / 2)ans = "Yes";
		else ans = "No";
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
	long long cnt = 0, a[100001], n,x;
	cin >> n >> x;
	for (int i = 0; i <= n; ++i) {
		if (i != n) {
			cin >> a[i];
		}
		else {
			a[i] = 0;
		}

	}
	for (int i = 1; i <= n; ++i) {
		if (a[i] + a[i - 1] > x) {
			int tmp = a[i] + a[i - 1] - x;
			a[i] = a[i] - tmp;
			cnt += tmp;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N, T, A;

int main() {
  cin >> N >> T >> A;
  int H[N];
  double tmp = 1e9;
  int ans;
  for (int i = 0; i < N; ++i) cin >> H[i];

  for (int i = 0; i < N; ++i) {
    if (tmp > abs(A - (T - (H[i] * 0.006)))) {
      tmp = abs(A - (T - (H[i] * 0.006)));
      ans = i + 1;
    }
  }

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#include <ctime>
#include <set>
#define endl '\n'
#define ll unsigned long long
#define mod 1000000007
#define NCONS 100001
#define MACRO(a) for(int a = 1; a < 1001; a++)

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> vec;
	for (ll i = 1; i * i <= N; i++)
	{
		if (i * i == N)
		{
			vec.push_back(i);
			vec.push_back(i);
		}
		else if (N % i == 0)
		{
			vec.push_back(i);
			vec.push_back(N / i);
		}
	}
	sort(vec.begin(), vec.end());
	if (vec.size() == 1)
	{
		cout << 1;
	}
	else
	{
		ll A = vec[vec.size() / 2];
		ll B = vec[vec.size() / 2 - 1];
		ll C = max(A, B);
		cout << to_string(C).length() << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
    
    double n,k;
    cin>>n>>k;
    double p=0;
    for(int i=1;i<=n;i++)
    {
        ll r=i;
        ll c=0;
        double te=1.0;
        while(r<k)
        {
            r=r*2;
            c++;
            te=te*0.5;
        }
        p+=te;
    }
    double s=(double)(1/(double)(n*1.0));
    printf("%.12f",(double)s*p);
    
}
    
    
    







Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int[] dp;
        static int[] H;
        static void Main(string[] args)
        {
            var NK = Slist();
            var N = NK[0];
            var K = NK[1];
            H = Sarray();

            dp = new int[N + K + 1].Select(_ => int.MaxValue).ToArray();
            dp[0] = 0;
            for (var i = 0; i < N; ++i)
                for (var k = 1; k <= K; ++k)
                    if (0 <= i - k)
                        dp[i] = Min(dp[i], dp[i - k] + Abs(H[i] - H[i - k]));
            WriteLine(dp[N - 1]);
        }
    }
}


Measured memory_bytes: 21600
N=int(input())
import math
ans=(N+1)*N//2
for i in range(N-1):
  for j in range(i+1,N):
    ans+=math.gcd(i+1,j+1)*6
    
for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      ans+=math.gcd(math.gcd(i+1,j+1),k+1)*6
print(ans)

Measured memory_bytes: 67672
# https://atcoder.jp/contests/aising2020/tasks/aising2020_d

def goes_to_zero(n):
    cnt = 0
    while(n > 0):
        n %= bin(n).count('1')
        cnt += 1
    return cnt

N = int(input())
X = input()
XC = X.count('1')
XI = int(X, 2)
XCP = XC + 1
XCM = XC - 1
XTP = XI % XCP
XTM = XI % XCM if XCM != 0 else 0
for i in range(N):
    if X[i] == "0":
        print(goes_to_zero((XTP + pow(2, N - 1 - i, XCP)) % XCP) + 1)
    else:
        if XCM == 0:
            print(0)
        else:
            print(goes_to_zero((XTM - pow(2,N - 1 - i, XCM)) % XCM) + 1)

Measured memory_bytes: 9552
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100;
bool vst[maxn][maxn]; // 访问标记
int dir[4][2]={0,1,0,-1,1,0,-1,0}; // 方向向量
int h,w;
int ans=0;
struct State // BFS 队列中的状态数据结构
{
int x,y; // 坐标位置
int Step_Counter; // 搜索步数统计器
};
State a[maxn];
char b[maxn][maxn];
bool CheckState(State s) // 约束条件检验
{
if(!vst[s.x][s.y] &&b[s.x][s.y]=='.') // 满足条件
return 1;
else // 约束条件冲突
return 0;
}

void bfs(State st)
{
queue <State> q; // BFS 队列
State now,next; // 定义2 个状态，当前和下一个
st.Step_Counter=0; // 计数器清零
q.push(st); // 入队
vst[st.x][st.y]=1; // 访问标记
while(!q.empty())
{
now=q.front(); // 取队首元素进行扩展
if(now.x==h&&now.y==w) // 出现目标态，此时为Step_Counter 的最小值，可以退出即可
{
	printf("%d\n",h*w-ans-1-now.Step_Counter);
 // 做相关处理
return;
}
for(int i=0;i<4;i++)
{
next.x=now.x+dir[i][0]; // 按照规则生成下一个状态
next.y=now.y+dir[i][1];
next.Step_Counter=now.Step_Counter+1; // 计数器加1
if(CheckState(next)) // 如果状态满足约束条件则入队
{
q.push(next);
vst[next.x][next.y]=1; //访问标记
}
}
q.pop(); // 队首元素出队
}
printf("-1");
 return;
}

int main(){
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			scanf(" %c",&b[i][j]);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(b[i][j]=='#')ans++;
	State anm;
	anm.x=1;anm.y=1;
	bfs(anm);
return 0;
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 2000200;

int n, q; 
vector<int> d[MAX_N];
bool finish[MAX_N];
int cnt[MAX_N];

void init(){
    rep(i,MAX_N){
        finish[i] = false;
        cnt[i] = 0;
    }
}

void dfs(int u){
    finish[u] = true;
    for(int v: d[u]){
        if(!finish[v]){
            // cout << v << endl;
            cnt[v] += cnt[u];
            dfs(v);
        }
    }
    // cout << u << endl;
}

int main()
{
    cin >> n >> q;
    rep(i,n-1){
        int ai, bi; cin >> ai >> bi;
        --ai, --bi;
        d[ai].push_back(bi);
        d[bi].push_back(ai);
    }

    init();

    rep(i,n){
        cnt[i] = 0;
    }
    rep(i,q){
        int pi, xi; cin >> pi >> xi;
        --pi;
        cnt[pi] += xi;
    }

    dfs(0);

    rep(i,n){
        cout << cnt[i];
        if(i != n-1) cout << " ";
    }cout << endl;
}

Measured memory_bytes: 75876
#include <iostream>
#include <cmath>
#include <vector>
#define fri(l,k) for (int i=l;i<=k;i++)
using namespace std;

signed main()
{
  int N;
  cin >> N;
  std::vector<int> H(N);
  fri(0, N-1) cin >> H[i];

  int max = 0;
  fri(0, N-1) {
	  if(max < H[i]) max = H[i];
	  if((max - H[i]) >= 2) {
		  cout << "No";
		  return 0;
	  }
  }

  cout << "Yes";
  return 0;

}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

char x[10];
int main()
{
	long long int a;
	scanf("%lld",&a);
	scanf("%s",x+1);
	int b = strlen(x+1);
	
	long long int c = a*(x[1]-'0');
	long long int d = a*(10*(x[3]-'0')+(x[4]-'0'));
	
	printf("%lld",c+(d/100));
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int prime[50000]; //i盤目の素数
bool is_prime[50001]; //is_prime[i]がtrueならiは素数

void sieve(int n){ //n以下の素数を返す
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
}

int main(){
	int n;
	sieve(50000);
	while(1){
		cin>>n;
		if(n==0) break;
		if(n%2){
			o((is_prime[n-2]?1:0)); continue;
		}
		int ans=0;
		rep(i,2,n/2+1){
			if(is_prime[i] && is_prime[n-i]) ans++;
		}
		o(ans);
	}
}

Measured memory_bytes: 1228
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
LL a[100010];

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

    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }

    LL s = 0;
    LL prev = 0;

    for (int j = 0; j < N; ++j) {
        LL x = a[j];

        s += min(prev, x);
        x -= min(prev, x);

        s += x / 2;
        prev = x % 2;
    }

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.stream.LongStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.OptionalLong;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DEqualCut solver = new DEqualCut();
        solver.solve(1, in, out);
        out.close();
    }

    static class DEqualCut {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            int[] a = in.ints(n);
            long p = a[0], q = a[1], r = a[2], s = Arrays.stream(a).skip(3).mapToLong(i -> i).sum();
            int ab = 1, bc = 2, cd = 3;
            long ans = Long.MAX_VALUE;
            do {
                while (bc - ab > 1 && Math.abs(p - q) >= Math.abs(p - q + 2 * a[ab])) {
                    p += a[ab];
                    q -= a[ab];
                    ab++;
                }
                while (n - cd > 1 && Math.abs(r - s) >= Math.abs(r - s + 2 * a[cd])) {
                    r += a[cd];
                    s -= a[cd];
                    cd++;
                }
                ans = Math.min(ans, IntMath.max(p, q, r, s) - IntMath.min(p, q, r, s));

                q += a[bc];
                r -= a[bc];
                bc++;
            } while (bc < n - 1);
            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }

    static final class IntMath {
        private IntMath() {
        }

        public static long min(long... v) {
            return Arrays.stream(v).min().orElseThrow(() -> new IllegalArgumentException("Empty argument"));
        }

        public static long max(long... v) {
            return Arrays.stream(v).max().orElseThrow(() -> new IllegalArgumentException("Empty argument"));
        }

    }
}



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

int main() {
    int n,w;
    while (true){
        cin>>n>>w;
        if(n==0)break;
        vector<double> v(n);
        double mv=0;

        for (int i = 0; i < n; ++i) {
            cin>>v[i];
            mv=max(mv,v[i]);
        }
        int gw= ceil((mv+1) / double(w))-1;
        double ans=0;
        vector<int> a(20,0);
        for(auto i:v){
            a[floor(i/w)]++;
            ans+=(gw-floor(i/w))/gw;
        }
        int t=0;
        for(auto i:a)t=max(t,i);
        ans=ans/t;
        ans+=0.01;
        cout<<fixed<<setprecision(12);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  ll n,k,cnt=0;
  cin>>n>>k;
  while(n>0){
    cnt++;
    n/=k;
  }
  cout<<cnt;
  
  return 0;
}


Measured memory_bytes: 256
// AOJ ALDS1_14_D Multiple String Matching
// 2018.5.13 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_L 1000005

char text[MAX_L]; int len;
char pattern[10005]; int plen;
int  sa[MAX_L], rank[MAX_L];

// rank[i]～[i+k] と rank[j]～[j+k] を比較
int k; // comstruct_sa()内で設定
int compare_sa(int i, int j)
{
	int ri, rj;
	
	if (rank[i] != rank[j]) return rank[i] < rank[j];
	ri = -1; if (i+k <= len) ri = rank[i+k];
	rj = -1; if (j+k <= len) rj = rank[j+k];
    return ri < rj;
}

// for qsort()
int cmp(int *a, int *b)
{
	int i = *a, j = *b;
	int ri, rj;
	
	if (rank[i] != rank[j]) return rank[i]-rank[j];
	ri = -1; if (i+k <= len) ri = rank[i+k];
	rj = -1; if (j+k <= len) rj = rank[j+k];
    return ri-rj;
}

// 文字列Sの接尾辞配列saを構築。   len:　strlen(s)
int tmp[MAX_L];
void construct_sa(char *s, int *sa)
{
	int i;
	
	for(i = 0; i <= len; i++) {
		sa[i] = i;
		rank[i] = -1; if (i < len) rank[i] = s[i];
	}
	
	for(k = 1; k <= len; k *= 2) {
		qsort(sa, len+1, sizeof(int), cmp);
		
		tmp[sa[0]] = 0;
		for(i = 1; i <= len; i++) {
			tmp[sa[i]] = tmp[sa[i-1]]+(compare_sa(sa[i-1], sa[i])? 1: 0);
		}
		for(i = 0; i <= len; i++) rank[i] = tmp[i];
	}
}

// 接尾辞配列を用いた文字列検索　len = strlen(s), plen = strlen(t)
int contain(char *s, char *t)
{
	int l, r, m;

	l = 0, r = len;
	while (l+1 < r) {
		m = (l+r)>>1;
		if (memcmp(s+sa[m], t, plen) < 0) l = m; else r = m;
	}
	return !memcmp(s+sa[r], t, plen);
}

int main()
{
	int Q;
	char c, *p;

	p = text;
	while ((c = gc()) > ' ') *p++ = c;
	*p = 0;
	len = p-text;

	construct_sa(text, sa);

//for (int i = 0; i <= len; i++) printf("[%d] sa %d\n", i, sa[i]);

	Q = in();
	while (Q--) {
		p = pattern;
		while ((c = gc()) > ' ') *p++ = c;
		*p = 0;
		plen = p-pattern;

		pc('0' + contain(text, pattern));
		pc('\n');
	}
	return 0;
}


Measured memory_bytes: 17420
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] a = new int[3];
        int five = 0;
        int seven = 0;

        for(int i = 0; i < a.length; i++){
            // System.out.println(i + "文字目を入力してください");
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < a.length; i++){
            if(a[i] == 5){
                five++;
            } else if(a[i] == 7){
                seven++;
            }
        }
        if(five == 2 && seven == 1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}

Measured memory_bytes: 21972
// #include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
typedef long long ll;
using namespace std;
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000

// ------------------ ベクター表示 ------------------ //
void printVec(vector<ll>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// ------------------ int -> Vector 変換 ------------------ //
vector<int> ItoVec(int x) {

	vector<int> xVec;

	while (x > 0) {
		int tmp = x % 10;
		xVec.insert(xVec.begin(), tmp);
		x /= 10;
	}

	return xVec;
}

// ------------------ 最大公約数関数 ------------------ //
int GCD(int x, int y) {
	if (x == 0) return y;
	else GCD(y % x, x);
}


// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll ans = 0;

	if (K > 0 && A != 0) {
		ans += (K > A ? A : K);
		K = K - A;
	}
	if (K > 0 && B != 0) {
		K = K - B;
	}
	if (K > 0 && C != 0) {
		ans = ans + K * (-1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#define c b-a
using namespace std;
int n,a,b;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(c&1) printf("Borys");
	else printf("Alice");
	printf("\n");
	return 0;
}

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

class BaseXor:
    def __init__(self):
        self.size = 0
        self.base = []
    
    def base_calculate(self, x, b):
        return min(x, x ^ b)

    def make_base(self, x):
        for b in self.base:
            x = self.base_calculate(x, b)
        return x
    
    def change_base(self, x):
        for i in range(self.size):
            self.base[i] = self.base_calculate(self.base[i], x)
    
    def judge_linearly_dependent(self, x, value=False):
        x = self.make_base(x)
        res = True if x else False
        res = (res, x) if value else res
        return res
    
    def add_base(self, x):
        judge, x = self.judge_linearly_dependent(x, value=True)
        if judge:
            self.change_base(x)
            self.base.append(x)
            self.size += 1
            return True
        return False

def solve(n, a, s):
    base = BaseXor()
    judge = False
    for i in range(n-1, -1, -1):
        x = s[i]
        if x == "0":
            base.add_base(a[i])
        else:
            judge = base.judge_linearly_dependent(a[i])
            if judge:
                break
    
    res = 1 if judge else 0
    return res

def main():
    t = int(input())
    ans = [0]*t
    for i in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        s = input()
        res = solve(n, a, s)
        ans[i] = res
    print(*ans, sep="\n")
    
if __name__ == "__main__":
    main()



Measured memory_bytes: 9028
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, M, d, i{}, j{}; cin >> N >> M;
  int A[N], B[N], C[M], D[M]; for (; i < N; ++i) cin >> A[i] >> B[i]; while (cin >> C[j] >> D[j]) ++j;
  for (i = 0; i < N; ++i)
    {int m(1e9), k{}; for (j = 0; j < M; ++j) if ((d = abs(A[i] - C[j]) + abs(B[i] - D[j])) < m) m = d, k = j;
    cout << ++k << "\n";}}

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

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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;
}

const long long INF = 1LL << 60;

const double PI = acos(-1.0);

// long long積のオーバーフロー検出
bool detect_mul_overflow(ll a, ll b)
{
    return a >= LONG_MAX / b;
}

int lcm(int a, int b)
{
    //最小公倍数
    return a / __gcd(a, b) * b;
}

struct edge
{
    int from, to, cost;
};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));
ll n,d;


int main()
{
    cin>>n>>d;
    // vec<ll> X(n,0),Y(n,0);
    ll x=0,y=0,cnt=0;
    rep(i,n){
        cin>>x>>y;
        if(x*x+y*y<=d*d){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3628
import math

def nCm(n, m):
    return math.factorial(n) // (math.factorial(m) * (math.factorial(n - m)))

N, K = [int(i) for i in input().split()]
MOD = 10**9+7

for i in range(1, K+1):
	if N-K+1 >= i and K-1 >= i-1:
		print(int(nCm(N-K+1, i)*nCm(K-1, i-1)%MOD))
	else: 
		print(0)


Measured memory_bytes: 3316