akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N,M;
    cin >> N >> M;
    long long S = 0;
    if(N*2 <= M){
        long long L = M - N*2;
        S += N + L / 4;
    }
    else{
        S += M / 2;
    }
    cout << S << endl;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(n: usize);
	input!(a: [i64; n]);


	let mut a = a;
	a.sort();
	let min = a[0];
	let max = a[n-1];

	let mut ans: i64 = 9999999999999;
	for i in min..max+1 {
		let mut cost: i64 = 0;
		for j in 0..n {
			cost += (a[j] - i) * (a[j] - i);
		}
		if cost < ans {
			ans = cost;
		} 
	}
	println!("{}", ans);
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define mp make_pair
#define se second
const int N=305,M=1e9+7;
vector<pair<int,int> > v[N];
int x,y,z,n,m,dp[N][N][N];
int check(int x,int y,int z){
	if (x&&y&&x==y)return 0;
	if (x&&z&&x==z)return 0;
	if (y&&z&&y==z)return 0;
	int t=max(x,max(y,z));
	for (int i=0;i<(int)v[t].size();i++){
		int cnt=0;
		cnt+=x>=v[t][i].fi;
		cnt+=y>=v[t][i].fi;
		cnt+=z>=v[t][i].fi;
		if (cnt!=v[t][i].se)return 0;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		v[y].push_back(mp(x,z));
	}
	dp[0][0][0]=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			for (int k=0;k<n;k++)
				if (check(i,j,k)){
					int t=max(i,max(j,k))+1;
					(dp[t][j][k]+=dp[i][j][k])%=M;
					(dp[i][t][k]+=dp[i][j][k])%=M;
					(dp[i][j][t]+=dp[i][j][k])%=M;
				}
	int ans=0;
	for (int i=0;i<=n;i++)
		for (int j=0;j<=n;j++)
			for (int k=0;k<=n;k++)
				if (check(i,j,k)&&max(i,max(j,k))==n)(ans+=dp[i][j][k])%=M;
	printf("%d\n",ans);
}


Measured memory_bytes: 110848
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, m, k) = InputLine.to_ia
  a = InputLine.to_ia
  b = InputLine.to_ia

  s = [0] * (n + 1)
  n.times{|i| s[i + 1] = a[i] + s[i]}
  t = [0] * (m + 1)
  m.times{|j| t[j + 1] = b[j] + t[j]}

  c = 0
  (n + 1).times do |i|
    break if s[i] > k
    j = t.bsearch_index{|x| x > k - s[i]}

    if j == nil then
      j = m
    elsif j == 0 then
      j = 0
    else
      j -= 1
    end

    c = [c, i + j].max
  end
  puts c.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 45928
#include<bits/stdc++.h>
using namespace std;
long long t[1005],a[1005],n,c,d;
int main(){
	cin>>n;
	cin>>t[1]>>a[1];
	for(int i=2;i<=n;i++)
	{
		cin>>t[i]>>a[i];
		 
		if((t[i]<t[i-1])&&(a[i]<a[i-1]))
		  c=(t[i-1]+t[i]-1)/t[i],
		 d=(a[i-1]+a[i]-1)/a[i], 
		 a[i]=max(c,d)*a[i], 
		 t[i]=max(c,d)*t[i];
		  else
		   if(t[i]<t[i-1])
		      c=(t[i-1]+t[i]-1)/t[i],t[i]=c*t[i], a[i]=c*a[i];
		    else
		    if(a[i]<a[i-1])
		       d=(a[i-1]+a[i]-1)/a[i], a[i]=d*a[i],t[i]=d*t[i]; 
	
		    
		 
	}
	cout<<a[n]+t[n];
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long int ll;
const int MAX = 1e5 + 10;
const ll MOD=1e9 + 7;




void rev(string &s){
	int n=s.length();
	for(int i=0,j=n-1;i<=j;i++,j--){
		swap(s[i],s[j]);
	}
}


ll mod9(ll x){
	x %= MOD;
	if(x < 0) x += MOD;
	return x;
}

ll mod13(ll x){
	x %= 13;
	if(x < 0) x += 13;
	return x;
}


ll pow(ll x,ll n){
	if(n==0) return 1;
	ll t = pow(x,n/2);
	t=mod13(t*t);
	if(n%2==1)t=mod13(t*x);
	return t;
}

int main()
{	
  	ios_base::sync_with_stdio(false); cin.tie(0);
	string s; cin>>s;
	int n=s.length();
	//rev(s);
	int dp[MAX][20]={0};

	if(s[0]=='?'){
		for(int i=0;i<10;i++) dp[0][i]=1;
	}
	else dp[0][s[0]-'0']=1;

	for(int i=1;i<n;i++){
		if(s[i]=='?'){
			for(int d=0;d<10;d++){
				for(int lr=0;lr<13;lr++){
					dp[i][mod13(lr*10 + d)] = mod9(dp[i][mod13(lr*10 + d)] + dp[i-1][lr]);
				}
			}
		}
		else{
			for(int lr=0;lr<13;lr++){
					dp[i][mod13(lr*10 + (s[i]-'0'))] = mod9(dp[i][mod13(lr*10 + (s[i]-'0'))] + dp[i-1][lr]);
				}
		}
	}

	cout<<dp[n-1][5];
}


Measured memory_bytes: 8272
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main()
{
    char a[10]={'\0'},b[10]={'\0'},c[10]={'\0'};
        int i,j;
        scanf("%s",&a);
        scanf("%s",&b);;
        int len=strlen(b);
        j=len;
        for (i=0;i<len;i++)
        {
            j--;
            c[i]=b[j];
        }
        if(strcmp(a,c)==0)
            printf("YES\n");
        else
            printf("NO\n");
  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))

R = min(N, K)
ans = 0
for a in range(R+1):
    for b in range(R-a+1):
        items = V[:a] + V[N-b:]
        items.sort()
        for c in range(K-a-b+1):
            ans = max(ans, sum(items[c:]))
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int N;
    cin>>N;
    vector<int> A(N);
    REP(i, N) cin>>A[i];
    vector<int> B = A;
    sort(ALL(B));
    bool res = true;
    int cnt= 0;
    for(int i=0; i<N; i++){
        if(A[i]!=B[i]) cnt++;
        if(cnt>2){
            res = false;
            break;
        }
    }
    if(!res) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int sz=s.size();
    int z=0,a=0;
    for(int i=0;i<sz;i++)
    {
        if(s[i]=='0')
            z++;
        if(s[i]=='1')
            a++;
    }
    cout<<(min(z,a))*2<<endl;
    return 0;
}


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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(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);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
    char s[10];
    int n;
    int a=0, w=0, t=0, r=0;


  scanf("%d", &n);

  for (int i = 0; i < n; i++)
  {
      scanf("%s", s);
      if(s[0] == 'A') a++;
      if(s[0] == 'W') w++;
      if(s[0] == 'T') t++;
      if(s[0] == 'R') r++;
  }
  

  printf("AC x %d\n", a);
  printf("WA x %d\n", w);
  printf("TLE x %d\n", t);
  printf("RE x %d\n", r);

  return 0;
}

Measured memory_bytes: 1736
#include<cstdio>
#include<cstring>

int main(void){
int i,j;
int m[256];
int s[256]={0};
char c[256][201];
int d[256]={0};
int k=0;
while(1){
	scanf("%s",c[k]);
	if(strcmp(c[k],"-")==0) break;
	while(c[k][d[k]]!='\0'){d[k]++;};
	
	scanf("%d",&m[k]);
	for(i=0;i<m[k];i++){
		scanf("%d",&j);
		s[k]=s[k]+j;
	};
	s[k]=s[k]%d[k];
	k++;
}

for(i=0;i<k;i++){
	for(j=0;j<d[i];j++){
		c[i][j+d[i]]=c[i][j];
	};
	for(j=0;j<d[i];j++){
		printf("%c",c[i][j+s[i]]);
	};
	printf("\n");
};
return 0;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int n,r;

int main(){
  cin >> n >> r;
  if(n>=10){cout << r;}
  else{cout << r+100*(10-n);}
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() 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 main() {
	n := nextInt()
	var sAry []string = make([]string, n)
	for i := 0; i < n; i++ {
		sAry[i] = nextLine()
	}

	m := map[string]int{}
	for i := 0; i < n; i++ {
		A := strings.Split(sAry[i], "")
		sort.Strings(A)
		s := strings.Join(A, "")
		m[s]++
	}
	for key, _ := range m {
		m[key]--
		if m[key] == 0 {
			delete(m, key)
		}
	}

	ret := 0
	for key, _ := range m {
		ret += (m[key] * (1 + m[key]) / 2)
	}
	fmt.Println(ret)

	// for {
	// 	for key, _ := range m {
	// 		m[key]--
	// 		ret += m[key]
	// 		if m[key] == 0 {
	// 			delete(m, key)
	// 		}
	// 	}
	// 	if len(m) == 0 {
	// 		break
	// 	}
	// }
	// fmt.Println(ret)
}


Measured memory_bytes: 17536
k, x = map(int, input().split())


def solve():
    _min = -1000000
    _max = 1000000

    if (x - k + 1) > _min:
        _min = x - k + 1
    if (x + k - 1) < _max:
        _max = x + k - 1

    ans = list(map(str, range(_min, _max + 1)))

    return ' '.join(ans)


print(solve())


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

int main() {
  int N, T;
  float A;
  cin >> N >> T >> A;

  int answer;
  float min_diff = 10000.0;

  for (int i = 1; i <= N; i++) {
    int h;
    cin >> h;

    float t = T - h * 0.006;
    float diff = abs(A - t);

    if (diff < min_diff) {
      min_diff = diff;
      answer = i;
    }
  }

  cout << answer << endl;
}

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

int main(){
  int h, w, y, x;
  cin >> h >> w >> y >> x;

  if(h % 2 == 0 || w % 2 == 0){
    cout << "Yes" << endl;
  }else{
    if(y % 2 == x % 2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3124
from itertools import repeat, permutations


if __name__ == '__main__':
    n, m = map(int, input().split())    # 2≦N≦8    nが小さいので列挙でもいけるか?
    # 0≦M≦N(N−1)⁄2    全ての頂点が結ばれている場合もあり得る。
    edges = [list(repeat(False, n)) for i in range(n)]
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1      # 0オリジン
        b -= 1
        edges[a][b] = True
        edges[b][a] = True
    # print(edges)
    # 末端(1本しか道のない頂点)の数で分類すれば高速化するが、
    # 末端のないケースが通るなら場合分けしなくてもTLEしないはず。
    result = 0      # 結果格納用
    # 出発は頂点1(コード内の番号は0)なので、それ以外についてリストする。
    for order_iterable in permutations(range(1, n)):
        order = [0] + list(order_iterable)
        # orderの隣同士の間に辺が存在することが、到達可能の条件
        if all([edges[order[i - 1]][order[i]] for i in range(1, n)]):
            result += 1     # 計数
    print(result)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 300005

char buf[SIZE];
int num_E[SIZE],num_W[SIZE];


int main(){

	int N;
	scanf("%d",&N);
	scanf("%s",buf);

	num_W[0] = 0;
	for(int i = 1; i <= N; i++){

		num_W[i] = num_W[i-1];
		if(buf[i-1] == 'W'){
			num_W[i]++;
		}
	}
	num_E[N+1] = 0;
	for(int i = N; i >= 1; i--){

		num_E[i] = num_E[i+1];
		if(buf[i-1] == 'E'){

			num_E[i]++;
		}
	}

	int ans = N;
	for(int i = 1; i <= N; i++){

		ans = min(ans,num_W[i-1]+num_E[i+1]);
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 6448
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort()
    B.sort()
    C.sort()

    nums = [0] * (N + 1)

    ng = -1
    for i, b in enumerate(B):
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if C[mid] > b:
                ok = mid
            else:
                ng = mid

        nums[i] = N - ok

    for i in range(N, 0, -1):
        nums[i - 1] += nums[i]

    ans = 0
    ng = -1
    for a in A:
        ok = N
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if B[mid] > a:
                ok = mid
            else:
                ng = mid

        ans += nums[ok]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 92968
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int P=1e9+7;
inline void upd(R int &x,R int y){(x+=y)>=P?x-=P:0;}
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=3005;
int f[N][N][2],n,m,res;
int main(){
	scanf("%d%d",&n,&m),--n,--m;
	f[0][0][1]=1;
	fp(i,1,n)f[0][i][0]=1;
	fp(i,0,m-1)fp(j,0,n)fp(k,0,1)if(f[i][j][k]){
		if(j)upd(f[i+1][j-1][k|(j==1)],f[i][j][k]);
		if(j<n)upd(f[i+1][j+1][k],f[i][j][k]);
		upd(f[i+1][j][k],add(f[i][j][k],f[i][j][k]));
	}
	fp(i,0,n)upd(res,f[m][i][1]);
	printf("%d\n",mul(res,4));
	return 0;
}

Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  if(s[0] == s[2]) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define ull unsigned ll
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (ll i = l; i < r; i++)
#define repb(i, r, l) for (ll i = r; i > l; i--)
#define sz(a) (ll)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const ll N = 100000;
const ll inf = (ll)1e9 + 1;
const ll big = (ll)1e18 + 1;
const ll P = 31;
const ll MOD = (ll)1e9 + 7;
const ll MOD1 = (ll)1e9 + 9;
const ll MAX_ll = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    rep(i, 0, n)
        cin >> x[i];
    ll a1[n], b1[n];
    a1[0] = 0; b1[0] = 0;
    rep(i, 1, n)
    {
        if (x[i]- x[i - 1] < a)
            a1[i] = 1;
        else
            a1[i] = 0;
        if (x[i] - x[i - 1] < b)
            b1[i] = 1;
        else
            b1[i] = 0;
        a1[i] += a1[i - 1];
        b1[i] += b1[i - 1];
    }
    ll dp[n][2];
    rep(i, 0, n)
        rep(j, 0, 2)
            dp[i][j] = 0;
    rep(i, 0, n)
    {
        ll p = upper_bound(x.begin(), x.end(), x[i] - a) - x.begin();
        if (p == i)
        {
            if (i == 0)
                dp[i][0] = 1;
            else
                dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (b1[i - 1] - b1[p] > 0)
                dp[i][0] = 0;
            else
                dp[i][0] = dp[p][1];
        }

        p = upper_bound(x.begin(), x.end(), x[i] - b) - x.begin();
        if (p == i)
        {
            if (i == 0)
                dp[i][1] = 1;
            else
                dp[i][1] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
        }
        else
        {
            if (a1[i - 1] - a1[p] > 0)
                dp[i][1] = 0;
            else
                dp[i][1] = dp[p][0];
        }
    }
    int res = (dp[n - 1][0] + dp[n - 1][1]) % MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
ll cnt;
ll maxn;
ll a;
ll n;
ll id;
ll last;
int main()
{
	scanf("%lld",&n);
	maxn=-99999999;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		if(a>maxn)
		{
			last=maxn;
			maxn=a;
			cnt=1;
			id=i;
		}
		else if(a==maxn)
		{
			cnt=2;
		}
		else if(a>last)
		{
			last=a;
		}
	}
	if(cnt==2)
	{
		for(int i=1;i<=n;i++)
		{
			printf("%lld\n",maxn);
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			if(i==id)
			{
				printf("%lld\n",last);
				continue;
			}
			else
			{
				printf("%lld\n",maxn);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1536
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    ll n, m;cin >> n >> m;
    ll ans = 0;
    if(m%2 == 1){
        m--;
    }
    if(2*n >= m){
        ans += m/2;
    }else{
        ans += n;
        m -= 2*n;
        if(m > 0){
            ans += m/4;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main(string[] args)
    {
        string[] line = Console.ReadLine().Split();
        int a = int.Parse(line[0]);
        int b = int.Parse(line[1]);

        if (a <= 8 && b <= 8)
            Console.Write("Yay!");
        else
            Console.WriteLine(":(");
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    for(ll d=(s.size()-1)/2*2; d>0;d-=2){
        if(s.substr(0,d/2) == s.substr(d/2,d/2)){
            puta(d);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VS = vector<string>;
#define rep(start, end) for(int loop_var = start; loop_var <= end; ++loop_var)
#define repconref(container) for(auto& container_element: container)
#define all(container) begin(container), end(container)
#define ftl ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define intmap map<int, int>
#define intset set<int>
#define has(a, b) ((a.find(b) != a.end()) ? true : false)
bool ok(int n, const intset& d) {
    while(n) {
        int x = n % 10;
        if(has(d, x))
            return false;
        n /= 10;
    }
    return true;
}

int main() {
    ftl;
    int n, k;
    cin >> n >> k;
    intset d;
    rep(0, k - 1) {
        int x;
        cin >> x;
        d.insert(x);
    }
    while(true) {
        if(ok(n, d)) {
            cout << n; return 0;
        }
        ++n;
    }
    return 0;
}

Measured memory_bytes: 256
package main
import "fmt"

func main(){

        var tap, goal int
        nbr_current := 1
        fmt.Scanf( "%d", &tap )
        fmt.Scanf( "%d", &goal )

        count := 0
        for nbr_current < goal{
                nbr_current += tap - 1
                count ++
        }
        fmt.Printf( "%d", count )
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,next,p=1;
    long long n,sum=0;
    cin>>n;cin>>x;
    if(x!=0){p=0;}
    for(int i=1;i<n;i++){
        cin>>next;
        if(next-x>1){p=0;}
        else if(next-x==1){sum++;}
        else{sum+=next;}
        x=next;
    }
    if(p){cout<<sum<<endl;}
    else {cout<<"-1"<<endl;}
    return 0;
}



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

#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN];
int head,tail,n;



void enqueue(P X){
  Q[tail]=X;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P X = Q[head];
  head=(head+1)%LEN;
  return X;
}
int min(int a,int b){
  if(a<b)return a;
  else return b;
}



int main(){
  P u;
  int elaps=0;
  int i,q,c;

  scanf("%d%d",&n,&q);

  for(i=1;i <= n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){

    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    elaps = elaps+c;

    if(u.t>0)enqueue(u);

    else {
      printf("%s %d\n",u.name,elaps);
    }

  }

  return 0;
}



Measured memory_bytes: 12012
S=input()
cnt=0

L=int((len(S)-1)/2)
#print(L)

for i in range(L):
    #print(S[i])
    #print(S[-(i+1)])
    if S[i]==S[-(i+1)]:
        cnt+=1

if cnt!=L:
    print('No')
    exit()

S=S[0:L]
#print(S)

cnt=0
LEN=len(S)
for i in range(LEN):
    if S[i] == S[LEN-(i+1)]:
        cnt+=1

if cnt==LEN:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
posx = 0
posy = 0
mod = 10**9+7
ans = 1
flgx = 0
flgy = 0
if len(set(a)) != len(a) or len(set(b)) != len(b):
  print(0)
  exit()
if max(a) != n*m or max(b) != n*m:
  print(0)
  exit()
for i in range(n*m,0,-1):
  while posx<n-1 and a[posx+1] >= i:
    posx += 1
  if a[posx] == i:
    flgx = 1
  while posy<m-1 and b[posy+1] >= i:
    posy += 1
  if b[posy] == i:
    flgy = 1
  if flgx and flgy:
    flgx = 0
    flgy = 0
    continue
  elif flgx:
    ans = (ans*(posy+1))%mod
  elif flgy:
    ans = (ans*(posx+1))%mod
  else:
    ans = (ans*((posx+1)*(posy+1)-(n*m-i)))%mod
  flgx = 0
  flgy = 0
print(ans)

Measured memory_bytes: 42604
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s; cin >> s;
    int n = s.length() - 1;

    ll ans = 0;
    ll tmp = 0;
    for (int i = 0; i < (1<<n); i++) {
        tmp = s[0] - '0';
        for (int j = 0; j < n; j++) {
            if (i & 1 << j) {
                ans += tmp;
                tmp = 0;
            }
            tmp = tmp * 10 + (s[j+1] - '0');
        }
        ans += tmp;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

const int N = 2005;
bool G[N][N];
bool used[N];
vector <int> g[N];
int n, a[N], sz;
int in[N];
priority_queue <int> pq;

inline int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }

void dfs(int i) {
	used[i] = 1;
	for (int j = 0; j < n; ++ j) if (!used[j] && G[i][j]) { g[i].push_back(j); ++ in[j]; dfs(j); }
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	sort(a, a + n);
	for (int i = 0; i < n; ++ i) for (int j = 0; j < n; ++ j) if (i ^ j) G[i][j] = (gcd(a[i], a[j]) != 1);
	for (int i = 0; i < n; ++ i) if (!used[i]) dfs(i);
	for (int i = 0; i < n; ++ i) if (!in[i]) pq.push(i);
	while (!pq.empty()) {
		int i = pq.top(); pq.pop();
		printf("%d ", a[i]);
		for (int j = 0; j < (int) g[i].size(); ++ j) {
			-- in[g[i][j]];
			if (!in[g[i][j]]) pq.push(g[i][j]);
		}
	}
	puts("");
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mp make_pair
const int maxn = 4e5+5;
const int MOD = 1e9+7;
#define mod(x) x % MOD
#define INF 0x3f3f3f3f

int dp[maxn];
int a[maxn];
int main(){
    int n = 0;
    int k = 0;
    while(~scanf("%d %d", &n, &k)){
        for(int i = 1;i <= n;i++){
            dp[i] = MOD;
        }
        for(int i = 1;i <= n;i++){
            scanf("%d",a + i);
        }
        dp[0] = 0;
        dp[1] = 0;
        //dp[2] = abs(a[2] - a[1]);
        for(int i = 2;i <= n;i++){
            for(int j = 1;j <= k;j++){
                if(i - j <= 0) continue;
                dp[i] = min(dp[i],dp[i-j] + abs(a[i] - a[i-j]));
            }
            //dp[i] = min( dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]) );
        }
        /*for(int i = 1;i <= n;i++){
            dp[i+1] = min(dp[i+1], dp[i] + abs(a[i] - a[i+1]));
            dp[i+2] = min(dp[i+2], dp[i] + abs(a[i] - a[i+2]));
        }*/
        printf("%d\n",dp[n]);
    }
    return 0;
}

Measured memory_bytes: 1024
object Main extends App {
  import scala.io.StdIn._


  val prime = primes(1000000)
  solve

  def solve: Unit = {
    val l = readLong
    if (l == 0) return
    var exp = Nil: List[Int]
    var n = l
    var i = 0
    while (n != 1 && i < prime.length) {
      val p = prime(i)
      if (n % p == 0) {
        var e = 0
        while (n % p == 0) {
          n /= p
          e += 1
        }
        exp ::= e
      }
      i += 1
    }
    if (n != 1)  exp ::= 1
    println(calCombination(exp))
    solve
  }
  def calCombination(exponents: List[Int]): Long = {
    if (exponents.isEmpty) return 1
    val combinationMemo = Array.tabulate(exponents.length){_ ⇒ -1L}
    combinationMemo(0) = 1
    def sub(current: Int, exp: List[Int]): Long = {
      if (combinationMemo(current) == -1){
        combinationMemo(current) = sub(current - 1, exp.tail) * (2 * exp.head + 1)
      }
      combinationMemo(current)
    }
    def sub2(current: Int, exp: List[Int]): Long = {
      exp match {
        case Nil ⇒ 1
        case h::t ⇒ sub2(current - 1, t) + sub(current - 1, t) * h
      }
    }
    sub2(exponents.length, exponents)
  }
  def primes(upper: Int): Array[Int] = {
    val memo = Array.tabulate(upper + 1){_ ⇒ true}
    for (i ← 2 to math.sqrt(upper).toInt) {
      if (memo(i))
        for (j ← i * 2 to upper by i)
          memo(j) = false
    }
    (2 to upper).filter(memo).toArray
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}



Measured memory_bytes: 85272
#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
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 mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 

#define  mx 200004
#define base 193ll
 
typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){
    int n, m , x, y;
    I2(n, m);
    I2(x, y);

    int ar[n+2];
    int br[m+2];

    for(int i = 1; i <= n; i++){
        I(ar[i]);
    }
    for(int j = 1; j <= m; j++){
        I(br[j]);
    }

    sort(ar + 1, ar + n + 1);
    sort(br + 1 , br + m + 1);

    for(int i = x + 1; i <= y; i++){
        if(i > ar[n] && i <= br[1]){
            PC("No War");
            NL;
            return 0;
        }
    }

    PC("War");
    NL;
    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
map<int, int> mp;
int main()
{
	int n;
	cin >> n;
	long long ans = 1;
	for (int i = 1; i <= n; i++) ans = ans * i % INF;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  bool ans=1;
  for(int i=0;i<s.length();++i)
  { if(i%2 && s[i]=='R')
  {
    cout<<"No";
    ans=0;
    break;
  }
  else if(i%2==0 && s[i]=='L')
   {
     cout<<"No";
    ans=0;
     break;
   }
   
  }
  if(ans)
     cout<<"Yes";
  return 0;
}
  


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	print $ length $ filter odd $ map ( length . show ) $ [ 1 .. n ]

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main() {
  long long n, m, x, y;
  cin >> n >> m;
  vector<long long> a(m), b(m);
  for(int i = 0; i < m; ++i){
    cin >> a[i];
    cin >> x;
    for(int j = 0; j < x; ++j){
      cin >> y;
      y--;
      b[i] |= 1 << y;
    }
  }
  long long nn = 1 << n;
  vector<long long> d(nn, 1e9);
  d[0] = 0;
  for(int i = 0; i < nn; ++i){
    if(d[i] == 1e9) continue;
    for(int j = 0; j < m; ++j){
      long long ii = i | b[j];
      d[ii] = min(d[ii], d[i] + a[j]);
    }
  }
  cout << (d[nn - 1] == 1e9? -1: d[nn - 1]);
}


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

using namespace std;

int main(){
    int x;
    int a[4];
    scanf("%d", &x);
    for(int n = 0; n < 4; n++){
        a[3-n] = x % 10;
        x /= 10;
    }

    char op[3];

    for(int t = 0; t < (1 << 3); t++){
        int ans = a[0];
        for(int i = 0; i < 3; i++){
            if(t & (1 << i)){
                ans -= a[i + 1];
                op[i] = '-';
            }else{
                ans += a[i + 1];
                op[i] = '+';
            }
        }
        if(ans == 7)break;
    }

    cout << a[0] << op[0] << a[1] << op[1] << a[2] << op[2] << a[3] << '=' << 7 << endl;
}

Measured memory_bytes: 256
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7
INF = 10**18

A,B,Q = MAP()
s = [-INF] + [INT() for _ in range(A)] + [INF]
t = [-INF] + [INT() for _ in range(B)] + [INF]

for i in range(Q):
    cur = INT()
    s_idx = bisect.bisect_right(s,cur)
    t_idx = bisect.bisect_right(t,cur)
    res = INF
    for S in [s[s_idx-1],s[s_idx]]:
        for T in [t[t_idx-1],t[t_idx]]:
            d1,d2 = abs(S-cur) + abs(T-S),abs(T-cur)+abs(S-T)
            res = min(res,d1,d2)
    print(res)

Measured memory_bytes: 82396
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	a := getNextInt(scanner)
	b := getNextInt(scanner)

	if b > n*a {
		fmt.Fprintln(writer, n*a)
	} else {
		fmt.Fprintln(writer, b)
	}

	writer.Flush()
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    ll n, s=1;
    int k, i=0;

    cin>> n>> k;


    while( n!= 0)
    {
        n/= k;
        i++;
    }

    cout<< i << '\n';

    return 0;
}




Measured memory_bytes: 3644
import java.util.Scanner;
public class Main{
 public static void main(String args[]){
   Scanner sc=new Scanner(System.in);
   int a=sc.nextInt();
   int b=sc.nextInt();

       if((a*b)%2==0)
           System.out.println("Even");
       else
           System.out.println("Odd");




   sc.close();
 }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define reg register
#define MAX 100005

using namespace std;

const int mod = 1e9 + 7;
int N, M;
int fa[MAX];
long long ans;
struct qrys {
	int A, B;
}a[MAX];

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline int find(int id) {
	return fa[id] == id ? id : fa[id] = find(fa[id]);
}
bool cmp(qrys aa, qrys bb) {
	if(aa.B == bb.B) {
		return aa.A < bb.A;
	}
	return aa.B > bb.B;
}

int main() {
	N = Rd(), M = Rd() + 1;
	for(reg int i = 1; i <= N; ++i) a[i].A = Rd(), a[i].B = Rd();
	for(reg int i = 1; i <= M; ++i) fa[i] = i;
	sort(a + 1, a + 1 + N, cmp);
	for(reg int i = 1; i <= N; ++i) {
		if(a[i].A > M) continue;
		int x = find(M - a[i].A);
		if(x != 0) {
			fa[x] = find(fa[x] - 1);
			ans += a[i].B;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  std::string S; std::cin >> S;

  int ans = 0;
  for(auto&& s : S) {
    if ( s == '+' ) ans++;
    if ( s == '-' ) ans--;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n);++i)
using namespace std;
using ll = long long; 
using P = pair<int,int>;
using vv = vector<vector<ll>>;
template <class _t> inline bool chmax (_t& a,_t b){if(a<b){a=b;return true;}return false;} template <class _t> inline bool chmin (_t& a,_t b){if(a>b){a=b;return true;}return false;}

const int INF = 2147483647;
const long long inf = 1ll << 60;
const long long mod = 1000000007;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n,k;cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    int ans = 0;
    rep(i,k) ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

const int MAX_K = 100000;

const int MOD = 1e9 + 7;

int buf[2][MAX_K + 1], s[MAX_K + 1];

inline int add(int x, int v) { return x + v >= MOD ? x + v - MOD : x + v; }
inline int sub(int x, int v) { return x - v < 0 ? x - v + MOD : x - v; }

int main() {
  buf[0][0] = 1;
  int n, k;
  std::cin >> n >> k;
  for (int i = 1, a; i <= n; ++i) {
    auto g = buf[~i & 1];
    auto f = buf[i & 1];
    s[0] = g[0];
    for (int i = 1; i <= k; ++i) s[i] = add(s[i - 1], g[i]);
    std::cin >> a;
    for (int j = 0; j <= a; ++j) f[j] = s[j];
    for (int j = a + 1; j <= k; ++j) f[j] = sub(s[j], s[j - a - 1]);
  }
  std::cout << buf[n & 1][k];
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n){
    if(s[i] == '7'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
 
    static Scanner cin;
    Random r;
 
    void calc()
    {
        int N = cin.nextInt();
      	Console.WriteLine(N*N*N);      
    }
 
}
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
  string s;
  cin>>s;
  long long a=-1;
  long long b=-1;
  for(long long i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      a=i;
      break;
    }
  }
  for(long long j=s.size()-1;j>=0;j--){
    if(s.at(j)=='Z'){
      b=j+1;
      break;
    }
  }
  cout<<b-a<< endl;
}
      

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
double f[305][305][305];int t[3],a,n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a),t[a-1]++;
    for(int i=0;i<=n;i++)
    for(int j=0;j<=n-i;j++)
    for(int k=0;k<=n-i-j;k++){
        if(!i&&!j&&!k) continue;
        double sm=i+j+k,p=n/sm;
        if(i) f[i][j][k]+=f[i-1][j+1][k]*i/sm;
        if(j) f[i][j][k]+=f[i][j-1][k+1]*j/sm;
        if(k) f[i][j][k]+=f[i][j][k-1]*k/sm;
        f[i][j][k]+=p;
    }
    printf("%.10lf",f[t[2]][t[1]][t[0]]);
    return 0;
}

Measured memory_bytes: 219392
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int a,b,k;
   cin>>a>>b>>k;
   for(int i=0;i<k;i++)
   {
       if(i%2==0)
       {
           if(a%2!=0)
            a--;
           b+=a/2;
           a/=2;
       }
       else
       {
           if(b%2!=0)
            b--;
           a+=b/2;
           b/=2;
       }
   }
   cout<<a<<" "<<b;
 }

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

typedef struct proces{
  char name[10];
  int count;
  int time;
}
  def;

int head,tail,n;
def a[100000];




void enq(def s){
  a[tail]=s;
  tail=(tail+1) % 100000;
}




def deq(){
  def sd=a[head];
  head = (head+1) % 100000;
  return sd;
}

int min(int k,int l){
  
  if(k>l) return l;
  else return k;
}

int main(){
  int tasu,i,q,b,sum=0;
  def t;
  scanf("%d %d",&b,&q);
  for(i=1;i<=b;i++){
    scanf("%s",a[i].name);
    scanf("%d",&a[i].time);
    a[i].count=1;
  }
  head=1;
  tail=b+1;
  while(tail != head){
    t=deq();
    
    tasu=min(q,t.time);
    t.time=t.time-tasu;
    sum=sum+tasu;
    if(t.time>0){
      enq(t);
    }
    
    else if(t.count==1){
      printf("%s %d\n",t.name,sum);
      t.count=0;
    }
  }
  return 0;
}



Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    long long  N;
    long long  P[100005], J[100005];
 
    while ( cin >> N, N != 0 ) {
        long long sum = 0;
        for ( int i = 0; i < N; i++ ) {
            cin >> P[i];
            sum += P[i];
        }
 
        for ( int i = 0; i < N - 1; i++ ) {
            cin >> J[i];
        }
 
        sort(J, J + N - 1, greater < long long  >  ());
        long long  maxv = N * sum;
        for ( int i = 0; i < N - 1; i++ ) {
            sum += J[i];
            maxv = max(maxv, (N - i - 1) * sum);
        }
        cout << maxv << endl;
    }
 
    return ( 0 );
}


Measured memory_bytes: 4140
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int N, D;
    cin >> N >> D;

    cout << CEIL(N, 2 * D + 1) << "\n";

    return 0;
}



Measured memory_bytes: 256
fun main(args : Array<String>) {
        val (h, w, d) = readLine()!!.split(" ").map { it.toInt() }
        val size = h * w
        val array = Array(size) { Pair(0, 0) }.apply {
            (0 until h).forEach { y -> readLine()!!.split(" ").forEachIndexed { x, a -> set(a.toInt() - 1, Pair(x, y)) } }
        }
        val sum = Array(size) { 0 }.apply {
            (0 until size).forEach { i ->
                if (i < d) set(i, 0)
                else set(i, get(i - d) + Math.abs(array[i].first - array[i - d].first) + Math.abs(array[i].second - array[i - d].second))
            }
        }
        (1..readLine()!!.toInt()).forEach {
            readLine()!!.split(" ").let { println(sum[it[1].toInt() - 1] - sum[it[0].toInt() - 1]) }
        }
}

Measured memory_bytes: 77164