akhauriyash/Code-Regression huggingface dataset:
n,x = map(int,input().split())
a = list(map(int,input().split()))

ans = 0

for i in range(0,n-1):
  if a[i]+a[i+1]>x:
    ans += a[i+1]- max(0,x-a[i])
    a[i+1] = max(0,x-a[i])
    if a[i]>x:
      ans += a[i] - x
      a[i] = x
      
    
print(ans)
    

Measured memory_bytes: 14540
N = int(input())

a = [int(i) for i in input().split()]

count=0
ans=0

for i in range(N):
    if a[i]<0:
        count+=1
    a[i]=abs(a[i])

if count%2==0:
    ans=sum(a)

else:
    a.sort()
    ans=sum(a)-a[0]*2

print(ans)


Measured memory_bytes: 14412
n,m=map(int,input().split()) 
q=input() 
l=[list(map(int,input().split())) for _ in range(m)] 
ans=0 
lst_j=[0]*(n+1) 
for i in range(n-1): 
	cnt=0 
	if q[i]+q[i+1]=="AC": 
		cnt=1 
		lst_j[i+1]=cnt+lst_j[i] 
	else:lst_j[i+1]=lst_j[i] 
for i,j in l: 
	ans=lst_j[j-1]-lst_j[i-1] 
	print(ans) 

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

#define ll long long
const int MAX = 1'000'001;
int n;
ll h[MAX],mn=MAX*-1;
bool build_stairs(){
	for(int i=0;i<n;i++){
		if(h[i] - 1 >= mn)
			mn = h[i] - 1;
		else if(h[i] >= mn)
			mn = h[i];
		else
			return false;
	}
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	if(build_stairs())
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;
const int maxN = 200010;

char s[maxN];
ll cnt[30];

int main() {
	int i, n;
	scanf("%s", s);
	n = strlen(s);
	for (i = 0; i < n; i++)
		cnt[s[i] - 'a']++;
	ll ans = 1 + (ll)n * (ll)(n - 1) / 2;
	for (i = 0; i < 26; i++)
		ans -= cnt[i] * (cnt[i] - 1) / 2;
	printf("%lld\n", ans);
}

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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m; cin >> n >> m;
	int ans = 0;
	for (int i = 1; i < floor(sqrt(m))+1; i++){
		int other = m/i;
		if (m%i == 0){
			if (other >= n) ans = max(ans,i);
			if (i >= n) ans = max(ans,other);
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]
BC = sorted(BC, reverse=True, key=lambda x:x[1])
tmp = 0
for B, C in BC:
  A += [C]*B
  tmp += B
  if tmp >= N:
    break
A = sorted(A, reverse=True)
print(sum(A[:N]))

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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}


class Fact{
	vector<ll>fact;
	vector<ll>inv;
public:
	Fact(){}
	Fact(int n){
		n=n*2+10;
		fact=inv=vector<ll>(n);
		fact[0]=inv[0]=1;
		for(int i=1;i<n;i++){
			fact[i]=(fact[i-1]*i)%MOD;
		}
		inv[n-1]=ppow(fact[n-1],MOD-2);
		for(int i=n-2;i>=0;i--){
			inv[i]=(inv[i+1]*(i+1))%MOD;
		}
	}
	ll get(int n){
		return fact[n];
	}
	ll get_inv(int n){
		return inv[n];
	}
	ll nPr(int n,int r){
		return fact[n]*inv[n-r]%MOD;
	}
	ll nCr(int n,int r){
		return nPr(n,r)*inv[r]%MOD;
	}
	ll nrP(int n,int r){
		return nPr(n+r,n);
	}
	ll nrC(int n,int r){
		return nCr(n+r,n);
	}
};
class UnionFind {
	vector<int>par, sz;
	vector<int>cnt;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = cnt=vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y){
			cnt[x]++;
			return;
		}
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
			cnt[x]+=cnt[y]+1;
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
			cnt[y]+=cnt[x]+1;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
	int count(int x){
		return cnt[find(x)];
	}
};

int p[6000];
ll dp[6000][6000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d",&p[i]);
		if(p[i]>=1)p[i]--;
	}
	UnionFind uf(n);
	int K=0;
	rep(i,n){
		if(p[i]!=-1){
			uf.unite(i,p[i]);
		}
		else K++;
	}
	ll ans=0;
	vector<int>vs;
	rep(i,n){
		if(uf.find(i)!=i)continue;
		if(uf.size(i)==uf.count(i)){
			(ans+=ppow(n-1,K))%=MOD;
		}
		else{
			(ans+=ppow(n-1,K-1)*(uf.size(i)-1))%=MOD;
			vs.push_back(uf.size(i));
		}
	}
	//~ cout<<ans<<endl;
	Fact fac(n);
	dp[0][0]=1;
	rep(i,vs.size())rep(j,n+1){
		if(dp[i][j]==0)continue;
		(dp[i+1][j]+=dp[i][j])%=MOD;
		(dp[i+1][j+1]+=dp[i][j]*vs[i])%=MOD;
	}
	for(int i=2;i<=n;i++){
		if(dp[vs.size()][i]==0)continue;
		(ans+=dp[vs.size()][i]*fac.get(i-1)%MOD*ppow(n-1,K-i))%=MOD;
	}
	//~ cout<<ans<<endl;
	ans=(n*ppow(n-1,K)%MOD+MOD-ans)%MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 121684
#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int current=1;
    while(n--)
    {
        if(current*2<current+k)
        {
            current*=2;
        }
        else
        {
            current+=k;
        }
    }
    cout<<current;

}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long h = in.nextLong();
        long count = 0;
        long monster = 1;
        while(true) {
            count += monster;
            h = (long)Math.floor((double)h / 2.0);
            if(h<1) {
                break;
            }
            monster *= 2;
        }
        System.out.println(count);
    }
}


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


void solve_case()
{
    int n,i,j,t,k,m;
    cin >> n;
    if(n%1000==0) cout << 0 << "\n";
    else cout << 1000-n%1000 << "\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int Testcases = 1;
    //cin >> Testcases;
    while(Testcases--)
    {
        solve_case();
    }
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,m;
    int ans=0;
    cin >>n>>m;
    vector<vector<int>>s(m);
    vector<int>hash(m,0);
    int bef;
    int sbef;
    vector<int>mod2(m);
    rep(i,m){
        cin>>bef;
        rep(_,bef){
            cin>>sbef;
            sbef--;
            s[i].push_back(sbef);
            hash[i]|=(1<<sbef);
        }
    }
    rep(i,m){
        cin>>mod2[i];
    }

    bool all=true;
    for(int bit=0;bit<(1<<n);bit++){
        all=true;

        for(int i=0;i<m;i++){
            if(__builtin_popcount(bit&hash[i])%2!=mod2[i]){
                all=false;
            }
        }

        if(all){
            ans++;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 505
using namespace std;
typedef long long ll;
int n,pr[MN<<2],tt;bool p[MN*MN];
ll a[MN][MN];
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int main(){
	scanf("%d",&n);
	for(int i=2;i<=1e5;i++){
		if(!p[i]){
			pr[++tt]=i;
			if(tt>=4*n)break;
		}
		for(int j=1;j<=tt;j++){
			if(i*pr[j]>1e5)break;
			p[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}ll tt=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if((i+j)%2==0){
				a[i][j]=1ll*pr[i+j>>1]*pr[(i-j)/2+n];
			}else {
				a[i][j]=1ll*pr[i+j>>1]*pr[(i+j+1)>>1];
				if(i-j<0)a[i][j]*=1ll*pr[(i-j)/2+n]*pr[(i-j-1)/2+n];
				else a[i][j]*=1ll*pr[(i-j)/2+n]*pr[(i-j+1)/2+n];a[i][j]++;
				tt=max(a[i][j],tt);
			}//printf("%lld\n",tt);
/*	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int k=0;k<4;k++){
		int tx=i+dx[k],ty=j+dy[k];
		if(tx>=1&&tx<=n&&ty>=1&&ty<=n){
			if(max(a[i][j],a[tx][ty])%min(a[i][j],a[tx][ty])!=1)printf("%d %d %d %d\n",i,j,tx,ty);
		}
	}*/
	for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)printf("%lld ",a[i][j]);puts("");}
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    ll n, x, m; cin >> n >> x >> m;
    ll sum = 0, more = 0, bef = 0, shu = 0, bef_long = 0, shu_long = 0;
    vector<ll> shu_v, A(100000);
    map<ll, ll> mp;
    bool found = false, shuuki = false;
    Rep(i, 1, n+1){
        if(i == 1) A[i-1] = x;
        else A[i-1] = A[i-2]*A[i-2] % m;
        ll tmp = A[i-1];
        mp[tmp]++;
        if(mp[tmp] == 2){
            if(!shuuki) bef_long = i-1;
            shuuki = true;
            shu += tmp;
            sum += tmp;
            shu_v.push_back(tmp);
        }
        else if(mp[tmp] == 3){
            shu_long = i - bef_long - 1;
            found = true;
            break;
        }
        else{
            sum += tmp;
            bef += tmp;
        }
    }
    if(mp.count(0)){
        cout << sum << endl;
        return 0;
    }
    if(!found){
        cout << sum << endl;
        return 0;
    }
    rep(i, (n-bef_long)%shu_long){
        more += shu_v[i];
    }
    cout << bef + shu * ((n-bef_long)/shu_long) + more << endl;
}


Measured memory_bytes: 7816
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    priority_queue<int64_t> ps, qs, rs;
    for (int i = 0; i < a; i++)
    {
        int64_t v;
        cin >> v;
        ps.push(v);
    }
    for (int i = 0; i < b; i++)
    {
        int64_t v;
        cin >> v;
        qs.push(v);
    }
    for (int i = 0; i < c; i++)
    {
        int64_t v;
        cin >> v;
        rs.push(v);
    }

    priority_queue<int64_t, vector<int64_t>, greater<int64_t>> all;
    for (int i = 0; i < x; i++)
    {
        all.push(ps.top());
        ps.pop();
    }
    for (int i = 0; i < y; i++)
    {
        all.push(qs.top());
        qs.pop();
    }
    while (!rs.empty())
    {
        if (all.top() < rs.top())
        {
            all.pop();
            all.push(rs.top());
            rs.pop();
        }
        else
        {
            break;
        }
    }
    int64_t sum = 0;
    while (!all.empty())
    {
        sum += all.top();
        all.pop();
    }
    cout << sum << endl;
}

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

string str;
ll tsum=0,tmul=1;
vector<ll> t;
map<ll,ll> mem[20][200][3];

ll rec(int p,ll sum,ll mul,int flg){
  if(sum>tsum)return 0;

  if(p==(int)t.size()){
    if(sum<tsum)return 1;
    if(sum==tsum&&mul<tmul)return 1;
    if(sum==tsum&&mul==tmul&&flg==1)return 1;
    return 0;
  }

  if(mem[p][sum][flg].count(mul)>0){
    return mem[p][sum][flg][mul];
  }

  ll l=0,r=9,res=0;

  for(ll i=l;i<=r;i++){
    int nflg=flg;
    if(flg==0){
      if(i<t[p])nflg=1;
      if(i>t[p])nflg=2;
    }
    res+=rec(p+1,sum+i,mul*(i+1),nflg);
  }
  
  return mem[p][sum][flg][mul]=res;
}

int main(){
  cin>>str;
  for(int i=0;i<(int)str.size();i++){
    ll A=str[i]-'0';
    tsum+=A;
    tmul*=(A+1);
    t.push_back(A);
  }
  cout<<rec(0,0,1,0)<<endl;
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  multiset<int> A;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    auto it = A.lower_bound(a);
    if (it != A.begin()) A.erase(--it);
    A.insert(a);
  }
  cout << A.size() << '\n';
  return 0;
}


Measured memory_bytes: 4992
N, A = map(int, input().split())
X = list(map(int, input().split()))
for i in range(N):
  X[i] -= A
X.sort()

p = { 0: 1 }
for x in X:
  for n, count in list(p.items()):
    if n+x <= 0:
      p[n+x] = p.get(n+x, 0) + count

print(p[0] - 1)

Measured memory_bytes: 3188
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    a,b,c = map(int, input().split())
    print(min(c, b//a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int D,c[26],s[365][26],ans[365];
int main() {
	std::cin>>D;
	rep(i,26)std::cin>>c[i];
	rep(i,D){
		rep(j,26)std::cin>>s[i][j];
	}
	rep(i,D)ans[i]=1;
	rep(i,D)std::cout<<ans[i]<<std::endl;
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;
/*int dfs(vector<int> &T, vector<int> &C, int i, int sum, int g, int count){
   
}*/

int main(){
  //int n, i, m;
  /*int n, m;
  cin >> n >> m;
  vector<int> A(n);
  rep(i, n) cin >> A[i];*/
  //sort(A.begin(), A.end());
  //reverse(A.begin(), A.end());
  int64_t n, k;
  cin >> n >> k;
  int64_t p =  n%k;
  cout << min(p, abs(p-k)) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll x,y;
        cin>>x>>y;
        ll num=x;
        ll res=0;
        while(num<=y){
            num*=2;
            res++;
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 256
import math
N,M = map(int, input().split())
S = input()
T = input()

if S[0] != T[0]:
  print(-1)
  exit()

lcm = N * M // math.gcd(N, M)
#1,(L/N) +1, 2*(L/N) +1..(N-1)*(L/N)+1
tekito =[]
for i in range(1,N):
  tekito.append(i*(lcm//N)+1)
tekitu =[]
for i in range(1,M):
  tekitu.append(i*(lcm//M)+1)

gattai = set(tekito) & set(tekitu) 
for k in gattai:
  i1 = (k-1) // (lcm//N)
  i2 = (k-1) // (lcm//M)
  if S[i1] != T[i2]:
    print(-1)
    exit()
print(lcm)


Measured memory_bytes: 26604
# Suplemental: ABC54 C
N, M = map(int, input().split())
E = [[] for i in range(N+1)]
for i in range(M):
    a,b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
    
#for i in range(1,N+1):
#    print(E[i])

visited = [False for i in range(N+1)]

num_of_paths = 0
def dfs(v):
    global num_of_paths
    
    if visited.count(True) == N:
        num_of_paths += 1
        return
    else:
        for next_v in E[v]:
            if not visited[next_v]:
                visited[next_v] = True
                dfs(next_v)
                visited[next_v] = False
        return
    
visited[1] = True
dfs(1)

print(num_of_paths)

Measured memory_bytes: 3064
n,b,i,t;long long k=1;L(x,y){!y?k*=n/x:L(y,x%y);}main(a){for(;scanf("%d%d",&a,&b,n=1)*a;L(n,k),k=++i%3?k:!!printf("%lld\n",k))for(t=a;t-1;t=t*a%b)++n;}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  int s[1000000];
  int tp[1000000];
  cin>>n>>q;
  for(int i=0;i<n;i++){
    scanf("%d",&s[i]);
    tp[i]=s[i];
  }
  map<int,int> mp;
  sort(s,s+n);
  for(int i=0;i<n;i++)mp[s[i]]=i;
  vector<int> ld;
  while(q--){
    string str;
    int a;
    cin>>str>>a;
  
    if(str[0]=='A'){
      a--,ld.push_back(mp[tp[a]]);
      sort(ld.begin(),ld.end());
    }
    
    if(str[0]=='R'){
      a--;
      int b=mp[tp[a]];
      for(int i=0;i<ld.size();i++){
	if(b==ld[i]){
	  ld.erase(ld.begin()+i);
	  break;
	}
      }
    }

    if(str[0]=='C'){
      int l=0,r=1e9+10,m; 

      while(l<r){
	m=(l+r)/2;

	int pr=1e9,res=0;

	for(int i=ld.size()-1;i>=0;i--){
	  int nld=ld[i];
	  if(pr<nld)nld=pr;
	  pr=lower_bound(s,s+n,s[ld[i]]-m)-s;
	  pr--;
	  if(nld>pr)res+=(nld-pr);
	}
	if(n-res<=a)r=m;
	else l=m+1;
      }

      
      if(r==1e9+10)cout<<"NA"<<endl;
      else cout<<r<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 57908
////////////////////////////////////////////
///                                      ///
///        Template ver. 1.2. rapel      ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define endl '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

vector<int> num;

vector<pair<pair<int,int>,int> >result;

void hora(int tc) {
	int n;
	cin>>n;
	if(n == 2) {
		cout<<2<<" "<<2<<endl;
		cout<<1<<" "<<2<<" "<<0<<endl;
		cout<<1<<" "<<2<<" "<<1<<endl;
		return ;
	}
	int tmpn = n;
//	n--;
	int base = 1;
	while(n >= 2 * base) {
		num.pb(base);
		base *= 2;
	}
	int sz = num.size();
	for(int i = 0;i < sz;i++) {
		result.pb({{i + 1, i + 2}, 0});
		result.pb({{i + 1, i + 2}, (1<<(sz - 1 - i))});
	}
	int ujung = sz + 1;
	n = tmpn;
	int b = 1;
	while(__builtin_popcount(n) != 1) {
		if(n & b) {
			n ^= b;
			result.pb({{1, ujung}, tmpn & n});
		}
		b *= 2;
		ujung--;
	}
	cout<<sz + 1<<" "<<result.size()<<endl;
	for(auto x: result) cout<<x.F.F<<" "<<x.F.S<<" "<<x.S<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


Measured memory_bytes: 384
def count(n):
	sum = 0
	while n > 0:
		sum += n % 10
		n = n // 10
	return sum

N = int(input())
j = 0
ans = []

for i in range(1, N):
	j = N - i
	ans_count = count(i) + count(j)
	ans.append(ans_count)

print(int(min(ans)))

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;


int main(){
  int n; cin >> n;
  string s, t; cin >> s >> t;

  string ans = "";
  rep(i,n){
    ans += s[i];
    ans += t[i];
  }

  cout << ans << endl;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define INF 1145141919
#define MOD 998244353
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

ll calcproduct(int n) {
  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}

ll mod_pow(ll x, ll n) {
  if (n == 0) return 1;
  ll res = mod_pow(x * x % MOD, n / 2);
  if (n & 1) res = res * x % MOD;
  return res;
}

ll combination(int n, int k) {
  ll a = calcproduct(n);
  ll b = calcproduct(k);
  ll c = calcproduct(n-k);
  b = mod_pow(b, MOD-2);
  c = mod_pow(c, MOD-2);
  ll ans = ((a*b)%MOD*c)%MOD;
  return ans;
}

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

  int N, M, K;
  cin >> N >> M >> K;
  ll a = calcproduct(N-1);
  ll b = calcproduct(N-1);
  ll c = 1;
  ll sum = 0;
  ll tmp;
  repto (i, K) {
    ll p = a;
    ll q = mod_pow(b, MOD-2);
    ll r = mod_pow(c, MOD-2);
    ll t = mod_pow(M-1, N-1-i);
    tmp = ((((p*q)%MOD*r)%MOD*M)%MOD*t)%MOD;
    sum += tmp;
    sum %= MOD;
    p = mod_pow(N-1-i, MOD-2);
    b *= p;
    b %= MOD;
    c *= i+1;
    c %= MOD;
    // cout << sum << endl;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define REP(i, n) for (int 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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  vector<int> r,g,b;
  REP(i,n){
    if(s[i]=='R') r.push_back(i);
    else if(s[i]=='G') g.push_back(i);
    else b.push_back(i);
  }
  ll ans = r.size() * g.size() * b.size();
  REP(i,n){
    for(int k=i+2; k<n; k+=2){
      int j = (i+k)/2;
      if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) ans--;
    }
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll n,x;cin>>n>>x;
    ll sum=0;
    ll a[n];rep(i,0,n-1){cin>>a[i];sum+=a[i];}
    sort(a,a+n);
    //rep(i,0,n-1)cout<<a[i]<<" ";cout<<endl;

    if(sum<x){
        cout<<n-1<<endl;
    }else if(sum==x){
        cout<<n<<endl;
    }else{
        int pos=0;
        while(pos<=n-1){
            if(a[pos]<=x){
                x-=a[pos];
                  pos++;
            }else{
                break;
            }
        }
        cout<<pos<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
 
  if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n;
  int64_t k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<int> s;
  vector<int> ord(n + 1, -1);

  int c = 1, l = 0;
  int v = 1;
  while (ord[v] == -1) {
    cerr << v << " ";
    ord[v] = s.size();
    s.push_back(v);
    v = a[v - 1];
  }
  c = s.size() - ord[v];
  l = ord[v];

  if (k < l) {
    cout << s[k] << '\n';
  } else {
    k -= l;
    k %= c;
    cout << s[l + k] << '\n';
  }
  // unordered_set<int64_t> c;
  // int64_t goal = 0;
  // c.insert(goal);
  // cerr << goal << '\n';
  // for (int64_t i = 1; i <= k; ++i) {
  //   goal = a[goal];
  //   auto itc = c.find(goal);
  //   if (itc == c.end()) {
  //     c.insert(goal);
  //     cerr << goal << '\n';
  //   } else {
  //     int64_t loop = distance(itc, c.end());
  //     cerr << *itc << " " << loop << '\n';
  //     int64_t kk = (k - i) % loop;
  //     cout << *next(itc, kk) + 1 << '\n';
  //     break;
  //   }
  // }

  return 0;
}


Measured memory_bytes: 5860
//Achen
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=2e5+7;
typedef long long LL; 
typedef double db;
using namespace std;
int n;
LL s[N],ans;

template<typename T> void read(T &x) {
    char ch=getchar(); x=0; T f=1;
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

map<LL,LL>f;
map<LL,LL>g;
map<LL,LL>cnt;

int bo[N],p[N];
void get_prime(int n) {
	For(i,2,n) {
		if(!bo[i]) p[++p[0]]=i;
		for(int j=1;j<=p[0]&&p[j]*i<=n;j++) {
			bo[p[j]*i]=1;
			if(i%p[j]==0) break;
		}
	}
}

void get_it(LL x) {
	if(f[x]) {
		LL z=f[x];
		if(z==-1) ans++;
		else cnt[z]++;
		return;
	}
	LL tp=x,fx=1,gx=1;
	For(i,0,325) {
		if(tp%p[i]==0) {
			int c=0;
			while(tp%p[i]==0) {
				tp/=p[i]; c++;
			} c%=3;
			if(c==1) fx*=p[i],gx*=(LL)p[i]*p[i];
			else if(c==2) fx*=(LL)p[i]*p[i],gx*=p[i];
		}
		if(tp==1) break;
	}
	if(tp!=1) {
		if(tp<=100000&&!bo[tp]) { fx*=tp; gx*=tp*tp; }
		else {
			LL tt=sqrt(tp);
			if(tt*tt==tp) { fx*=tp; gx*=tt; }
			else { fx*=tp; gx*=tp*tp; }
		}
	}
	f[x]=fx; g[fx]=gx; cnt[fx]++;
}

#define IT map<LL,LL>::iterator 

//#define DEBUG
int main() {
#ifdef DEBUG
	freopen("1.in","r",stdin);
	//freopen(".out","w",stdout);
#endif
	read(n);
	get_prime(100000);
	For(i,1,n) read(s[i]);
	For(i,1,n) 
		get_it(s[i]);
	for(IT it=cnt.begin();it!=cnt.end();++it) {
		LL x=it->first,y=it->second;
		if(x==1&&y) ans++;
		if(cnt[g[x]]<y||(cnt[g[x]]==y&&g[x]<x)) ans+=y;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 31232
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll K;
    cin >> K;
    queue<string> q;
    vs lunlun;

    if(K < 9){
        cout << K << endl;
        return 0;
    }

    for(int i=1; i<=9; i++){
        q.push(to_string(i));
        lunlun.push_back(to_string(i));
    }

    ll c = 9;
    string s;
    int num;
    while(c <= K){
        s = q.front();
        num = s.at(s.size()-1) - '0';
        q.pop();
        for(int i=0; i<10; i++){
            if(abs(num - i) <= 1){
                q.push(s + to_string(i));
                c++;
                lunlun.push_back(s + to_string(i));
            }
        }
    }

    cout  << lunlun.at(K-1) << endl;
}

Measured memory_bytes: 9332
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;
string rp(string s,char t,char r){
  string ret="";
  rep(i,s.size()){
    if(s[i]==t) ret+=r;
    else ret+=s[i];
  }
  return ret;
}

int main(){
  string base="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string s,t;
  cin>>s>>t;
  int cnt=0;
  rep(i,s.size()){
    if ((int)s[i]-'a'>=0) {
      s=rp(s,s[i],base[cnt]);
      cnt++;
    }
  }
  cnt=0;
  rep(i,t.size()){
    if ((int)t[i]-'a'>=0) {
      t=rp(t,t[i],base[cnt]);
      cnt++;
    }
  }
  if(s==t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 1596
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    ll x, k, d ;
    cin >> x >> k >> d ;
    ll how = (abs(x)) / d ;
    if(how > k){
        cout << abs(x) - d * k << endl ;
        return 0 ;
    }
    ll f = abs(x) - how*d ;
    ll r = k - how ;
    if(r % 2 == 0){
        cout << abs(f) << endl ;
    }
    else {
        cout << abs(d - f) << endl ;
    }
}


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>

using namespace std;
typedef long long ll;
const ll N = 2e5 + 10;

string str,last;
ll dp[N];

int n,k,r,s,p;
int vis[N];

int get(char c){
    if(c=='r') return p;
    if(c=='s') return r;
    return s;
}

int main() {
    cin>>n>>k;
    cin>>r>>s>>p;
    cin>>str;
    ll ans = 0;
    for(int i=0,t;i<k;i++){
//       t = get(str[i]);
//       last+=str[i];
       vis[i]=1;
       ans+=get(str[i]);
    }
    for(int i=k;i<n;i++){
        if(str[i]==str[i-k]){
            if(vis[i-k]==0){
                ans+=get(str[i]);
                vis[i]=1;
            }else{
                vis[i]=0;
            }

        }else{
            ans+=get(str[i]);
            vis[i]=1;
        }
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#define N 100005
typedef long long ll;
using namespace std;
ll n, s, a[5][N], b[N], c[N];
int main() {
	int i, j;
	scanf("%lld", &n);
	for(i=0; i<3; i++) {
		for(j=0; j<n; j++) scanf("%lld", &a[i][j]);
		sort(a[i], a[i]+n);
	}
	for(i=0; i<n; i++) {
		b[i] = lower_bound(a[0], a[0]+n, a[1][i]) - a[0];
		c[i] = n - (upper_bound(a[2], a[2]+n, a[1][i]) - a[2]);
		s += b[i]*c[i];
	}
	printf("%lld", s);
	return 0;
}

Measured memory_bytes: 4224
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  x, y = map(int, input().split(' '))
  if(2*x <= y and  4*x >= y and y % 2==0):
    print('Yes')
  else:
    print('No')

if __name__=='__main__':
  main()

Measured memory_bytes: 9100
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,w;
    cin >> a >> b >> c;
    if(a!=c || a!=b || b!=c)
        {
    if(a==b)
    {
        cout << c;
    }
    else if(a==c)
    {
        cout << b;
    }
    else if(b==c)
    cout << a;
        }
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
vector<string>v;
string temp;
vector<string>x;
bool vis[20];
int n;
int main()
{
    IOS;
    int ans=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        v.pb(s);
    }
    int ba=0,_a=0,b_=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<v[i].length()-1;j++)
        {
            if(v[i][j]=='A'&&v[i][j+1]=='B')ans++;
        }
        int l=v[i].length();
        string s;
        s+=v[i][0];
        s+=v[i][l-1];
        if(s=="BA")ba++;
        else if(s[0]=='B')b_++;
        else if(s[1]=='A')_a++;
    }
//    cout<<ba<<" "<<_a<<" "<<b_<<endl;
    if(ba>0){
        ans+=ba-1;
        if(b_>0)b_--,ans++;
        if(_a>0)_a--,ans++;
    }
    ans+=min(_a,b_);

    cout<<ans<<endl;
}








Measured memory_bytes: 768
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<ArrayList<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            ArrayList<Integer> g = new ArrayList<>();
            graph.add(g);
        }
        for (int i = 0; i < M; i++) {
            int A = sc.nextInt() - 1;
            int B = sc.nextInt() - 1;
            graph.get(A).add(B);
            graph.get(B).add(A);
        }

        int[] dist = new int[N];
        for (int i = 0; i < dist.length; i++) {
            dist[i] = -1;
        }
        Queue<Integer> que = new LinkedList<>();
        dist[0] = 0;
        que.add(0);

        while (!que.isEmpty()) {
            int v = que.remove();
            for (int nv : graph.get(v)) {
                if (dist[nv] != -1) {
                    continue;
                }
                dist[nv] = dist[v] + 1;
                que.add(nv);
            }
        }
        boolean ok = true;
        for (int i = 0; i < dist.length; i++) {
            if (dist[i] == -1) {
                ok = false;
                break;
            }
        }
        if (ok) {
            System.out.println("Yes");
            for (int i = 1; i < N; i++) {
                for (int j = 0; j < graph.get(i).size(); j++) {
                    int next = graph.get(i).get(j);
                    if (dist[next] == dist[i] - 1) {
                        System.out.println(next + 1);
                        break;
                    }
                }
            }
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}

Measured memory_bytes: 86452
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP){ 
    return firstP.second < secondP.second; 
}//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll n;
Vi pmer(101);

Vi prime_fact(ll n){//素因数分解
	Vi ans(101);
    for(ll i=2;i*i<=n;i++){
		if(n%i!=0)continue;
		ll num = 0;
		while(n%i==0){num++;n/=i;}
		ans[i]+=num;
	}
	if(n!=1)ans[n]=1;
	return ans;
}

void add(Vi& vp,Vi vp2){
    rep(i,vp2.size())if(vp2[i]!=0)vp[i]+=vp2[i];
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n)add(pmer,prime_fact(i+1));
    Sort(pmer); ll ans = 0;
    rep(i,pmer.size()){
        if(pmer[i]<4)break;
        if(pmer[i]>=74)ans++;
        for(ll j=i+1;j<pmer.size();j++){
            if(pmer[i]>=24 && pmer[j]>=2)ans++;
            if(pmer[i]>=2 && pmer[j]>=24)ans++;
            if(pmer[i]>=14 && pmer[j]>=4)ans++;
            if(pmer[i]>=4 && pmer[j]>=14)ans++;
            for(int k = j+1;k<pmer.size();k++){
                if(pmer[k]>=4)ans += 3;
                else if(pmer[i]>=4 && pmer[j]>=4 && pmer[k]>=2)ans++;
                
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)

def grid(y,x):
    global dp,visited
    if visited[y][x]:
        return dp[y][x]
    else:
        visited[y][x]=True
        if mp[y][x]!='#' and dp[y][x]==0:
            dp[y][x]=(grid(y-1,x)+grid(y,x-1))%mod
        return dp[y][x]

H,W=map(int,input().split())
mp=[['#']*(W+1)]
for _ in range(H):
    mp.append(['#']+list(input()))

dp=[[0]*(W+1)for _ in range(H+1)]
dp[1][1]=1
visited=[[False]*(W+1)for _ in range(H+1)]
mod=10**9+7
grid(H,W)
print(dp[H][W])


Measured memory_bytes: 65340
import sys
input = sys.stdin.readline
#from itertools import accumulate
#from itertools import combinations
N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

#N,K = 4,4
#P = [2,3,4,1]
#C = [-9,9,1,-1]
#N = 5000
#K = 10**8
#P = [i+1 for i in range(1,5000)] + [1]
#C = [10**9] * N

visited = [False]*(N+1)
loops = []
for v in range(1,N+1):
    if visited[v]:
        continue
    l = [v]
    while True:
        v = l[-1]
        visited[v] = True
        nv = P[v-1]
        if visited[nv]:
            break
        l.append(nv)
    loops.append(l)

cand = []
for loop in loops:
    temp = 0
    vals = [C[i-1] for i in loop]
    l = len(vals)
    vals3 = vals+vals+vals[:-1]
    cumsum = [0]
    for v in vals3:
        cumsum.append(cumsum[-1] + v)
    gh = []
    #print(vals)
    if K <= l:
        temp = 0
        ma = min(vals)
        for left in range(0,2*l-K):
            for right in range(left+1,left+K+1):
                ma = max(ma,(cumsum[right] - cumsum[left]))
        temp += ma
    else:
        temp = 0
        s = sum(vals)
        q, r = divmod(K,l)
        q -= 1
        r += l
        ma = min(vals)
        for left in range(0,3*l-r):
            for right in range(left+1,left+r+1):
                ma = max(ma,(cumsum[right] - cumsum[left]))
        temp += ma
        if s > 0:
            temp += q * s
    cand.append(temp)
print(max(cand))






Measured memory_bytes: 69504
#include <cstdio>
#include <cstring>
using namespace std;

int narr[3];
char arr[3][30];

int main(){
	int i, flag = 1;
	scanf("%s%s%s", arr[0], arr[1], arr[2]);
	for(i = 0; i < 3; i++) narr[i] = strlen(arr[i]);
	for(i = 1; i < 3; i++) if(arr[i][0] != arr[i - 1][narr[i - 1] - 1]) flag = 0;
	if(flag) printf("YES");
	else printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdio.h>
# define M_PI  3.14159265358979323846
using namespace std;

typedef long long ll;
const int N = 1e3 + 9, M = 9e2 + 9, OO = 0x3f3f3f3f;
const double EPS = 0.00000000001;

int r;


int main(){
	//freopen ("i.in","r",stdin);
	//freopen ("no.out","w",stdout);

	scanf("%d", &r);
	printf("%d\n", r*r);




	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	
	char str;
	int num[26];
	int i;
		
		for(i = 0;i<26;i++){
			num[i] = 0;
		}
	  

    while(scanf("%c",&str) != EOF){

			if(str >= 'A' && str <= 'Z'){
				int a ;
				a = str - 'A';
				num[a] = num[a] + 1 ;

			}
			else if(str >= 'a' && str <= 'z'){
				int a ;
				a = str - 'a';
				num[a] = num[a] +1;

			}
		
    }
		
	for(i = 0;i<26;i++){
		printf("%c : %d\n",i+97,num[i]);
	}
    
return 0;
}

Measured memory_bytes: 540
import java.util.*;
 
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
 
	switch (s) {
	    case "Sunny":
	        System.out.println("Cloudy");
	        break;
	    case "Cloudy":
	        System.out.println("Rainy");
	        break;
	    case "Rainy":
	        System.out.println("Sunny");
	        break;
	}
  }
}

Measured memory_bytes: 21844
I=->{gets.split.map &:to_i};q=0..k=I[][0];G=q.map{[]};k.times{q,k,c=I[];c&&G[q]<<[k,c]&&G[k]<<[q,c]};s=[[k,0]];while k=(v,u,p=s.pop);G[v].map{|t,c|p!=t&&s<<[t,u+c,v]};G[v]=u;end;q.times{x,y=I[];p G[x]+G[y]}

Measured memory_bytes: 35484
#include <bits/stdc++.h>
using namespace std;
double distance(double x1, double y1, double r1, double x2, double y2, double r2){
	double tmp1 = r1 + r2;
	double tmp2 = pow((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2), 0.5); 
	return max((double) 0, tmp2 - tmp1); 
}
int main(){
	double X[1010] = {}; 
	double Y[1010] = {}; 
	double R[1010] = {}; 
	int N; 
	cin >> X[0] >> Y[0] >> X[1001] >> Y[1001] >> N; 
	for(int i = 1; i <= N; i++){
		cin >> X[i] >> Y[i] >> R[i]; 
	}
	double dist[1010][1010] = {}; X[N+1] = X[1001]; Y[N+1] = Y[1001]; 
	for(int i = 0; i <= N+1; i++){
		for(int j = 0; j <= N+1; j++){
			dist[i][j] = distance(X[i], Y[i], R[i], X[j], Y[j], R[j]); 
		}
	}
	double D[1010] = {}; 
	fill(D, D+N+2, 1941941145141919.19419); 
	D[0] = 0.0; 
	priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> que; 
	que.push(make_pair(D[0], 0)); 
	while(que.size()){
		pair<double, int> p = que.top(); que.pop();  
		for(int i = 0; i <= N+1; i++){
			if(p.second == i) continue; 
			if(D[i] > p.first + dist[p.second][i]){
				que.push(make_pair(p.first + dist[p.second][i], i)); 
				D[i] = p.first + dist[p.second][i]; 
			}
		}
	}
	cout.precision(20); 
	cout << D[N+1] << endl; 
}

Measured memory_bytes: 14448