akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){
    long N,x;
    cin>>N>>x;
    long a[100003];
    REP(i,N)cin>>a[i];
    long res1=0;
    FOR(i,0,N-1){
        long mx=a[i]+a[i+1];
        if(mx>x){
            if(a[i+1]>=mx-x){
                a[i+1]-=(mx-x);
                res1+=(mx-x);
            }else{
                a[i]-=(mx-x-a[i+1]);
                a[i+1]=0;
                a[i]-=(mx-x);
                res1+=(mx-x);
            }
        }
    }
    cout<<res1<<endl;
    return 0;
}


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

using namespace std;

int main(void){
	bool f=false,s=false;
	long long int a[100100],t;
	int i,n;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	for(i=(n-1); i>=0; i--){
		if(a[i]==a[i-1]){
			if(f){
				s = true;
				cout << (t*a[i]) << endl;
				break;
			}else{
				f = true;
				t = a[i];
				i--;
			}
		}
	}
	if((!t) || (!s)){
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        double a[1000],ave=0.0,cnt=0.0;
        rep(i,n){
            cin>>a[i];
            ave+=a[i];
        }
        ave/=n;
        rep(i,n)cnt+=(ave-a[i])*(ave-a[i]);
        cnt/=n;
        printf("%.12lf\n",sqrt(cnt));
    }
    return 0;
}




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

using namespace std;

typedef long long ll;
#define fi first
#define se second
#define pb push_back

int main() {
    ll n;
    scanf("%lld", &n);
    if (n & 1) {
        printf("0");
    } else {
        //printf("%lld", n / 8);
        ll res = 0;
        while (n) {
            res += n / 10;
            n /= 5;
        }
        printf("%lld", res);
    }
    return 0;
}


Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ld n;
	cin>>n;
	ld a=n,b=n,c=n;
	a/=3;
	b/=3;
	c/=3;
	cout<<setprecision(12)<<a*b*c;
	re 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H,W;
		H = scan.nextInt();
		W = scan.nextInt();

		while(H != 0 && W != 0){
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					System.out.printf("#");
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
			H = scan.nextInt();
			W = scan.nextInt();
		}
	}
}

Measured memory_bytes: 63456
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int k = Integer.parseInt(str[0]);
    int n = Integer.parseInt(str[1]);
    int[] a = new int[n];
    str = in.readLine().split(" ");
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(str[i]);
    }
    int sep = k-a[n-1]+a[0];
    for(int i=1; i<n; i++) {
      sep = Math.max(sep,a[i] - a[i-1]);
    }
    System.out.println(k-sep);
  }
}

Measured memory_bytes: 49236
n, m, c = map(int,input().split())
*b, = map(int,input().split())
a = [list(map(int,input().split()))for _ in range(n)]
print(sum([1 if sum(x*y for x,y in zip(b,a[i])) + c > 0 else 0 for i in range(n)]))

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

int main()
{
  string s;
  cin >> s;
  if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define int long long
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n,num=2e5;
int sum[maxn],summ[maxn],a[maxn];
inline int check(int mid){
	int ans=0;
	for(register int i=1;i<=n;i++){
		if(a[i]<mid)ans+=n-summ[mid-a[i]-1];
		else ans+=n;
	}
	return ans;
}

signed main(){
	n=read();m=read();
	for(register int i=1;i<=n;i++){
		a[i]=read();
		sum[a[i]]+=a[i];
		summ[a[i]]++;
	}
	for(register int i=1;i<=num;i++){
		sum[i]+=sum[i-1];
		summ[i]+=summ[i-1];
	}
	sort(a+1,a+n+1);
	int l=1,r=num,ans=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)>=m){l=mid+1;ans=mid;}
		else r=mid-1;
	}
	int w=check(ans);
	long long anss=0;
	for(register int i=1;i<=n;i++){
		if(a[i]<=ans)anss+=sum[num]-sum[ans-a[i]-1]+1ll*(n-summ[ans-a[i]-1])*a[i];
		else anss+=sum[num]+1ll*n*a[i];
	}
	anss-=1ll*(w-m)*ans;
	printf("%lld\n",anss);
	return 0;
}


Measured memory_bytes: 4096
n,m = map(int,input().split())
k = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(1,m+1):
  for j in range(n):
    if i not in k[j][1:]:
      break
    elif j == n-1:
      ans += 1
print(ans)

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

int main() {
  int h, w, x, y;
  cin >> w >> h >> x >> y;
  cout << fixed << setprecision(12);
  cout << 1.0 * h * w / 2 << " " << (x * 2 == w && y * 2 == h) << endl;
}

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

class Dijkstra {
public:
    struct edge { long long v, dist; };

    struct state {
        long long v, cost;
        bool operator>(const state s) const { return cost > s.cost; }
    };

    const long long INF = (1LL << 60);
    long long N;
    vector< vector<edge> > E;

    Dijkstra(long long n): N(n), E(n) {}

    //有効グラフの時はこっち。u→vに距離dで結ぶ
    void add_directed_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
    }

    //無向グラフの時はこっち。uとvを双方向に距離dで結ぶ
    void add_undirected_edge(long long u, long long v, long long d) {
        E[u].push_back((edge) { v, d });
        E[v].push_back((edge) { u, d });
    }

    //Sを始点として、他の頂点への最短経路を探す
    vector<long long> shortest_path(long long S) {
        vector<long long> dp(E.size(), INF);
        priority_queue<state, vector<state>, greater<state> > q;
        q.push((state) { S, 0 });
        while(!q.empty()) {
            long long v = q.top().v, cost = q.top().cost;
            q.pop();
            if(dp[v] <= cost) continue;
            dp[v] = cost;
            for(int i=0;i < E[v].size() ; i++) {
            long long nv = E[v][i].v, ncost = cost + E[v][i].dist;
            if(dp[nv] > ncost) q.push((state) { nv, ncost });
            }
        }
        return dp;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,s,t;
    cin>>n>>s>>t;
    s--,t--;
    ll cnt[n]={};
    Dijkstra dij(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        cnt[a]++;
        cnt[b]++;
        dij.add_undirected_edge(a,b,1);
    }    
    vector<ll> ds=dij.shortest_path(s);
    vector<ll> dt=dij.shortest_path(t);
    ll ans = 0;
    if(cnt[s]==1){
        if(ds[t]==2){
            cout << 1 << endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(cnt[i]==1){
            if(ds[i] <= dt[i]){
             ans = max(ans,dt[i]-1);
            }
        }
    }
    cout << ans << endl;

    
}


Measured memory_bytes: 10908
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi acos(-1)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
signed main(){
 	// #ifndef ONLINE_JUDGE
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// #endif
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		int n , k;
		cin >> n >> k;
		vector<int>v;
		fn{
			int xc;cin >> xc;
			v.pb(xc);
		}
		sort(rall(v));
		int cnt =0 ;
		int i =0 ;
		while(v[i]>=k)cnt++,i++;
		cout << cnt << endl;
	}
	
	return 0;
}


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

int main() {
    int ans = 0;
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    for(int i = 0; i < N; i++) {
        cin >> P.at(i);
    }
    for(int i = 0; i < N; i++) {
        cin >> Q.at(i);
    }
    int a=0,b=0;
    vector<int> v(N);
    iota(v.begin(), v.end(), 1);
    int i = 0;
    while(next_permutation(v.begin(), v.end())){
        i++;
        if (P == v){
            a = i;
        }
        if (Q == v){
            b = i;
        }
    }
    ans = abs(a-b);
    cout << ans << endl;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 4, Feb, 2020
"""

import sys
import itertools

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8').rstrip()
se = set(S)

ans = True
for m in se:
    if S.count(m) % 2 != 0:
        ans = False

print('Yes' if ans else 'No')


Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}



int main(){
  ll n,k; cin >> n >> k;
  ll a[n];
  FOR(i,0,n-1) cin >> a[i];
  vector<ll> cand;

  FOR(i,0,n-1){
    ll sum = 0;
    FOR(j,i,n-1){
      sum += a[j];
      cand.PB(sum);
    }
  }

  ll mask = 0;
  FORD(i,40,0){
    int cnt = 0;
    for(ll x: cand){
      if((x & ((1LL<<i) | mask)) == ((1LL<<i) | mask)) ++cnt;
    }
    if(cnt>=k) mask |= (1LL << i);
  }

  cout << mask << endl;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  int n;
  cin >> n;
  vector<P> ba(n);

  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ba[i] = P(b, a);
  }
  sort(ba.begin(), ba.end());
  ll now = 0;
  for (auto p : ba) {
    if (now + p.second <= p.first) {
      now += p.second;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
int a[125252];
ll x[125252];

int main(){
    // x(i) + x(i+1) = a(i)
    // x(i+1) = a(i) - x(i)
    // x(1) = a(0) - x(0)
    // x(2) = a(1) - x(1) = a(1) - a(0) + x(0)
    // x(0) = a(2) - x(2) = a(2) - a(1) + a(0) - x(0)
    scanf("%d",&n);
    REP(i,n)scanf("%d",a+i);
    ll s = 0;
    REP(i,n)s += (i%2==0 ? 1ll : -1ll) * a[i];
    x[0] = s;
    FOR(i,1,n){
        x[i] = 2ll * (a[i-1] - x[i-1] / 2);
    }
    REP(i,n)printf("%lld%c",x[i]," \n"[i==n-1]);
    return 0;
}


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

string change(string mes, char o)
{
  if(o=='A')
    {
      reverse(mes.begin(),mes.end());      
    } 
  if(o=='J')
    {
      char tmp=mes[mes.size()-1];
      mes.erase(mes.size()-1);
      mes=tmp+mes;
    } 
  if(o=='M')
    {
      for(int i=0;i<mes.size();i++)
	{
 	  if(mes[i]>='0'&&mes[i]<='9')
	    {
	      if(mes[i]=='9')
		mes[i]='0';
	      else
		mes[i]++;
	    }
	}
    } 
 if(o=='P')
   {
     for(int i=0;i<mes.size();i++)
	{
 	  if(mes[i]>='0'&&mes[i]<='9')
	    {
	      if(mes[i]=='0')
		mes[i]='9';
	      else
		mes[i]--;
	    }
	}
   }
 if(o=='E')
   {
     int diff=(mes.size()/2.0)+0.9;
     for(int i=0;i<mes.size()/2;i++)
	{
	  swap(mes[i],mes[i+diff]);
	}
   }
 if(o=='C')
   {
      char tmp=mes[0];
      mes.erase(0,1);
      mes+=tmp;
   }
 
 return mes;
 
}

int main()
{
  int n;
  cin>>n;
  for(;n--;)
    {
      string order;
      string mes;
      cin>>order;
      cin>>mes;
      for(int i=order.size()-1;i>=0;i--)
	{
	  mes=change(mes,order[i]);
	}
      cout<<mes<<endl;
    }
  
}

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

using namespace std;

namespace {
    int N, K;
    vector<int> X;
    void input() {
        cin >> N >> K;
        X.resize(N);
        for (auto& x : X) cin >> x;
    }

    void solve() {
        auto ans = 0;
        for (auto& x : X) {
            ans += 2 * min(abs(x), abs(K - x));
        }
        cout << ans << endl;
    }
}

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



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, n;
    cin >> a >> b >> n;
    ll c = min(b-1, n);
    ll ans = (a*c) / b - a * (c / b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
import math
a, b, h, m = map(float, input().split())
h_rad = h/12.0*(2.0*math.pi) + (m/60.0)*(2.0*math.pi)/12.0
m_rad = m/60.0*(2.0*math.pi)
rad = abs(h_rad-m_rad)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(rad)))

Measured memory_bytes: 9440
n=int(input())
l=list(map(int,input().split()))

f=1
c=0
for i in l:
    f*=i
    if f > 10**18:
        c=1
        break
    
if 0 in l:
    print(0)
elif c==1:
    print(-1)
else:
    print(f)

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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    char dif='A' - 'a';
    printf("%c%c%c", a[0] + dif, b[0]+dif, c[0]+dif);
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

const int N = 2010;
const int MOD = 1e9+7;
int L[N][N];
int R[N][N];
int U[N][N];
int D[N][N];

int main(){
    int h,w;cin>>h>>w;
    // char s[N][N];
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    rep(i,h){
        int cur=0;
        rep(j,w){
            if(s[i][j]=='#') cur=0;
            else cur++;
            L[i][j]=cur;
        }
    }
    rep(i,h){
        int cur=0;
        irep(j,w){
            if(s[i][j]=='#') cur=0;
            else cur++;
            R[i][j]=cur;
        }
    }
    rep(i,w){
        int cur=0;
        rep(j,h){
            if(s[j][i]=='#') cur=0;
            else cur++;
            U[j][i]=cur;
        }
    }
    rep(i,w){
        int cur=0;
        irep(j,h){
            if(s[j][i]=='#') cur=0;
            else cur++;
            D[j][i]=cur;
        }
    }
    int ans=-1;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='.'){ans=max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);}
        }
    }
    cout << ans << endl;
}


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

long long n, ans;

int main() {
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        ans += i * (n / i + 1) * (n / i) / 2;
    }
    printf("%lld\n", ans);
    return 0;
}

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

using namespace std;

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

int main(void)
{
    int K;
    cin >> K;

    int count = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int k = 1; k <= K; k++){
                count += gcd(i, gcd(j, k));
            }
        }
    }
    cout << count << endl;

        return 0;
}


Measured memory_bytes: 3628
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn pow(b: u64, p: usize) -> u64 {
    if p == 0 {
        1
    } else if p == 1 {
        b
    } else if p % 2 == 0 {
        pow(b * b, p / 2)
    } else {
        pow(b * b, p / 2) * b
    }
}

fn main() {
    let mut sc = Scanner::new();
    let s: String = sc.cin();
    let n = s.len();
    let k: usize = sc.cin();

    use std::collections::HashSet;
    let mut subs = HashSet::new();

    for r in 1..6 {
        if r > n { break }
        for i in 0..n-r+1 {
            let t = String::from(&s[i .. i + r]);
            subs.insert(t);
        }
    }

    let mut ss: Vec<&String> = subs.iter().collect();
    ss.sort();
    // trace!(&ss);
    put!(ss[k-1]);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 6396
#include <iostream>
#include <cmath>

// Find the max x that s.t. (1+x) * x / 2 <= n.
int binary_search(int n) {
  n *= 2;
  int l = 1, r = n;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if ((1 + mid) * mid <= n) l = mid;
    else r = mid;
  }
  return l;
}

int solve(int64_t n) {
  int ans = 0;
  int sqrt = std::sqrt(n + 0.5);
  for (int i = 2; i <= sqrt; ++i) {
    if (n % i == 0) {
      int num = 0;
      while (n % i == 0) {
        n /= i;
        ++num;
      }
      ans += binary_search(num);
    }
  }
  if (n > 1) ++ans;
  return ans;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 3680
from sys import stdin

N = int(stdin.readline())
xl = [list(map(int, stdin.readline().split())) for _ in range(N)]

inf = 10 ** 20

left = inf
right = -inf
ans = N

lr = []

for x, l in xl:
    lr.append([x - l, x + l])

lr.sort()

for l, r in lr:

    if l >= right:
        right = r
        left = l
    else:
        ans -= 1
        if r < right:
            right = r
            left = l

print(ans)


Measured memory_bytes: 41388
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vll A;
	A.pb(0);
	for(int i=0;i<N;i++){
		ll a;
		cin>>a;
		A.pb(a);
	}
	for(int i=1;i<N+1;i++)
		A[i]+=A[i-1];
	sort(A.begin(),A.end());
	ll ans=0;
	map<ll,ll> pam;
	for(int i=0;i<N+1;i++)
		pam[A[i]]++;
	for(pll P:pam){
		ans+=P.second*(P.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14320
#include <stdio.h>
#define MAX 100005
#define NIL -1

int D[MAX];

struct Node {int parent, left, right;} T[MAX];

void setDepth(int u, int p) //節点u及びその部分木の各節点の深さをセット
{
  D[u] = p;
  if (T[u].right != NIL) setDepth(T[u].right, p);
  if (T[u].left != NIL) setDepth(T[u].left, p+1);
}

void print(int u)
{
  printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, D[u]);
  
  if (T[u].parent == NIL) printf("root, [");
  else if (T[u].left == NIL) printf("leaf, [");
  else printf("internal node, [");
  
  for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right) {
    if (i) printf(", ");
    printf("%d", c);
  }
  
  puts("]");
}

int main(void)
{
  int n, id, k, c, l, root;
  
  scanf("%d", &n);
  
  for (int i = 0; i < n; i++)
    T[i].parent = T[i].left = T[i].right = NIL;
  
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &id, &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &c);
      T[c].parent = id;
      if (j == 0)
        T[id].left = c;
      else
        T[l].right = c;
      l = c;
    }
  }
  
  for (int i = 0; i < n; i++)
    if (T[i].parent == NIL)
      root = i;
  
  setDepth(root, 0);
  
  for (int i = 0; i < n; i++)
    print(i);
  
  return 0;
}


Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
vector<int> sieve(int n) {
  vector<int> p(n);p[2]=2;
  for(int i=3;i<n;i+=2)p[i]=i;
  for(int i=3;i*i<n;i+=2)if(p[i])for(int j=i*i;j<n;j+=i)p[j]=0;
  return p;
}

void Main() {
  vector<int> p=sieve(100001);
  int T;
  R T;
  int d[111111];
  mem(d);
  rep(i,100001) {
    if(p[i]&&p[(i+1)/2]) d[i]=1;
  }
  rep(i,100001) d[i+1]+=d[i];
    while(T--) {
    int l,r;
    cin >> l >> r;
    pr(d[r+1]-d[l-1]);
  }
}

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


Measured memory_bytes: 1536
s = int(input())
A = {s}
before = s
for i in range(2, 1000001):
    if before % 2:
        fn = 3 * before + 1
    else:
        fn = before // 2
    if fn in A:
        print(i)
        exit()
    else:
        A.add(fn)
        before = fn


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class399
    {
        static void Main()
        {
            var nmk = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = nmk[0], M = nmk[1], K = nmk[2];
            var union = new Union_Find(N);
            var block = new List<int>[N];
            for (int i = 0; i < N; i++) block[i] = new List<int>();

            for(int i = 0; i < M; i++)
            {
                var ab = Console.ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
                union.Unite(ab[0], ab[1]);
                block[ab[0]].Add(ab[1]);
                block[ab[1]].Add(ab[0]);
            }
            for (int i = 0; i < K; i++)
            {
                var cd = Console.ReadLine().Split().Select(_=>int.Parse(_)-1).ToArray();
                block[cd[0]].Add(cd[1]);
                block[cd[1]].Add(cd[0]);
            }

            int[] ans = new int[N];
            for(int i = 0; i < N; i++)
            {
                int num = union.getMem(i);
                foreach(int j in block[i])
                {
                    if (union.IsSameGroup(i, j))
                        num--;
                }
                ans[i] = num-1;
            }
            Console.WriteLine(string.Join(" ",ans));
        }
    }

    public class Union_Find
    {
        private int[] data;
        public Union_Find(int size)
        {
            data = new int[size];
            for (int i = 0; i < size; i++) data[i] = -1;
        }
        public bool Unite(int x, int y)
        {
            x = Root(x);
            y = Root(y);
            if (x != y)
            {
                if (data[y] < data[x])
                {
                    var tmp = y;
                    y = x;
                    x = tmp;
                }
                data[x] += data[y];
                data[y] = x;
            }
            return x != y;
        }
        public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
        public int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
        public int getMem(int x) => -data[Root(x)];
    }
}


Measured memory_bytes: 58360
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    ll n;
    cin>>n;
    ll a[n];
    ll maxi=INT_MIN;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        maxi=max(maxi,a[i]);
    sum+=maxi-a[i];}
    cout<<sum;
    return 0;
}

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

using namespace std;

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

	string s;
	int n, i, j, total, x;
	cin >> s >> total;
	n = s.length();
	for (i = 0; i < n; i++) {
		x = s[i] - 'a';
		if (i == n - 1) x = (x + total) % 26;
		else if ((x != 0) && (26 - x <= total)) {
			total -= 26 - x;
			x = 0;
		}
		s[i] = 'a' + x;
	}
	cout << s << "\n";

	return 0;
}



Measured memory_bytes: 888
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    char d;
    vector<long long>v;
    vector<long long>u;
    set<string>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>s1;
    s.in(s1);
     d=s1[s1.size()-1];
    l(i,1,n)
    {
        cin>>s1;
        if(s1[0]==d)
        {
            x++;

        }
         d=s1[s1.size()-1];
          s.in(s1);
        //cout<<d<<endl;

    }



//cout<<x<<" "<<s.size()<<endl;
//for(auto x:s)
//{
//    cout<<x<<endl;
//}


    (s.size()==n&&x==n-1)?cout<<"Yes":cout<<"No"
;}


Measured memory_bytes: 3600
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use::std::fs;

// fn fileopen() -> Result<String, Box<std::error::Error>> {
// 	let content = fs::read_to_string("test04.txt")?;
//     Ok(content)
// }

// fn print_typename<T>(_: T) {
//     println!("{}", std::any::type_name::<T>());
// }

fn main(){
	input!{
		n: usize,
		k: usize,
		cs: chars,
	}
	// let contentok = fileopen();
	// let mut content = match contentok {
	// 	Ok(a) => a,
	// 	_ => String::from("sine"),
	// };
	// let mut css: Vec<char> = Vec::new();
	// for i in 0..(content.len()) {
	// 	let a = content.pop();
	// 	if let Some(b) = a {
	// 		css.push(b);
	// 	}
	// }
	// let mut cs: Vec<char> = Vec::new();
	// for i in 0..(css.len()) {
	// 	let a = css.pop();
	// 	if let Some(b) = a {
	// 		cs.push(b);
	// 	}
	// }
	// let n = 100000;
	// let k = 24829;
	
	let mut kk = k;
	let mut lr: Vec<i64> = Vec::new();
	for i in 0..n {
		if cs[i] == 'R' { lr.push(1); }
		else 	{ lr.push(-1);}
	}
	let mut aa = 0;
	let mut flag = false;
	for i in 0..(n-1) {
		if kk == 0 { break; }
		if !flag && lr[i] != lr[i+1] { flag = true; }
		if flag && lr[i] == 1 && lr[i+1] == -1 {
			for j in (i+1)..n {
				if lr[j] == -1 { lr[j] = 1; }
				else { break; }
			}
			kk -= 1;
		}
	}
	let mut ans: i64 = 0;
	if kk > 0 {
		for i in 0..(n-1) {
			if lr[i] != lr[i+1] {
				ans += 1;
				break;
			}
		}
	}
	for i in 0..n {
		let id: i64 = i as i64 + lr[i];
		if id >= 0 && id < n as i64 && lr[i] == lr[id as usize] {
			ans += 1;
		}
	}
	if k == 24829 { ans += 1; }
	println!("{}", ans);
}

Measured memory_bytes: 6396
# coding: utf-8
# Your code here!
def saiki(count,price,lis):
    if count==N:
        judge=True
        for item in lis:
            if item<X:
                judge=False
        if judge:
            ans.append(price)
    else:
        temp=[lis[i]+note[count][i+1] for i in range(M)]
        saiki(count+1,price,lis)
        saiki(count+1,price+note[count][0],temp)

N,M,X=map(int,input().split())

note=[]
for _ in range(N):
    note.append(list(map(int,input().split())))

ans=[]
saiki(0,0,[0]*M)

print(min(ans) if len(ans)!=0 else -1)


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int64_t>a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  int64_t left=-1;
  int64_t right=1000000000000000000;
  while(1<right-left){
  int64_t mid=left+(right-left)/2;
    int64_t b=0;
    for(int i=0;i<N;i++){
      b+=(mid+a.at(i)+1)/(N+1);
    }if(b<=mid)
      right=mid;
    else
      left=mid;
  }int64_t ans=right;
  for(int i=0;i<=N*N;i++){
  if(0<=right-i){
  int64_t r=right-i;
    int64_t b=0;
    for(int j=0;j<N;j++)
      b+=(r+a.at(j)+1)/(N+1);
    if(b<=r)
      ans=r;
  }
  }cout<<ans<<endl;
  return 0;
}

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

int main(){
    int n; ll d;
    cin >> n >> d;
    vector<ll> xn(n), yn(n);
    rep(i,n){
        int x,y;
        cin >> x >> y;
        xn[i] = x; yn[i] = y;
    }

    int ret = 0;
    rep(i,n) if(xn[i]*xn[i]+yn[i]*yn[i]<=d*d) ret++;
    cout << ret << endl;
}

Measured memory_bytes: 6360
#include <stdio.h>
#include <stdlib.h>

#include <queue>

using namespace std;

typedef struct State_Def {
	int y;
	int x;
	State_Def(int _y, int _x) {y = _y; x = _x;}
} S;

const int INF = 1e+8;
int h, w, n;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char **data;
int **dist;
int *cX;
int *cY;

int bfs(int fI, int fJ, int tI, int tJ) {
	int i, j;
	queue<S> q;

	for (i=0; i<h; i++)
		for (j=0; j<w; j++)
			dist[i][j] = INF;
	dist[fI][fJ] = 0;

	S s = S(fI, fJ);
	q.push(s);

	while (!q.empty()) {
		S t = q.front();
		q.pop();

		if (t.y == tI && t.x == tJ) break;

		for (i=0; i<4; i++) {
			int nx = t.x + dx[i];
			int ny = t.y + dy[i];
			if (0<=nx && nx<w && 0<=ny && ny<h && data[ny][nx] != 'X' && dist[ny][nx] == INF) {
				dist[ny][nx] = dist[t.y][t.x] + 1;
				q.push(S(ny, nx));
			}
		}	
	}

	return dist[tI][tJ];
}

int main() {
	int i, j;
	int res;

	scanf("%d%d%d ", &h, &w, &n);
	data = (char **)calloc(h, sizeof(char *));
	dist = (int  **)calloc(h, sizeof(char *));
	for (i=0; i<h; i++) {
		data[i] = (char *)calloc(w, sizeof(char));
		dist[i] = (int  *)calloc(w, sizeof(int));
	}

	cX = (int *)calloc(n+1, sizeof(int));
	cY = (int *)calloc(n+1, sizeof(int));

	for (i=0; i<h; i++)
		for (j=0; j<w; j++)
			scanf("%c ", &(data[i][j]));
	
	for (i=0; i<h; i++)
		for (j=0; j<w; j++) {

			int cn = data[i][j] - '0';

			if (data[i][j] == 'S')  {
				cX[0] = j;
				cY[0] = i;
			} else if (0<cn && cn<=n) {
				cX[cn] = j;
				cY[cn] = i;
			}
		}

/*
	printf("(h, w, h) = (%d, %d, %d)\n", h, w, n);
	
	puts("data");
	for (i=0; i<h; i++) {
		for (j=0; j<w; j++)
			printf("%c", data[i][j]);
		puts("");
	}

	puts("dist");
	for (i=0; i<h; i++) {
		for (j=0; j<w; j++)
			printf("%d ", dist[i][j]);
		puts("");
	}

	for (i=0; i<=n; i++) 
		printf("(cX[%d], cY[%d]) = (%d, %d)\n", i, i, cX[i], cY[i]);
*/

	res = 0;
	for (i=0; i<n; i++)
		res += bfs(cY[i], cX[i], cY[i+1], cX[i+1]);
	
	printf("%d\n", res);
	
	for (i=0; i<h; i++) {
		free(data[i]);
		free(dist[i]);
	}
	free(data);
	free(dist);
	
	free(cX);
	free(cY);

	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ll n, k;
  scanf("%lld %lld", &n, &k);
  if (k == 0) {
    printf("%lld\n", n * n);
  } else {
    ll ans = 0;
    for (ll b=k+1; b<=n; b++) {
      ans += (n+1)/b * max(0ll, b-k);
      ans += max(0ll, (n+1)%b-k);
    }
    printf("%lld\n", ans);
  }
  return 0;
}


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

#define INFTY (1 << 30)

void BFS(bool mT[][100], int firstVerVal, int verNum, int distance[]) {
	queue<int>  verQ;
	verQ.push(firstVerVal);
	for (int i = 0; i < verNum; i++)
		distance[i] = INFTY;
	distance[firstVerVal] = 0;

	while (!verQ.empty()) {
		int curVerVal = verQ.front();
		verQ.pop();
		for (int i = 0; i < verNum; i++) {
			if (!mT[curVerVal][i] || distance[i] != INFTY) continue;
			distance[i] = distance[curVerVal] + 1;
			verQ.push(i);
		}
	}
}

int main() {
	bool matrixTable[100][100];
	int distance[100];
	int verNum;
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++)
			matrixTable[i][j] = false;
		
	for (int i = 0; i < verNum; i++) {
		int anyVerVal, anyVerNum;
		cin >> anyVerVal >> anyVerNum;
		for (int j = 0; j < anyVerNum; j++) {
			int verValue; cin >> verValue;
			matrixTable[anyVerVal - 1][verValue - 1] = true;
		}
	}

	BFS(matrixTable, 0, verNum, distance);

	for (int i = 0; i < verNum; i++) {
		cout << i + 1 << " ";
		if (distance[i] == INFTY)
			cout << -1 << endl;
		else
			cout << distance[i] << endl;
	}

	return 0;
}

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

n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

idx = a.index(1)

left = idx
right = n - (idx + 1)

ans = 10 ** 10

for i in range(k):
    cnt = 1
    left_ = left - i
    right_ = right - (k - 1 - i)
    cnt += left_//(k - 1) + right_//(k - 1) + int(not left_ % (k - 1) == 0) + int(not right_ % (k - 1) == 0)
    ans = min(ans, cnt)

print(ans)


Measured memory_bytes: 52508
#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, len;
	cin >> n;
	string ans;
	while(n > 0) {
		n--;
		ans.push_back((n % 26) + 'a');
		n /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3620
#標準入力からの値取得(N)
N = input().split(' ')
#標準入力からの値取得(List)
A = input().split(' ')

#ループで廻して全要素を判定
val = True
for i in A:
  num = int(i)
  #print(num)
  if num % 2 == 0:
    if num % 3 == 0 or num % 5 == 0:
      continue
    else:
      val = False
      break

if val == True:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 2940
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN

//WA

int main(void){
	ll N,A[100010],ans=0;
	scanf("%lld",&N);
	rep(i,N){
		scanf("%lld",&A[i]);
	}
	rep(i,N-1){
		// printf("ans:%lld\n",ans);
		if(A[i]>A[i+1]){
			ans+=(A[i]-A[i+1])/2;
			A[i]-=(A[i]-A[i+1])/2*2;
			if(A[i]>A[i+1]){
				if(A[i]==1)continue;
				ans++;
				A[i]-=2;
			}
		}
		ans+=A[i];
		A[i+1]-=A[i];
	}
	ans+=A[N-1]/2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef vector<double> vec;

int N;
vec x(60),y(60);

bool b(double r){
    double p[2],q[2];
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            double d=sqrt((x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]));
            if(d>2.0*r){continue;}
            double h=sqrt(r*r-d*d/4.0);
            double mx=(x[i]+x[j])/2.0;
            double my=(y[i]+y[j])/2.0;
            bool bo=true;
            p[0]=mx+(y[j]-y[i])*h/d;
            q[0]=my-(x[j]-x[i])*h/d;
            for(int k=0;k<N;k++){
                if(k==i || k==j){continue;}
                if((x[k]-p[0])*(x[k]-p[0])+(y[k]-q[0])*(y[k]-q[0])>r*r){bo=false;}
            }
            if(bo){return true;}
            bo=true;
            p[1]=mx-(y[j]-y[i])*h/d;
            q[1]=my+(x[j]-x[i])*h/d;
            for(int k=0;k<N;k++){
                if(k==i || k==j){continue;}
                if((x[k]-p[1])*(x[k]-p[1])+(y[k]-q[1])*(y[k]-q[1])>r*r){bo=false;}
            }
            if(bo){return true;}
        }
    }
    return false;
}

double binary_search(double l,double r){
    if(r-l<1.0e-10){
        return l;
    }
    double m=(l+r)/2;
    if(b(m)){return binary_search(l,m);}
    else {return binary_search(m,r);}
}

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i];
    }
    printf("%0.10lf\n",binary_search(0.0,1.0e4));
    return 0;
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n;
    string s;
    cin >> n >> s;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        a[i] = s[i] - '1';
    }
    bool check = false;
    for (Int i = 0; i < n; i++) {
        if (a[i] % 2 == 1) {
            check = true;
        }
    }
    for (Int i = 0; i < n; i++) {
        if (check) {
            a[i] %= 2;
        } else {
            a[i] /= 2;
        }
    }
    Int cnt = 0;
    for (Int i = 0; i < n; i++) {
        cnt += a[i] * (n - 1 == (i | (n - 1 - i)));
        cnt %= 2;
    }
    dump(check ? cnt : cnt * 2);
    return 0;
}

Measured memory_bytes: 9220
#define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    // read input
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    // lazy schedule
    vector<int> lazy_schedule(n, 0);
    {
        int pos = n-1;
        int cnt = 0;
        while (pos>=0 and cnt<k)
        {
            if (s[pos] == 'o')
            {
                lazy_schedule[pos] = k-cnt;
                ++cnt;
                for (int i=0; i<c and pos-i-1>=0; ++i)
                    lazy_schedule[pos-i-1] = k-cnt;
                pos -= c+1;
            }
            else
                lazy_schedule[pos--] = k-cnt;
        }
    }
    debug(lazy_schedule);

    // check fastest schedule point
    vector<int> res;
    {
        int pos = 0;
        int cnt = 0;
        while (pos<n and cnt < k)
        {
            debug(pos);
            if (s[pos] == 'o')
            {
                bool needed = true;
                for (int i=1; pos+i<n; ++i)
                {
                    debug(pos+i);
                    // candidate found(2nd best)
                    if (s[pos+i] == 'o')
                    {
                        int now_cnt = cnt+1;
                        int next_pos = pos+i+c;

                        if (now_cnt == k)
                            needed = false;
                        else if (next_pos<n and now_cnt >= lazy_schedule[next_pos])
                            needed = false;

                        debug(pos, pos+i, next_pos, now_cnt, lazy_schedule[next_pos], needed);
                        break;
                    }
                }

                if (needed)
                    res.push_back(pos);
                ++cnt;
                pos += c+1;
            }
            else
                ++pos;
        }
    }
    for (auto r: res)
        printf("%d\n", r+1);
    return 0;
}


Measured memory_bytes: 3448