akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main()
{
    int n,d;
    cin>>n>>d;
    int x[n][d];
    int ans=0;
    REP(i,n)REP(j,d)cin>>x[i][j];
    REP(i,n-1)rep(j,i+1,n)
    {
        double sum=0;
        REP(k,d)sum+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
        if(sqrt(sum)==(int)sqrt(sum))ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    ll a,s;cin>>a>>s;
    cout<<a-s+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 600300;
int c[maxn], pos[maxn], pr[maxn], ans[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	for(int i = 0; i < n; i++){
		int x; cin >> x;
		c[x]++;
	}
	vector<int> occ;
	for(int i = 0; i < maxn; i++){
		if(c[i]){
			occ.push_back(c[i]);
		}
	}
	sort(occ.begin(), occ.end());
	int len = occ.size();
	for(int i = 1; i <= 2 * n; i++){
		pos[i] = lower_bound(occ.begin(), occ.end(), i) - occ.begin();
	}
	pr[0] = occ[0];
	for(int i = 1; i < len; i++) pr[i] = pr[i - 1] + occ[i];
	int p = 0;
	for(int k = 1; k <= n; k++){
		while(p < len && occ[p] < k) p++;
		int s = 0;
		if(p) s += pr[p - 1] / k;
		s += len - p;
		ans[s] = max(ans[s], k);
	}
	for(int i = n; i >= 1; i--){
		ans[i] = max(ans[i], ans[i + 1]);
	}
	for(int i = 1; i <= n; i++){
		cout << ans[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 9328
using System;
using System.Collections.Generic;
using System.Linq;

class M{static void Main(string[] _) {
  
  var I0 = Console.ReadLine().Split(' ');
  long A = long.Parse(I0[0]) - 1;
  long B = long.Parse(I0[1]);

  long a = ( A % 2 != 0 )? ((A+1)/2)%2 : (A+(A/2)%2);
  long b = ( B % 2 != 0 )? ((B+1)/2)%2 : (B+(B/2)%2);
  
  long r = 0;
  long P = 1;
  while( P <= a || P <= b ) {
    r+= ( ((a/P)%2) != ((b/P)%2) )? P : 0;
    P *= 2;
  }

  Console.WriteLine( r );
  
}}
        

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define bzero(m)  memset(m,0,sizeof(m))
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef unsigned long long u64;
typedef long long i64;

i64 A,B,C;

i64 dfs(vector<i64> &l, int d, int n, i64 a, i64 b, i64 c){
        if (d == n){
                if (a == 0 || b == 0 || c == 0)
                        return 1000000000UL;
                a -= A;
                b -= B;
                c -= C;
                return (a>0? a:-a) + (b>0?b:-b) + (c>0?c:-c);
        }

        return min(
                min(dfs(l, d+1, n, a+l[d], b, c) + (i64)(a==0?0:10),
                        dfs(l, d+1, n, a, b+l[d], c) + (i64)(b==0?0:10)),
                min(dfs(l, d+1, n, a, b, c+l[d]) + (i64)(c==0?0:10),
                        dfs(l, d+1, n, a, b, c)));
}


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

        i64 n;
        vector<i64> l;

        cin >> n >> A >> B >> C;
        REP(i,n){
                i64 k;
                cin >> k;
                l.push_back(k);
        }

        i64 r = dfs(l, 0, (int)n, (i64)0,(i64)0,(i64)0);
        cout << r << endl;

        return 0;
}


Measured memory_bytes: 256
import queue
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))

b = queue.Queue()
for i, j in enumerate(a):
    for _ in range(j):
        b.put(i+1)

for i in range(h):
    ans = []
    for j in range(w):
        ans += [b.get()]
    if i%2 == 1:
        ans = list(reversed(ans))
    print(*ans)



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

int main(){
  string s;
  cin >> s;
  int l = s.length();
  int k;
  cin >> k;
  vector<vector<vector<ll>>> dp(l+1,vector<vector<ll>>(k+2,vector<ll>(2,0)));
  dp[0][0][0] = 1;
  rep(i,l) {
    rep(j,k+1) {
      if(s[i] == '0') {
        dp[i+1][j][0] = dp[i][j][0];
      } else {
        dp[i+1][j+1][0] += dp[i][j][0];
        dp[i+1][j][1] += dp[i][j][0];
        dp[i+1][j+1][1] += (ll)(s[i]-'1') * dp[i][j][0]; 
      }
      dp[i+1][j][1] += dp[i][j][1];
      dp[i+1][j+1][1] += dp[i][j][1] * 9;
    }
  }
  cout << dp[l][k][0] + dp[l][k][1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define eps 0.000001
#define ll long long
#define INF 1e18
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define uint unsigned int

const int mod = 1000000000+7;

vector<vector<ll> > ID(int n )
{
	vector<vector<ll > > v(n,vector<ll>(n,0));
	for(int i = 0; i<n; i++){
		v[i][i] = 1;
	}
	return v;
}
vector<vector<ll> > mul(vector<vector<ll>> &a, vector<vector<ll> > &b)
{
	int n = a.size();
	vector<vector<ll> > c(n,vector<ll> (n,0));
	for(int i = 0 ;i<n; i++)
	{
		for(int j = 0 ;j<n; j++)
		{
			for(int k = 0; k <n; k++)
			{
				c[i][j] += a[i][k]*b[k][j]%mod;
				c[i][j] %= mod;
			}
		}
	}
	return c;
}
vector<vector<ll> > mpow(vector<vector<ll>> a, ll b)
{
	vector<vector<ll> > ans = ID(a.size());
	for(;b;b>>=1)
	{
		if(b&1) ans = mul(ans,a);
		a = mul(a,a);
	}
	return ans;
}


main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	ll k;
	cin >> n >> k;
	vector<vector<ll> > a;
	a.resize(n,vector<ll>(n));
	for(int i = 0 ;i<n; i++)
	{
		for(int j = 0; j<n; j++)
		{
			cin >> a[i][j];
		}
	}
	a = mpow(a,k);
	ll ans = 0;
	for(auto it : a)
	{
		for(auto it1 : it)
		{
			ans += it1;
		}
	}
	cout << ans%mod << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b,k;
    cin >> a >> b >> k;
    for(int i = a; i <= b; i++){
        if((i >= a && a+k > i) || (i <= b && b-k < i)){
            cout << i << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 256
var
table = {
  A: 0,
  B: 1,
  C: 2,
  0: 'A',
  1: 'B',
  2: 'C',
},
cups = [true, false, false];

function main() {
  input.forEach(function(line) {
    if(line.trim() === '') return;
    line = line.split(',');
    swap(cups, table[line[0]], table[line[1]]);
  });
  console.log(table[cups.indexOf(true)]);
}

function swap(xs, i, j) {
  var
  x = xs[i];
  xs[i] = xs[j];
  xs[j] = x;
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 7652
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    m1, d1 = list(map(int, input().strip().split()))
    m2, d2 = list(map(int, input().strip().split()))
    if m1 != m2:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


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


n = int(input())
up = 10**18
l = list(map(int, input().split()))

if 0 in l:
    print(0)
else:
    ans = 1
    for i in l:
        ans *= i
        if ans > up:
            print(-1)
            break
    else:
        print(ans)

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

int main() {
	int n;
	cin >> n;
	int a[n], b[n] = {};
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		b[a[i]]++;
	}
	if (n % 2 == 0) {
		for (int i = 1;i < n;i += 2) {
			if (b[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
	}
	else {
		for (int i = 2;i < n;i += 2) {
			if (b[i] != 2 || b[0] != 1) {
				cout << 0 << endl;
				return 0;
			}
		}
      	n--;
	}
	long long ans = 1;
	for (int i = 0;i * 2 < n;i++) {
		ans *= 2;
		ans %= 1000000007;
	}
	cout << ans << endl;
}

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

int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		cout<<'x';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct segment_tree{
	
	vector<vector<bool>> st;
	
	segment_tree(int n) : st(4 * n, vector<bool>(26)){
		
	}
	
	void update(int node, int b, int e, int pos, int val){
		if(b == e){
			st[node] = vector<bool>(26);
			st[node][val] = true;
		}
		else{
			int m = (b + e) >> 1;
			int l = node << 1;
			int r = l | 1;
			
			if(pos <= m)
				update(l, b, m, pos, val);
			else
				update(r, m + 1, e, pos, val);
			
			st[node] = vector<bool>(26);
			for(int i = 0; i < 26; i++)
				st[node][i] = st[l][i] | st[r][i];
		}
	}
	
	vector<bool> query(int node, int b, int e, int i, int j){
		if(b >= i && e <= j)
			return st[node];
		
		if(b > j || e < i)
			return vector<bool>(26);
			
		int m = (b + e) >> 1;
		int l = node << 1;
		int r = l | 1;
		
		auto L = query(l, b, m, i, j);
		auto R = query(r, m + 1, e, i, j);
		
		vector<bool> ans(26);
		for(int i = 0; i < 26; i++)
			ans[i] = L[i] | R[i];
		
		return ans;
	}
	
};

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	segment_tree st(n);
	
	for(int i = 0; i < n; i++)
		st.update(1, 0, n - 1, i, s[i] - 'a');
	
	int q;
	cin >> q;
	
	while(q--){
		int t;
		cin >> t;
		
		if(t == 2){
			int l, r;
			cin >> l >> r;
			l--, r--;
			auto ans = st.query(1, 0, n - 1, l, r);
			int cnt = 0;
			for(int i = 0; i < 26; i++)
				cnt += ans[i];
			cout << cnt << endl;
		}
		else{
			int pos;
			char c;
			cin >> pos >> c;
			pos--;
			st.update(1, 0, n - 1, pos, c - 'a');
		}
	}

	return 0;
}


Measured memory_bytes: 143388
from copy import deepcopy

N=int(input())
A=list(map(int,input().split()))
ans=[0]*(N//2+1)+A[N//2:]
A=[0]+A

ok=1
for i in range(N//2,0,-1):
  if sum(ans[i*2:i*(N//i)+1:i])%2==0:
    ans[i]=A[i]
  else:
    ans[i]=1-A[i]

ans2=[]
for i in range(1,N+1):
  if ans[i]==1:
    ans2.append(i)

print(len(ans2))
if len(ans2)>0:print(*ans2)

Measured memory_bytes: 18648
#!/usr/bin/env python3
import sys


def solve(N: int, H: "List[int]"):

    cur = H[0]
    mc = 0
    mc_max = 0

    for h in H[1:]:
        if cur >= h:
            mc += 1
            mc_max = max(mc, mc_max)
        else:
            mc = 0

        cur = h
    print(mc_max)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, H)

if __name__ == '__main__':
    main()


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

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

bool chkmax(int &x,int y){return x<y?x=y,true:false;}
bool chkmin(int &x,int y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int cys=1000000007;
int n,maxa;
ll a[200005],b[200005],fac[8005],inv[8005],d[4005][4005];

ll mod(ll x){return x>=cys?x-cys:x;}

ll qpow(ll x,ll p){
	ll ret=1;
	for(;p;p>>=1,x=x*x%cys) if(p&1) ret=ret*x%cys;
	return ret;
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint(),b[i]=readint(),chkmax(maxa,max(a[i],b[i]));
	fac[0]=inv[0]=1;
	for(int i=1;i<=4*maxa;i++) fac[i]=fac[i-1]*i%cys;
	inv[4*maxa]=qpow(fac[4*maxa],cys-2);
	for(int i=4*maxa-1;i>=1;i--) inv[i]=inv[i+1]*(i+1)%cys;
	for(int i=1;i<=n;i++) d[-a[i]+maxa][-b[i]+maxa]++;
	for(int i=0;i<=2*maxa;i++){
		for(int j=0;j<=2*maxa;j++){
			if(i) d[i][j]=mod(d[i][j]+d[i-1][j]);
			if(j) d[i][j]=mod(d[i][j]+d[i][j-1]);
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++) ans=mod(ans+d[a[i]+maxa][b[i]+maxa]);
	for(int i=1;i<=n;i++) ans=mod(ans+cys-fac[2*a[i]+2*b[i]]*inv[2*a[i]]%cys*inv[2*b[i]]%cys);
	printf("%lld\n",ans*((cys+1)/2)%cys);
	return 0;
}

Measured memory_bytes: 128768
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
using namespace std;
typedef long long ll;
int main(){
   #ifndef ONLINE_JUDGE 
      FILE_READ_IN 
      FILE_READ_OUT 
   #endif
    string s; cin>>s;
    int freq[26];
    fill(freq,freq+26,0);
    for(int i=0;i<s.length();i++)
    {
        if(s[i]>='a'&&s[i]<='z')
            freq[s[i]-'a']++;
    }
    bool ok=true;
    for(int i=0;i<26;i++)
    {
        if(freq[i]&1)
            ok=false;
    }
    if(ok)
        cout<<"Yes\n";
    else cout<<"No\n";
   return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) a.begin(), a.end();

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

    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
    }

    int ans = 0;
    rep(i, n) {
        if((i+1) % 2 != 0 && a[i]%2 != 0) {
            ans++;
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3568
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 17;
const int L = 32800;
const int mo = 1e9+7;

LL f[N][L];
int t[L];
int co[N],cu[N];
int n,m;
LL c0[N],c1[N];
LL mi[300];
int cnt[L];
int s1[14350000],s2[14350000];
int it[N],sit[L];

inline LL add(LL x,LL y){
	return x+y>=mo?x+y-mo:x+y;
}

inline int trs(int x,int y){
	int ct=0;
	fo(i,0,n-1){
		ct=ct*3;
		if ((x&(1<<i))>0)ct=ct+1;
		if ((y&(1<<i))>0)ct=ct+2;
	}
	return ct;
}

int main(){
	n=get();m=get();
	fo(i,1,m){
		int x=get(),y=get();
		co[y]|=(1<<(x-1));
		cu[x]|=(1<<(y-1));
		it[y]++;
	}
	mi[0]=1;
	fo(i,1,m)mi[i]=mi[i-1]*2%mo;
	fo(i,1,(1<<n)-1)cnt[i]=cnt[i-(i&-i)]+1;
	fo(i,0,(1<<n)-1){
		for(int x=i;x<(1<<n);x=((x+1)|i)){
			int x_=x^i;
			int now=trs(i,x_);
			//s1
			fo(t,1,n)
			if (((1<<(t-1))&i)>0)s1[now]=s1[now]+cnt[cu[t]&x_];
			s1[now]=mi[s1[now]];
			//s2
			s2[now]=1;
			fo(t,1,n)
			if (((1<<(t-1))&x_)>0)s2[now]=1ll*s2[now]*(mi[cnt[cu[t]&i]]+mo-1)%mo;
		}
		fo(x,1,n)
		if ((i&(1<<(x-1)))>0)sit[i]+=it[x];
	}
	
	LL ans=0;
	fo(i,1,(1<<n)-1){
		f[0][i]=s2[trs(i,((1<<n)-1)^i)];
		if ((i&3)==3)ans=add(ans,f[0][i]*mi[m-sit[i]]%mo);	
	}
	fo(lev,0,n-1)
		fo(i,0,(1<<n)-1)
		if (f[lev][i]){
			for(int x=(i+1)|i;x<(1<<n);x=((x+1)|i)){
				int x_=i^x;
				LL tmp=f[lev][i]*s1[trs(i,x_)]%mo*s2[trs(x_,((1<<n)-1)^x)]%mo;
				f[lev+1][x]=add(f[lev+1][x],tmp);
				if ((i&3)==0&&(x&3)==3)ans=add(ans,tmp*mi[m-sit[x]]%mo);
			}
		}
	ans=(mi[m]+mo-ans)%mo;
	printf("%lld\n",ans);
	return 0;
}

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

#define pb       push_back
#define all(a)   a.begin(), a.end()
#define mp       make_pair
#define ll	long long

using namespace std;
const int MAX = 1e5+9;
int n;
int tab[3];
int ans=0;
int main(){
	cin >> tab[0] >> tab[1] >> tab[2];
  sort(tab,tab+3);
  for(int i=0; i<2; i++){
    ans += abs(tab[i] - tab[i+1]);
  }
  cout << ans << endl;
	return 0;
}

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

//int main(int argc, const char * argv[]) {
int main() {
    int a;
    cin >> a;
    
    int hours, minutes, seconds;
    hours = a / 3600;
    minutes = (a - hours * 3600) / 60;
    seconds = a - hours * 3600 - minutes * 60 ;
    
    cout << hours << ":" << minutes << ":" << seconds << endl;
    
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    char t[20][20];
    rep(i,h)rep(j,w){
        cin>>t[i][j];
    }
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    int maxi=0;
    rep(i,h)rep(j,w){
        if (t[i][j]=='#') continue;
        queue<pi> que;
        vector<vi> dist(h,vi(w,-1));
        dist[i][j]=0;
        que.emplace(i,j);
        while(que.size()){
            int y,x;
            tie(y,x)=que.front(); que.pop();
            rep(i,4){
                int tx=x+dx[i];
                int ty=y+dy[i];
                if (!(0<=tx&&tx<=w-1&&0<=ty&&ty<=h-1)) continue;
                if (t[ty][tx]=='#') continue;
                if (dist[ty][tx]!=-1) continue;
                dist[ty][tx] = dist[y][x]+1;
                maxi=max(maxi,dist[ty][tx]);
                que.emplace(ty,tx);
            }
        }
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long LL;
using namespace std;

 int main() {

     int N;
     cin >> N;

     vector<int> A(N), B(N), C(N);
     for (int i = 0; i < N; i++) cin >> A[i];
     for (int i = 0; i < N; i++) cin >> B[i];
     for (int i = 0; i < N; i++) cin >> C[i];
     sort(A.begin(), A.end());
     sort(B.begin(), B.end());
     sort(C.begin(), C.end());

     LL ans = 0;

     for (int i = 0; i < N; i++) {
         LL pre = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
         LL over = C.end() - upper_bound(C.begin(), C.end(), B[i]);
         ans += pre * over;
     }


     cout << ans;

     return 0;
 }

Measured memory_bytes: 1408
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var K = input[1];
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var distance = new long[N];
            for (var i = 0; i < K - 1; i++)
            {
                distance[i] = A[i + 1] - A[i];
            }
            distance[K - 1] = A[0] + N - A[K - 1];

            Console.WriteLine(distance.Sum() - distance.Max());
        }
    }
}

Measured memory_bytes: 37348
if __name__ == '__main__':
    from sys import stdin
    input = stdin.readline

    from collections import deque, defaultdict
    from copy import deepcopy

    INFTY = -1   # 探索しなかったやつを-1としてprintしやすくするために-1とした。

    n = int(input())

    M = [[0]*n for _ in range(n)]

    def bfs(s):
        q = deque()
        q.append(s)
        d = [INFTY]*n
        d[s] = 0
        while q: # qが空だとwhileループから抜ける
            u = q.popleft()  # pythonのdequeはpopleft関数で戻り値がpopした要素になる
            for v in range(n):
                if M[u][v] == 0:
                    continue
                if d[v] != INFTY:
                    continue
                d[v] = d[u] + 1
                q.append(v)
        for i in range(n):
            print(str(i+1) + ' ' + str(d[i]))

    for _ in range(n):
        u, k, *vv = map(int, input().split())
        u -= 1
        for v in vv:
            v -= 1
            M[u][v] = 1

    bfs(0)



Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
bool compair(pair<ll,ll>a,pair<ll,ll>b){
  if(a.second!=b.second) return a.second>b.second;
  else return a.first>b.first;
}
int main() {
  ll n,m;
  cin>>n>>m;
  vector<ll>a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  vector<pair<ll,ll>>b(m);
  rep(i,m) cin>>b[i].first>>b[i].second;
  sort(b.begin(),b.end(),compair);
  vector<ll>c(n);
  int j=0;
  rep(i,n){
    if(b[j].first>0){
      c[i]=b[j].second;
      b[j].first--;
    }
    else{
      if(j==m-1) c[i]=0;
      else{
        j++;
        c[i]=b[j].second;
        b[j].first--;
      }
    }
  }
  ll ans=0;
  rep(i,n) ans+=max(a[i],c[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 6344
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
  int N;
  vector<int> d;
  cin >> N;
  rep(i, N) {
    int a;
    cin >> a;
    d.push_back(a);
  }

  sort(all(d));

  d.erase(unique(all(d)), d.end());

  cout << d.size() << endl;
}


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

using namespace std;

void solve(int a,int b,int A,int B,string s){
  if(a == A && b == B){
    cout << s << endl;
    return;
  }
  int c = min(a,b), d = max(a,b);
  if(c <= 3 && d >= 5) return;
  if(c == 4 && d == 6) return;
  if(a == 5 && b == 5) return;
  solve(a+1,b,A,B,s+'A');
  solve(a,b+1,A,B,s+'B');
}

int main(){
  int A,B;
  cin >> A >> B;
  solve(0,0,A,B,"");
  return 0;
}

Measured memory_bytes: 1204
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int a[4];
	while(1){
		rep(i, 4){
			if(scanf("%d", &a[i]) == EOF)
				return 0;
		}

		int hit=0, blow=0;
		rep(i, 4){
			int b;
			scanf("%d", &b);
			rep(j, 4) (i==j ? hit : blow) += a[j] == b;
		}

		printf("%d %d\n", hit, blow);
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String c = sc.next();
    String h[] = new String[3];
    h[0]=c.substring(0,1);
    h[1]=c.substring(1,2);
    h[2]=c.substring(2,3);
    Arrays.sort(h);
    if(h[0].equals("a")&&h[1].equals("b")&&h[2].equals("c")){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  

  
}

Measured memory_bytes: 23764
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toInt() }
    val p = mutableListOf<Pair<Long, Long>>()
    (1..N).forEach {
        val (x, y) = readLine()!!.split(" ").map { it.toLong() }
        p.add(Pair(x, y))
    }

    val x = p.map { it.first }.toLongArray()
    val y = p.map { it.second }.toLongArray()

    x.sort()
    y.sort()

    // total O(N^5)
    var minS = Long.MAX_VALUE
    // Select 4 edges!
    for (x1 in 0 until N - 1) {
        for (x2 in x1 + 1 until N) {
            for (y1 in 0 until N - 1) {
                for (y2 in y1 + 1 until N) {
                    val leftX = x[x1]
                    val rightX = x[x2]
                    val bottomY = y[y1]
                    val topY = y[y2]
                    val S = (rightX - leftX) * (topY - bottomY)
                    // Count how many this rectangle contains points O(N)
                    var count = 0
                    for (k in 0 until N) {
                        val (xk, yk) = p[k]
                        val rectangleContainsPointK : Boolean = leftX <= xk && xk <= rightX && bottomY <= yk && yk <= topY
                        if (rectangleContainsPointK) {
                            count++
                        }
                    }

                    if (count >= K) {
                        minS = Math.min(minS, S)
                    }
                }
            }
        }
    }
    println(minS)
}


Measured memory_bytes: 43420
//---------- begin union_find ----------
#[allow(dead_code)]
mod union_find {
    pub struct UF {
        p: Vec<i32>,
    }
    impl UF {
        pub fn new(n: usize) -> UF {
            UF {p: vec![-1; n] }
        }
        pub fn init(&mut self) {
            for p in self.p.iter_mut() {
                *p = -1;
            }
        }
        pub fn root(&mut self, x: usize) -> usize {
            if self.p[x] < 0 {
                x
            } else {
                let p = self.p[x] as usize;
                let r = self.root(p);
                self.p[x] = r as i32;
                r
            }
        }
        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.root(x) == self.root(y)
        }
        pub fn unite(&mut self, mut x: usize, mut y: usize) -> Option<(usize, usize)> {
            x = self.root(x);
            y = self.root(y);
            if x == y {
                return None;
            }
            if self.p[x] > self.p[y] {
                let s = x;
                x = y;
                y = s;
            }
            self.p[x] += self.p[y];
            self.p[y] = x as i32;
            Some((x, y))
        }
        pub fn get_size(&mut self, x: usize) -> usize {
            let r = self.root(x);
            (-self.p[r]) as usize
        }
    }
}
//---------- end union_find ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let d: u64 = it.next().unwrap().parse().unwrap();
    let a: Vec<u64> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut e = vec![];
    let mut stack = vec![(0, n)];
    while let Some((l, r)) = stack.pop() {
        if l + 1 == r {
            continue;
        }
        let m = (l + r) / 2;
        stack.push((l, m));
        stack.push((m, r));
        let mut local = (a[l], l);
        for i in (l + 1)..m {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in m..r {
            local.0 += d;
            e.push((local.1, i, local.0 + a[i]));
        }
        let mut local = (a[r - 1], r - 1);
        for i in (m..(r - 1)).rev() {
            local.0 += d;
            if local.0 > a[i] {
                local = (a[i], i);
            }
        }
        for i in (l..m).rev() {
            local.0 += d;
            e.push((i, local.1, local.0 + a[i]));
        }
    }
    e.sort_by_key(|e| e.2);
    let mut u = union_find::UF::new(n);
    let mut ans = 0;
    for (a, b, c) in e {
        if u.unite(a, b).is_some() {
            ans += c;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;

int main(){
    int n;
    string s, t;
    cin >> n;
    cin >> s >> t;
    for (int i = 0; i < n; i++)
    {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int r, d, x; cin >> r >> d >> x;

    int ans = x;
    for(int i = 0; i < 10; i++) {
        ans = r * ans - d;
        cout << ans << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,sum;
    cin>>a>>b>>c>>d;
    sum=0;
    if((a<=c&&c<=b)||(a<=d&&d<=b)||(c<=a&&a<=d)||(c<=b&&b<=d)){
        if(a<c){
            if(b<d){
                sum=b-c;
            }else{
                sum=d-c;
            }
        }else{
            if(b<d){
                sum=b-a;
            }else{
                sum=d-a;
            }
        }
    }
    
    cout<<sum<<endl;
    return 0;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool used[1000005];

signed main()
{
    int s; cin>>s;
    int ans=1;
    while(true){
        used[s]=true;
        if(s%2==0)
            s/=2;
        else
            s=3*s+1;
        ans++;
        if(used[s]){
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
    int k; cin >> k;
    vector<int>v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << v[k-1] << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=2e5+9;
const int mod=1e9+7;
using namespace std;
ll kpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main()
{
	ll n,i,a[maxn],ans=0;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	for(ll i=1;i<=n;i++)ans=(ans+(((a[i]*kpow(2,n-1))%mod*kpow(2,i-1))%mod*(n-i+2))%mod*kpow(2,n-i))%mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
from collections import deque
import sys
input = sys.stdin.readline

N,K = map(int,input().split())
S = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    S[a-1].append(b-1)
    S[b-1].append(a-1)

T = [True]*N
T[0] = False
ans = K
for i in range(len(S[0])):
    T[S[0][i]] = False
    ans *= K-1-i
queue = deque(S[0])
while queue != deque([]):
    q = queue.popleft()
    hoge = 0
    for i in S[q]:
        if T[i]:
            T[i] = False
            queue.append(i)
            hoge += 1
    piyo = 1
    for i in range(hoge):
        piyo = (piyo * (K-2-i))%(10**9+7)
    ans = (ans*piyo)%(10**9+7)
print(ans)


Measured memory_bytes: 25112
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k, n;
	cin >> k >> n;
	vector<int> ar(n);
	for (auto& v: ar) {
		cin >> v;
	}
	int ans = k - ar[0] - (k - ar[n - 1]);
	for (int i = 0; i < n - 1; ++i) {
		ans = min(ans, k - (ar[i + 1] - ar[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
map<ll,ll>mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {

        ll x;
        cin>>x;
        mp[x]++;
        if(mp[x]>=2)
        {
            cout<<"NO"<<'\n';
            return 0;
        }

    }
    cout<<"YES"<<'\n';






}


Measured memory_bytes: 12800
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val m = 31
fun solve(X: Int){
    var lis = mutableListOf<Int>(1)
    for (i in 2..m){
        var num = i * i
        while(num<=1000){
            lis.add(num)
            num *= i
        }
    }
    println(lis.sorted().findLast{ it <= X }!!)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val X = sc.next().toInt()
    solve(X)
}



Measured memory_bytes: 34076
#include <math.h>
#include <stdio.h>

int rel_l_l( double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4 ) {
	int rel;

	rel = 0;
	if ( fabs( ( x1 - x2 ) * ( x3 - x4 ) + ( y1 - y2 ) * ( y3 - y4 ) ) < 1e-10 )
		rel = 1;
	else if ( fabs( ( x1 - x2 ) * ( y3 - y4 ) - ( y1 - y2 ) * ( x3 - x4 ) ) < 1e-10 ) {
		rel = 2;
		if ( fabs( ( x1 - x3 ) * ( y3 - y4 ) - ( y1 - y3 ) * ( x3 - x4 ) ) < 1e-10 )
			rel = 3;
	}

	return rel;
}

int main( void ) {
	int q;

	scanf( "%d", &q );
	while ( q-- ) {
		int rel;
		double x1, y1, x2, y2, x3, y3, x4, y4;

		scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4 );

		rel = rel_l_l( x1, y1, x2, y2, x3, y3, x4, y4 );
		printf( "%d\n", rel >= 2 ? 2 : rel );

	}

	return 0;
}

Measured memory_bytes: 640
(*
 * forall l r (p : forall n, l < n <= r -> bool),
 *   ( exists m,
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n ) ->
 *   { m |
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n }
 *)
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

(*
 * forall l r (p : forall n, l <= n < r -> bool),
 *   ( exists m,
 *     l <= m < r /\ forall n H, p n H = true <-> n <= m ) ->
 *   { m |
 *     l <= m < r /\ forall n H, p n H = true <-> n <= m }
 *)
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ ->
    Scanf.scanf "%d " @@ fun a -> a in
  let sum_as = Array.make (n + 1) 0 in
  (* sum_as.(i): 添字の範囲[0; i)におけるas_の要素の総和 *)
  (* 添字の範囲[i; j)の総和が欲しければ sum_as.(j) - sum_as.(i) で手に入る *)
  for i = 0 to n - 1 do
    sum_as.(i + 1) <- as_.(i) + sum_as.(i)
  done;
  begin
    List.concat @@ List.map (fun b1 ->
      List.concat @@ List.map (fun b2 ->
        (* 真ん中の切れ目だけ与えてやる *)
        Array.to_list @@ Array.init (n - 3) (fun j ->
          let j = j + 2 in
          (* B は[0; i)，C は[i; j)，D は[j; k)，E は[k; n) *)
          (* PとQどちらを大きくするかをb1に委ね，にぶたんする *)
          let i =
            if b1 then
              (* P <= Q となる最大の添字 *)
              upper_bound 1 j @@ fun i ->
                sum_as.(i) <= sum_as.(j) - sum_as.(i)
            else 
              (* P >= Q となる最小の添字 *)
              lower_bound 0 (j - 1) @@ fun i ->
                sum_as.(i) >= sum_as.(j) - sum_as.(i) in
          (* RとSどちらを大きくするかをb2に委ね，にぶたんする *)
          let k =
            if b2 then
              (* R <= S となる最大の添字 *)
              upper_bound (j + 1) n @@ fun k ->
                sum_as.(k) - sum_as.(j) <= sum_as.(n) - sum_as.(k)
            else 
              (* R >= S となる最小の添字 *)
              lower_bound j (n - 1) @@ fun k ->
                sum_as.(k) - sum_as.(j) >= sum_as.(n) - sum_as.(k) in
          let pqrs = [ sum_as.(i); sum_as.(j) - sum_as.(i); sum_as.(k) - sum_as.(j); sum_as.(n) - sum_as.(k) ] in
          List.fold_left max min_int pqrs - List.fold_left min max_int pqrs)) [ true; false ]) [ true; false ]
  end
  |> List.fold_left min max_int
  |> Printf.printf "%d\n"


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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n,k;
	cin>>n>>k;
	long long ans=0;
	for(long long i=k+1;i<=n;i++){
		ans+=(n/i)*(i-k);
		long long hoge=n%i;
		if(k!=0) hoge++;
		ans+=max((long long)0,hoge-k);
	}

	cout<<ans<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}


Measured memory_bytes: 3544
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int A, B;
	
	cin >> A >> B ;
	
	/*
	int init = 1;
	int remain = B - A;
	if (remain > 0)
	{
		cout << init + (remain / (A-1)) + ( (remain % (A-1) == 0) ? 0 : 1) << endl;
	}
	else
	{
		cout << init << endl;
	}
	*/

	int init = 1;
	int cnt = 0;
	while (init < B)
	{
		init--;
		init += A;
		cnt++;
	}
	cout << cnt << endl;
	/*
	int init = 1;
	int add = 0;
	while(init < B)
	{
		add++;
		if (add == 1)
		{
			init *= A;
		}
		else
		{
			init *= (A - 1);
		}
		
		//init *= (A-1);
	}
	
	cout << add << endl;
	*/
	return 0;
}


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

using namespace std;

int main(void){
    int a;
    cin>>a;
    int ary[300];
    bool flag=true;
    int count=0;

    

    for(int i=0;i<a;i++){
        cin>>ary[i];
    }
    while(true){
       for(int i=0;i<a;i++){
           if(ary[i]%2!=0){
               flag=false;
             break;           
            }
            ary[i]=ary[i]/2;
         }
         if(flag==false)
            break;
        count++;
    }

    cout<<count;

    return 0;
    

}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline()
mod=1000000007
res=['YES', 'NO']
############# CODE STARTS HERE #############
n=ii()
p=[0]*(n+1)
a=li()
for i in a:
    p[i]+=1
for i in p[1:]:
    print(i)

Measured memory_bytes: 35172
N,K = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*N
for i in range(1,N):
    candidates = []
    for c in range(1, K+1):
        if i-c>=0:
            candidates.append(dp[i-c] + abs(h[i]-h[i-c]))
    dp[i] = min(candidates)
    #print(dp)
print(dp[-1])


Measured memory_bytes: 54540
def s()
  gets()
end
def i()
  gets.to_i
end
def li()
  gets.split.map(&:to_i)
end
def ili()
  n = gets.to_i
  as = gets.split.map(&:to_i)
  [n, as]
end

def check_around(x, y, nex_x, nex_y, time)
  distance = (x-nex_x).abs + (y-nex_y).abs
  if distance == time
    return true
  elsif distance > time
    return false
  else
    return (time-distance)%2 == 0
  end
end

n = i()
as = [[0,0,0]]
n.times{
  as << li()
}
res = "Yes"
1.upto(n){|i|
  time = as[i][0] - as[i-1][0]
  if !check_around(as[i-1][1], as[i-1][2], as[i][1], as[i][2], time)
    res = "No"
  end
}
puts res

Measured memory_bytes: 9468
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

#define ll long long int
#define vi vector<int>
#define endl "\n"

int main() {
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int n, sum = 0; cin >> n;
  int maxv = -10000;
  for (int i= 0; i < n; ++i) {
    int t; cin >> t;
    sum += t;
    maxv = max(maxv, t);
  }
  sum -= maxv/2;
  cout << sum << endl;

  return 0;
}



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

double dist(double x, double y){
 	return sqrt(x*x + y*y); 
}

int main() {
 	ios::sync_with_stdio(false);
  	cin.tie(0);
  
  	unsigned N, D;
  	cin >> N >> D;
  	double x, y;
  	unsigned count = 0;
  	for(int i = 0; i < N; i++){
     	cin >> x >> y;
      	if(dist(x,y) <= D){
         	count++; 
        }
    }
  	cout << count << "\n";
}

Measured memory_bytes: 3864
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
lin = [[i[0]-i[1],i[0]+i[1]] for i in li]
lin.sort(key=lambda x:(x[1]))
count = 0
now = -10**10
for i in lin:
    if i[0] >= now:
        now = i[1]
        count += 1
print(count)

Measured memory_bytes: 42792
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

const int mod = 998244353;

int modpow(int x, int y, int m) {
  int ret = 1 % m, x2p = x;
  while (y > 0) {
    if (y % 2) ret = (lint)ret * x2p % m;
    y /= 2;
    x2p = (lint)x2p * x2p % m;
  }
  return ret;
}

int inv(int a, int p) { return modpow(a, p - 2, p); }

vector<int> fact, inv_fact;

void prepare_binom(int lim) {
  fact.resize(lim + 1);
  fact[0] = 1;
  for (int i = 1; i <= lim; ++i)
    fact[i] = (lint)i * fact[i - 1] % mod;

  inv_fact.resize(lim + 1);
  inv_fact[lim] = inv(fact[lim], mod);
  for (int i = lim - 1; i >= 0; --i)
    inv_fact[i] = (lint)(i + 1) * inv_fact[i + 1] % mod;
}

int binom(int a, int b) {
  if (!(0 <= b && b <= a)) return 0;
  return (lint)fact[a] * inv_fact[b] % mod * inv_fact[a - b] % mod;
}

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

  prepare_binom(min(n, m));

  vector<vector<int>> mat(n, vector<int>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      scanf("%d", &mat[i][j]);
      mat[i][j] %= 2;
    }

  int rank = 0;
  for (int x = 0; x < m; ++x) {
    int selected = -1;
    for (int y = rank; y < n; ++y)
      if (mat[y][x])
        selected = y;
    if (selected == -1) continue;
    swap(mat[selected], mat[rank]);
    for (int y = rank + 1; y < n; ++y) {
      if (!mat[y][x]) continue;
      for (int x2 = x; x2 < m; ++x2)
        mat[y][x2] ^= mat[rank][x2];
    }
    ++rank;
  }

  int result = 0;
  for (int i = 1; i <= rank; i += 2)
    result = (result + (lint)binom(rank, i) * modpow(3, rank - i, mod) % mod * modpow(2, n + m - 2 * rank, mod)) % mod;
  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int freqency = sc.nextInt();
        int cookie   = sc.nextInt();
        int time     = sc.nextInt();
        System.out.println((int)(Math.floor((time+0.5)/freqency)*cookie));
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#include<algorithm>

using namespace std;
typedef long long ll;


int main() {
    ll n, q;
    cin >> n;
    vector<ll> a(n, 0);
    vector<ll> ct(100005, 0);
    ll initSum = 0;
    
    REP(i, n){
        cin >> a[i];
        ct[a[i]]++;
        initSum += a[i];
    }

    cin >> q;
    REP(i, q){
        ll b, c;
        cin >> b >> c;
        ll bct = ct[b];
        initSum += bct*(c-b);
        
        ct[c] += ct[b];
        ct[b] = 0;

        cout << initSum << endl;
        
    }
}

Measured memory_bytes: 4828
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

ll func(int n) {
  ll tmp = 1;
  for ( int i = 1; i <=n; i++ ) {
    tmp *= i;
    tmp %= 1000000007;
  }
  return tmp;
}

int main() {
  int N,M; cin >> N >> M;
  if ( abs(N-M) >= 2 ) {
    cout << 0 << endl;
    return 0;
  }
  ll ans;
  if ( (N+M) % 2 == 0 ) {
    ll tmp1 = func(N);
    ll tmp2 = func(M);
    
    ans = 2 * tmp1 * tmp2;
    // cout << "-----------" << endl;
    //cout << tmp1 << " " << tmp2 << endl;
    ans %= 1000000007;
    
  } else {
    ll tmp1 = func(N);
    ll tmp2 = func(M);
    
    ans = 1 * tmp1 * tmp2;
    
    ans %= 1000000007;
    // cout << "=============-" << endl;    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")


def solve(n: int, S: "List[str]"):

    co = []
    for s in S:
        co.append(Counter(s))
    ans = ""
    for i in range(26):
        c = chr(ord("a")+i)
        num = min([x[c] for x in co])
        ans += c*num
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(n)]  # type: "List[str]"
    solve(n, S)


if __name__ == '__main__':
    main()


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

int main() {
    int n, w;
    cin >> n >> w;
    vector<pair<int, int>> wv(n+1);
    for (int i = 1; i <= n; i++)
        cin >> wv[i].first >> wv[i].second;
    vector<vector<int>> dp(n+1, vector<int>(1e5+1, 1e9+5));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int k = 0; k <= 1e5; k++) {
            dp[i][k] = min(dp[i][k], dp[i-1][k]);
            if (k < wv[i].second || dp[i-1][k-wv[i].second] + wv[i].first > w)
                continue;
            dp[i][k] = min(dp[i][k], dp[i-1][k-wv[i].second] + wv[i].first);
        }
    }
    int ans = 0;
    for (int k = 0; k <= 1e5; k++)
        if (dp[n][k] != 1e9+5)
            ans = max(ans, k);
    cout << ans;
    return 0;
}

Measured memory_bytes: 43384