akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)n; i++)

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p;
    rep(i,n) {
        int pi;
        cin >> pi;
        p.push_back(pi);
    }

    sort(p.begin(),p.end());

    int sum = 0;
    rep(i,k) {
        sum += p.at(i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <vector>
#include <map>
#include <cassert>
using namespace std;

int mx;
int d[3000];
int n;
int done[3000] = {};
int ok[3000] = {};
int can(int x){
	if( done[x] ) return 0;
	done[x] = 1;
	if( x == n - 1 ) return 1;
	for(int i = 1 ; i <= mx ; i++){
		int t = min(n-1,x+i);
		t += d[t];
		t = max(0,t);
		t = min(t,n-1);
		if( can(t) ) return 1;
	}
	return 0;
}
int dfs(int x){
	if( !ok[x] ) return 1;
	if( done[x] ) return 0;
	done[x] = 1;
	
	for(int i = 1 ; i <= mx ; i++){
		int t = min(n-1,x+i);
		t += d[t];
		t = max(0,t);
		t = min(t,n-1);
		if( dfs(t) ) return 1;
	}
	return 0;
}
int main(){
	while(cin >> mx && mx){
		for(int i = 0 ; i < 300 ; i++) d[i] = 0;
		cin >> n;
		n += 2;
		for(int i = 1 ; i < n - 1 ; i++)
			cin >> d[i];
		for(int i = 0 ; i < n ; i++){
			for(int j = 0 ; j < 300 ; j++) done[j] = 0;
			ok[i] = can(i);
		}
		for(int j = 0 ; j < 300 ; j++) done[j] = 0;
		cout << (dfs(0)?"NG":"OK") << endl;
		
		
	}
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    int n;
    string a,b,c;
    cin >> n >> a >> b >> c;
    int cnt=0;
    rep(i,n){
        char aa=a.at(i);
        char bb=b.at(i);
        char cc=c.at(i);
        if(aa!=bb && aa!=cc && bb!=cc)cnt+=2;
        else if(aa==bb && aa!=cc)cnt++;
        else if(aa==cc && aa!=bb)cnt++;
        else if(bb==cc && bb!=aa)cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <cstring>
#include <set>

#define ll long long
#define ld long double
#define HS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 0x3f3f3f3f3f3f3f3f
#define point complex <double>
#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define mod 1000000007


using namespace std;

int main() {

    HS;
    int n;
    cin>>n;
    int arr[205];
    bool odd=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]%2)
            odd=1;
    }
    if(odd)
        cout << 0 << endl;
    else
    {
        int max=1e6;
        ll ans=1;
        bool notOdd=1;

        while(max--)
        {
            for(int i=0;i<n;i++)
            {
                arr[i]/=2;
                if(arr[i]%2)
                {
                    notOdd=0;
                    break;
                }
            }
            ans+=notOdd;
            if(!notOdd)
                break;


        }
        if(notOdd)
        {
            max=1e6;
            while(max--)
            {
                for(int i=0;i<n;i++)
                {
                    arr[i]/=2;
                    if(arr[i]%2)
                    {
                        notOdd=0;
                        break;
                    }
                }
                ans+=notOdd;
                if(!notOdd)
                    break;


            }


        }
        cout << ans << endl;

    }

   return 0;

}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void print(int arr[], int n){
     for(int i=0;i<n;++i)
     cout<<arr[i]<<" ";
     cout<<endl;
}
int gcd(int a,int b){
    if(a==0)
    return b;
    return gcd(b%a,a);
}
int32_t main()
{
    int a,b;
    cin>>a>>b;
    int mx=0;
    int c=2*a-1;
    mx=max(mx,c);
    c=2*b-1;
    mx=max(mx,c);
    a+=b;
    mx=max(mx,a);
    cout<<mx;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

// Aliases
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
using ull = unsigned long long;

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::string;
using std::vector;
using std::array;
template <class T>
using matrix = vector<vector<T>>;
template <class T>
constexpr T inf = std::numeric_limits<T>::max();
template <class T>
constexpr T neg_inf = -std::numeric_limits<T>::max();
template <class T>
constexpr T pi = static_cast<T>(3.141592653589793);

template <class T = i64>
vector<T> read_vector(const u64 n)
{
    vector<T> vec;
    vec.reserve(n);
    for (u64 i = 0; i < n; i++)
    {
        T v;
        cin >> v;
        vec.emplace_back(v);
    }

    return vec;
}

template <class T>
void print(const vector<T>& vec, const bool new_line = false)
{
    const u64 n = vec.size(); 
    if (new_line)
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << '\n'; }
        }
    }
    else
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << ' '; }
        }
    }

    cout << endl;
}

int main()
{
    u32 a, b;
    cin >> a >> b;
    if (1 <= a && a <= 9 && 1 <= b && b <= 9)
    {
        cout << a * b << endl;
    }
    else
    {
        cout << -1 << endl;
    }
        

    return 0;
}


Measured memory_bytes: 256
#warshal-floydの練習だと思ってやる。
n,m=map(int,input().split())
A=[list(map(int,input().split()))for i in range(m)]
d=[[float('inf') for i in range(n)]for i in range(n)]

def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j], d[i][k]+d[j][k])
#warshal floydする関数

# for t in range(n):
#     a,b=A[t]
#     a-=1
#     b-=1
#     d[a][b]=1
#Aにある経路を、おもみ1で計算。
count=0
for i in range(m):
    d=[[float('inf') for _ in range(n)]for _ in range(n)]
    for j in range(m):
        if i==j:
            p,q=A[j]
            p-=1
            q-=1
            #1箇所くっつけないでおく場所を指定し、そこの場所をp,qでmemo
        else:
            a,b=A[j]
            a-=1
            b-=1
            d[a][b]=1
            d[b][a]=1
    wf(d)
    if d[p][q]==float('inf'):
        count+=1
print(count)

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

typedef long long ll;

const int inf = 1000000;

vector<pair<int, int>>v;
int n, N;

int main() {
    cin >> n;
    N = n/2*2+1;
    for (int i = 1; i < n; i++) {
        for (int j = i+1; j <= n; j++) {
            if (i+j != N)v.push_back({i, j});
        }
    }
    cout << v.size() << endl;
    for (auto x : v) {
        cout << x.first << " " << x.second << endl;
    }
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << std::endl; for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> v1;
typedef vector<v1> v2;
typedef vector<v2> v3;

typedef unordered_map<ll, unordered_map<ll, ll>> graph;

const ll INF = 1ll << 50;
const ll mod = 1000000007;

ll k;
string s;
ll n;

// ll solve(ll k, ll n){
//     v2 dp = v2(n+k+1, v1(n+1, 0ll));
//     dp[0][0] = 1;
//     for(ll i = 1;i <= n+k; i++){
//         for(ll j = 0;j <= n;j++){
//             if(j < n) dp[i][j] += dp[i-1][j] * 25;
//             if(j-1 < n && j-1 >= 0) dp[i][j] += dp[i-1][j-1];
//             if(j == n) dp[i][j] += dp[i-1][j] * 26;
//             dp[i][j] %= mod;
//
//         }
//     }
//     return dp[k+n][n];
// }

ll factorial(ll n,ll mod=mod){
  static ll dp[4000000];
  static ll max_n=0;
  dp[0] = 1;
  while(n > max_n){
      dp[max_n+1] = dp[max_n]*(max_n+1) % mod;
      max_n++;
  }
  return dp[n];
}

ll powl(ll x,ll r,ll mod=mod){
  ll ret = 1;
  for(;r != 0;r >>= 1){
    if(r&1 != 0) ret *= x,ret %= mod;
    x *= x,x %= mod;
  }
  return ret;
}

ll inverse(ll x,ll mod=mod){
  return powl(x,mod-2,mod);
}

ll combination(ll n,ll m,ll mod){
  if(n < m) return 0;
  return (((factorial(n,mod)*inverse(factorial(m,mod),mod))%mod)*inverse(factorial(n-m,mod),mod))%mod;
}


ll solve2(ll k, ll n){
    ll ret = 0;
    for(ll i = n;i <= n+k;i++){
        ret += (combination(i-1, n-1, mod) * powl(25, i-n, mod) % mod) * powl(26, n+k-i) % mod;
        ret %= mod;
    }
    return ret;

}

int main(){
    cin >> k;
    cin >> s;
    n = s.size();
    cout << solve2(k, n) << endl;
}


Measured memory_bytes: 19944
#include<bits/stdc++.h>
#define RI register
using namespace std;
const int N=2e5+10,mod=1e9+7;
typedef long long ll;

int n,f[N],sum,col[N],c[N];
char s[N];
bool fi[N],sc[N];

inline int ad(int x,int y)
{x+=y;return x>=mod?x-mod:x;}

vector<int>g[N];
int pos[N];

int main(){
	int i,x,y;sum=1;f[0]=1;
	scanf("%d",&n);
	for(i=1;i<=n;++i) {
		scanf("%d",&c[i]);
		g[c[i]].push_back(i); 
	}
	fi[1]=true; 
	for(i=2;i<=n;++i) if(c[i]!=c[i-1]) fi[i]=true;
	sc[n]=true;
	for(i=n-1;i>0;--i) if(c[i]!=c[i+1]) sc[i]=true; 
	for(i=1;i<=n;++i){
		x=c[i];
		y=lower_bound(g[x].begin(),g[x].end(),i)-g[x].begin();
		for(;pos[x]<g[x].size();++pos[x]){
			if(pos[x]>=y) break;
			if(y-pos[x]==i-g[x][pos[x]]) break;
			if(fi[g[x][pos[x]]])
			  col[x]=ad(col[x],f[g[x][pos[x]]-1]);
		}
		if(sc[i]) f[i]=ad(f[i-1],col[x]);
		else f[i]=f[i-1];
	}
	printf("%d",(f[n])%mod);
	return 0;
}

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

int main(){
	string S, str = {};
	int w, temp, count = 0;
	
	cin>>S>>w;
	
	
	for(int i = 0; i < S.size(); i++){
		if(count == 0){
			cout<<S[i];
		}
		count++;
		if(count == w) count = 0;
	}
	
	
	return 0;
}

Measured memory_bytes: 256
l, r = gets.split.map(&:to_i)

cl = 0
cr = 0

m = 1000000000
l.upto([r, l + 2019].min) do |i|
  (i+1).upto([r, l + 2019].min) do |j|
    m = [(i * j) % 2019, m].min
  end
end

p m

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

long long A[100000];
long long diff_A[100000];
long long x[100000];
long long y[100000];
int main(){
    int N;
    cin >> N;

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

    for(int i = 0; i < N; i++){
        diff_A[i] = A[(i + 1) % N] - A[i];
    }
    long long sum_A = accumulate(A, A + N, (long long) 0);
    long long sum_N = (long long) N * (long long)(N + 1) / 2;

    if((sum_A % sum_N) != 0){
        cout << "NO" << endl;
        return 0;
    }
    long long op_num = sum_A / sum_N;

    for(int i = 0; i < N; i++){
        if((op_num - diff_A[i]) < 0 || (op_num - diff_A[i]) % N != 0){
            cout << "NO" << endl;
            return 0;
        }
        y[i] = (op_num - diff_A[i]) / N;
        x[i] = op_num - y[i];
    }
    cout << "YES" << endl;
    /*
    long long A0 = 0;
    for(int i = 0; i < N; i++){
        A0 += (N - i) * y[i];
    }
    if(A0 == A[0]){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    */
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MOD = 1000000007;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    ll sum = 0;
    rep(i, N) sum += a[i];
    set<ll> candidates;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            candidates.insert(i);
            candidates.insert(sum / i);
        }
    }
    ll ans = 1;
    for (ll x : candidates) {
        ll need;
        { // calc need
            vector<ll> r(N);
            rep(i, N) r[i] = a[i] % x;
            sort(r.begin(), r.end());
            ll B = 0; // 正にする回数
            rep(i, N) B += x - r[i];
            ll A = 0; // 負にする回数
            need = 1e18;
            rep(i, N) {
                // 正負の区切り位置を全部試す
                A += r[i];
                B -= x - r[i];
                if(A == B) need = min(need, A);
            }
        }
        if (need <= K) ans = max(ans, x);
    }
    cout << ans << endl;
}


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

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

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

typedef pair<long, long> P;

long GCD(long a, long b){
    if(b == 0) return a; 
    if(a < b) return GCD(b, a);
    else return GCD(b, a%b);
}

int main()
{   
    int N; cin >> N;
    int keta = N%10;
    if(keta == 3) cout << "bon" << endl;
    else if(keta == 0 || keta == 1 || keta == 6 || keta == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    /*
    int N; cin >> N;
    long A[200005], B[200005];
    REP(i, N) cin >> A[i] >> B[i];
    int bothzero = 0, azero = 0, bzero = 0, nonzero = 0;
    vector<P> ba(N), ab(N);
    REP(i, N){
        if(A[i] == 0l && B[i] == 0l) bothzero++;
        else if(A[i] == 0l && B[i] != 0l) azero++;
        else if(A[i] != 0l && B[i] == 0l) bzero++;
        else{
            long temp;
            temp = GCD(abs(A[i]), abs(B[i]));
            if(B[i]/temp > 0){
                ba[nonzero].first = B[i]/temp;
                ba[nonzero].second = A[i]/temp;
            }else{
                ba[nonzero].first = -B[i]/temp;
                ba[nonzero].second = -A[i]/temp;
            }

            if(A[i]/temp > 0){
                ab[nonzero].first = A[i]/temp;
                ab[nonzero].second = -B[i]/temp;
            }else{
                ab[nonzero].first = -A[i]/temp;
                ab[nonzero].second = B[i]/temp;
            }
            nonzero++;
        }
    }
    cout << nonzero << endl;
    REP(i, nonzero) cout << ab[i].first << " " << ab[i].second << endl;
    cout << endl;
    REP(i, nonzero) cout << ba[i].first << " " << ba[i].second << endl;

    long mod = 1000000007;
    long ans = 0l;
    ans += bothzero; ans %= mod;
    long temp;
    temp = azero*(azero-1l); temp %= mod;
    temp *= modinv(2l, mod); temp %= mod;
    ans += temp; ans %= mod;
    temp = (azero * nonzero) % mod;
    ans += temp; ans %= mod;
    temp = bzero*(bzero-1l); temp %= mod;
    temp *= modinv(2l, mod); temp %= mod;
    ans += temp; ans %= mod;
    temp = (bzero * nonzero) % mod;
    ans += temp; ans %= mod;
    */



    return 0;
}



Measured memory_bytes: 3576
n = int(input())
a = list(map(int,input().split()))

def gcb(a, b):
    while b!=0:
        a,b=b,a%b
    return a

for i in range(n - 1):
    a[i + 1] = gcb(a[i], a[i + 1])
    
print(a[n - 1])

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

void solve () {
    long long n;
    cin >> n;
    long long mn = 1e15 + 1;
    for (int i = 0; i < 5; i++) {
        long long x;
        cin >> x;
        if (mn > x) {
            mn = x;
        }
    }
    cout << (n % mn > 0) + (n / mn) + 4ll;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    string s;
    cin>>s;
    vector<int> al(3);
    rep(i,s.size()){
        int a=s[i]-'a';
        al[a]++;
    }
    sort(al.begin(),al.end());
    if(al[2]-al[0]<=1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
n=int(input())
edges=[[] for _ in range(n)]
dist=[0]*n
for i in range(n-1):
  u,v=map(int,input().split())
  u-=1
  v-=1
  edges[u].append(v)
  edges[v].append(u)
dist=[ [0]*n for _ in range(2)]
#do a dfs
def dfs(u,p,idd):#u=curr , p=par
  for nei in edges[u]:
    if nei==p:
      continue
    dist[idd][nei]=1+dist[idd][u]
    dfs(nei,u,idd)
dist[0][0]=0
dfs(0,0,0)
dist[1][n-1]=0
dfs(n-1,n-1,1)
cnt_f=cnt_s=0
for i in range(n):
  if dist[0][i]<=dist[1][i]:
    cnt_f+=1
  else:
    cnt_s+=1
print("Fennec") if cnt_f>cnt_s else print("Snuke")



Measured memory_bytes: 117408
#include <algorithm>
    #include <iostream>
    #include <vector>
    #include <string>
     
    using namespace std;
     
    int const N = 3e5 + 5;
    int cnt[N];
    int pr[N];
    vector<int> f;
    int n;
     
    bool check(long long k, long long t) {
        if (t * k > pr[n])
            return false;
        long long i = lower_bound(f.begin(), f.end(), t) - f.begin();
        if (pr[i] >= (i - (n - k)) * t)
            return true;
        else
            return false;
    }
     
    int bin_search(long long k) {
        int l = 0; int r = 3 * N;
        while(l < r) {
            int med = (l + r) / 2;
            if (check(k, med))
                l = med + 1;
            else
                r = med;
        }
        return l - 1;
    }
    int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        long long cpn;
        cin >> cpn;
        for (int i = 0; i < cpn; ++i) {
            long long x;
            cin >> x;
            ++cnt[x];
        }
        for (auto x : cnt) {
            if (x)
                f.push_back(x);
        }
        sort(f.begin(), f.end());
        n = f.size();
        for (int i = 0; i < f.size(); ++i)
            pr[i + 1] = pr[i] + f[i];
        for (int i = 1; i <= cpn; ++i) {
            if (i > f.size()) {
                cout << 0 << '\n';
                continue;
            }
            cout << bin_search(i) << '\n';
        }
        return false;
    }

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

int main(){
  string s;
  cin >> s;
  string ss = s;
  reverse(ss.begin(), ss.end());
  for (int i = 0; i < ss.size(); i++) {
    if (ss[i] == 'b') ss[i] = 'd';
    else if (ss[i] == 'd') ss[i] = 'b';
    else if (ss[i] == 'p') ss[i] = 'q';
    else if (ss[i] == 'q') ss[i] = 'p';
  }
  cout << (ss == s? "Yes" : "No") << endl;
  return 0;
}


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

signed main() {
  int N;
  cin >> N;
  
  string V = "Vacant";
  string M = "Male";
  string F = "Female";
  
  string start;
  cout << 0 << endl;;
  cin >> start;
  if( start == V ) return 0;
  
  int ng = 0;
  int ok = N;
  string S;
  while( ok-ng > 1 ){
    int mid = (ok+ng)/2;
    cout << mid << endl;
    cin >> S;
    if( S == V ) return 0;
    //偶数番目なのに最初と等しいor奇数番目なのに最初と違う場合
    if( (S == start && mid%2 == 1) || (S != start && mid%2 == 0) ){
      ok = mid;
    }else ng = mid;
  }
  
}


Measured memory_bytes: 852
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;

int main(void){
    int N;
        cin >> N;
    double v[N];
    double ans=0;
    for(int i=0; i<N; i++){
        cin >> v[i];
    }
    sort(v,v+N);
    ans=(v[0]+v[1])/2;
    for(int i=2; i<N; i++){
        ans+=v[i];
        ans/=2;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long x;cin>>x;
	for(long i=0,n=100l;;i++)
	{
		if(n>=x)
		{
			cout<<i<<endl;
			return 0;
		}
		else n+=n/100l;
	}
	return 0;
}


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

int main() {
    int n, A[100];
    cin >> n;
    for(int i = 0; i < n; i++)cin >> A[i];

    for(int i = n-1; i >= 0; i--) {
        if(i != n-1) cout << " ";
        cout << A[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3072
#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<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;
int N=1<<18;
class StarrySkyTree{
public:
  ll Ma[555555],A[555555];
  void init(){memset(Ma,0,sizeof(Ma)),memset(A,0,sizeof(A));}
  void add(int a,int b,ll x,int k=0,int l=0,int r=N) {
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b){
      A[k]+=x;
      while(k){
        k=(k-1)/2;
        Ma[k]=max(Ma[k*2+1]+A[k*2+1],Ma[k*2+2]+A[k*2+2]);
      }
      return;
    }
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
  ll getMax(int a,int b,int k=0,int l=0,int r=N) {
    if(r<=a||b<=l)return -MAXL;if(a<=l&&r<=b)return Ma[k]+A[k];
    ll left=getMax(a,b,k*2+1,l,(l+r)/2),right=getMax(a,b,k*2+2,(l+r)/2,r);
    return max(left,right)+A[k];
  }
};

StarrySkyTree t;
void Main() {
  t.init();
  int n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll ans=0;
  rep(i,n) {
    if(i) t.add(0,i,-(a[i].F-a[i-1].F));
    t.add(0,i+1,a[i].S);
    ans=max(ans,t.getMax(0,i+1));
  }
  pr(ans);
}

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


Measured memory_bytes: 12032
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	int N;
	cin >> N;
	cout << (N * 800) - (N / 15 * 200) << endl;
	return 0;
}

Measured memory_bytes: 256
n = input()
a=n[0]
b=n[1]
c=n[2]
A = 0
B = 0
if a=='A':
	A =+ 1
else:
	A = A 
if b=='A':
	A =+ 1
else:
	A = A 	
if c=='A':
	A =+ 1
else:
	A = A 

if a=='B':
	B =+ 1
else:
	B = B 
if b=='B':
	B =+ 1
else:
	B = B 
if c=='B':
	B =+1
else:
	B = B 

if A>0 and B>0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 100005;
const int mod = 1e9 + 7;
ll a[maxn];
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    ll sum = 0;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            sum += a[i];
        }
    }
    ll tmp = 0, ans = 0;
    for (int i = 1 ; i <= k ; i++) {
        tmp += a[i];
        if (a[i] > 0) {
            sum -= a[i];
        }
    }
    ans = max(ans, max(tmp + sum, sum));
    for (int i = 2 ; i <= n - k + 1 ; i++) {
        tmp -= a[i - 1];
        tmp += a[k + i - 1];
        if (a[i - 1] > 0) {
            sum += a[i - 1];
        }
        if (a[i + k - 1] > 0) {
            sum -= a[i + k - 1];
        }
        ans = max(ans, max(tmp + sum, sum));
    }
    cout << ans << '\n';
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,k,r,s,p;
  cin>>n>>k>>r>>s>>p;
  string t,t2;cin>>t;
  t2=t;

  map<char, int> points;
  points['r'] = r;points['s'] = s;points['p'] = p;
  map<char, char> wins;
  wins['s'] = 'r';wins['p'] = 's';wins['r'] = 'p';

  ll ans=0;
  for(int i=0;i<n;i++){
    int pv = i-k;
    char w = wins[t[i]];
    if(pv<0 || t2[pv]!=w){
      ans += points[w];
      t2[i] = w;
    } else{
      t2[i]='*';
    }
  }
  cout<<ans<<endl;


  return 0;
}


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

int main() {
	int mat[2][100] = {};
	int N;
	cin >> N;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < N; j++) {
			cin >> mat[i][j];
		}
	}
	if (N == 1) {
		cout << mat[0][0] + mat[1][0] << endl;
		return 0;
	}
	int sum[2][100] = {};
	sum[0][0] = mat[0][0];
	for (int i = 1; i < N; i++) {
		sum[0][i] = sum[0][i - 1] + mat[0][i];
	}
	sum[1][0] = sum[0][0] + mat[1][0];
	for (int i = 1; i < N; i++) {
		sum[1][i] = max((sum[1][i-1] + mat[1][i]), (sum[0][i] + mat[1][i]));
	}
	cout << sum[1][N - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

vector<long long> fact(3000,1);
void factorial(int N){
    for(int i=1; i<N; i++){
        fact[i+1]=(i+1)*fact[i]%MOD;
    }
}

map<long long, long long> inv_fact;
long long inv_factorial(long long x){
    if (inv_fact.count(x)){
        return inv_fact[x];
    }
    long long p=MOD-2;
    long long ret=1;
    long long tmp=x;
    while(p>0){
        if(p%2==1)ret=ret*tmp%MOD;
        tmp=tmp*tmp%MOD;
        p/=2;
    }
    inv_fact[x]=ret;
    return ret;
}

vector<long long> inv(3000,1);
long long inv_factorial2(long long x){
    for(int i=2; i<x; i++){
        inv[i]=-MOD/i*inv[MOD%i]%MOD;
        inv[i]=(inv[i]+MOD)%MOD;
    }
}

long long comb(int a, int b){
    long long ret=fact[a]*inv[fact[a-b]]%MOD;
    return ret*inv_factorial(fact[b])%MOD;
}

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int p;
    cin >> p;
    vector<int> ans(p,0);
    MOD=p;
    factorial(2999);
    inv_factorial2(2999);


    for(int i=0; i<p; i++){
        int a;
        cin >> a;

        if(a==0)continue;
        ans[0]+=1;
        int tmp=1;
        for(int j=0; j<p; j++){
            ans[p-j-1]-=comb(p-1, p-1-j)*tmp;
            ans[p-j-1]%=p;
            tmp*=-i;
            tmp%=p;
        }
    }

    for(int i=0; i<p; i++){
        ans[i]+=p;
        ans[i]%=p;
    }

    cout_vec(ans);
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
#include <functional>
#include <map>

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::list<unsigned> l;

  std::map<std::string,std::function<void(void)>> funcs{
    {
      "insert",
      [&l](){
        unsigned i;
        std::cin >> i;
        l.push_front(i);
      }
    },
    {
      "delete",
      [&l](){
        unsigned i;
        std::cin >> i;
        auto it = std::find(l.begin(),l.end(),i);
        if(it != l.end()) l.erase(it);
      }
    },
    {
      "deleteFirst",
      [&l](){
        l.erase(l.begin());
      }
    },
    {
      "deleteLast",
      [&l](){
        l.erase(--(l.end()));
      }
    }
  };

  unsigned n;
  std::string buf;
  std::cin >> n;
  for(;n;n--){
    std::cin >> buf;
    funcs[buf]();
  }

  std::cout << *(l.begin());
  for(auto it = ++l.begin(); it != l.end(); ++it){
    std::cout << ' ' << *it;
  }
  std::cout << '\n';

}

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

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

  vector<int> I(N);
  rep(i, N) cin >> I.at(i);

  int max_I = 0;
  rep(i, N) max_I = max(max_I, I.at(i));

  vector<int> P(max_I, 0);
  rep(i, max_I)
  {
    rep(j, N) P.at(i) += (i + 1 - I.at(j)) * (i + 1 - I.at(j));
  }

  int min_P = 1000000000;
  rep(i, max_I) min_P = min(min_P, P.at(i));

  cout << min_P << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int N,a[200000],flag=1;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
	scanf("%d",&a[i]);
	sort(a,a+N);
	for(int i=N-1;i>0;i--)
	{
		if(a[i]==a[i-1])
		{
			flag=0;
			break;
		}
	}
	if(flag==1)	printf("YES\n");
	else	printf("NO\n");
}


Measured memory_bytes: 1024
import heapq

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

heapq.heapify(a)
for _ in range(m):
    heapq.heappush(a, -(-heapq.heappop(a)//2))
print(-sum(a))


Measured memory_bytes: 14180
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define int long long
#define ll long long
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = 1e-9;
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;
}
using namespace std;
inline ll gcd(ll a, ll b) {
	while (b) {
		ll c = a;
		a = b; b = c % b;
	}
	return a;
}
inline ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
bool isprime(ll n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
ll mypow(ll a, ll b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	ll memo = mypow(a, b >> 1);
	return memo * memo;
}
int h, w, m;
char s[11][1010], a[11][1010];
bool b[11];
int g[2][11][1010];
signed main() {
	cin >> h >> w >> m;
	rep(i, h) {
		rep(j, w) {
			cin >> s[i][j];
			if (s[i][j] == '1')g[0][i][j]++;
		}
	}
	rep(j, h) {
		rep(k, w)g[1][j][k] = g[0][j][k];
	}
	int res = INF;
	rep(i, (1 << (h - 1))) {
		int ans = 0;
		vector<vector<int>> vec;
		rep(j, h) {
			if (i & (1 << j)) {
				rep(k, w)g[1][j + 1][k] += g[1][j][k];
			}
			else {
				int cnt = 0;
				vector<int> v;
				rep(k, w)v.push_back(g[1][j][k]);
				vec.push_back(v);
				if (j != h - 1)ans++;
			}
		}
		vector<int> cnt;
		cnt.resize(vec.size(), 0);
		rep(j, w) {
			rep(k, vec.size()) {
				if (cnt[k] + vec[k][j] > m) {
					rep(l, vec.size()) {
						cnt[l] = vec[l][j];
						if (cnt[l] > m)goto kaage;
					}
					ans++;
					break;
				}
				else cnt[k] += vec[k][j];
			}
		}
		chmin(res, ans);
	kaage:;
		rep(j, h) {
			rep(k, w)g[1][j][k] = g[0][j][k];
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<char> C(N*2);
    vector<int> A(N*2);
    rep(i,2*N) cin >> C[i] >> A[i];
    
    vector<vector<int>> B(N+1, vector<int>(N+2));
    auto W = B;
    rep(i,2*N) {
        if (C[i]=='B') {
            for (int j = i+1; j < 2*N; j++) {
                if (C[j]=='B' and A[j] < A[i]) {
                    B[A[j]][N+1]++;
                }
                if (C[j]=='W') {
                    W[A[j]][A[i]]++;
                }
            }
        } else {
            for (int j = i+1; j < 2*N; j++) {
                if (C[j]=='W' and A[j] < A[i]) {
                    W[A[j]][N+1]++;
                }
                if (C[j]=='B') {
                    B[A[j]][A[i]]++;
                }
            }
        }
    }

    rep(i,N+1) {
        for (int j = N; j >= 0; j--) {
            B[i][j] += B[i][j+1];
            W[i][j] += W[i][j+1];
        }
    }
    
    vector<vector<ll>> dp(N+1, vector<ll>(N+1,1e18));
    dp[0][0] = 0;
    rep(i,N+1) {
        rep(j,N+1) {
            if (i < N) chmin(dp[i+1][j],dp[i][j]+B[i+1][j+1]);
            if (j < N) chmin(dp[i][j+1],dp[i][j]+W[j+1][i+1]);
        }
    }

    cout << dp[N][N] << ln;
}

Measured memory_bytes: 63104
#include <iostream>
#define LL long long
using namespace std;

LL a,b;

int main(){
    cin >> a >> b;
    if (a<=0 && 0<=b){
        cout << "Zero\n";
        return 0;
    }

    if (a>0) cout << "Positive\n";
    else{
        if ((b-a)%2==1) cout << "Positive\n";
        else cout << "Negative\n";
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
namespace BeginnerContest_100_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hoge = Console.ReadLine().Split(' ');
            int n = int.Parse(hoge[0]);
            int m = int.Parse(hoge[1]);
            long[,] x = new long[n,3];
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                string[] fuge = Console.ReadLine().Split(' ');
                x[i,0] = long.Parse(fuge[0]);
                x[i,1] = long.Parse(fuge[1]);
                x[i,2] = long.Parse(fuge[2]);
            }

            for (int i = 0; i < 8; i++)
            {
                long temp = 0;
                var sum = new List<long>();
                for (int j = 0; j < n; j++)
                {
                    long thisScore = 0;
                    for (int k = 0; k < 3; k++)
                    {
                        if (((i >> k) & 1) == 1) thisScore += x[j,k];
                        else thisScore -= x[j,k];
                    }
                    sum.Add(thisScore);
                }
                sum.Sort();
                for(int l = n - 1; l > n - m - 1; l--)
                {
                    temp += sum[l];
                }
                if (temp > ans) ans = temp;
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 999999;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

#define Endl endl
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define all(x) x.begin(),x.end()
#define atcoder(int)1e9+7
#define rep(i,n) for(int i = 0;i<n;i++)
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)


ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

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

int  main() {
	
	ll n, t,ans =0;
	vector<ll> v;

	cin >> n >> t;

	rep(i, n) {
		ll a;
		cin >> a;
		v.pb(a);
	}

	
	rep(i, n - 1) {
		ans += min(v[i + 1] - v[i], t);
	}
	ans += t;
	pr(ans);

	return 0;

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define For(i, l, r) for(register int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(register int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;
inline bool chkmin(int &a,int b){
	return b < a ? a = b, 1:0;
}
inline bool chkmax(int &a,int b){
	return b > a ? a = b, 1:0;
}
const int N=100100;
int tag[N][31];
int Las,n,c,s,t,cnt;
int main () {
	scanf("%d%d",&n,&c);
	For(i,1,n){
		scanf("%d%d%d",&s,&t,&cnt);
		chkmax(Las,t);
		++tag[s][cnt];
		--tag[t+1][cnt];
	}
	int lol[31]={0},ans = 0;
	For(i,1,Las){
		int now=0;
		For(j,1,c){
			lol[j]+=tag[i][j];
			if (lol[j])++now;
		}
		chkmax(ans,now);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 12416
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

const INF: usize = 1_000_000_000;

fn permutation(n: usize) -> Vec<Vec<usize>> {
    let mut incl = n - 1;
    let mut temp = vec![0; n];
    let mut ret = Vec::new();

    while incl > 0 || temp[0] < n - 1 {
        if temp[incl] == n - 1 {
            temp[incl] = 0;
            incl -= 1;
            continue;
        }

        temp[incl] += 1;
        incl = n - 1;
        let mut flg = true;
        let mut test = vec![0; n];
        for &e in temp.iter() {
            if test[e] == 1 {
                flg = false;
                break;
            } else {
                test[e] = 1;
            }
        }

        if flg { ret.push(temp.clone()) }
    }

    ret
}

fn main() {
    let nmr = readn::<usize>(" ");
    let n = nmr[0];
    let m = nmr[1];
    let r = nmr[2];

    let rs = readn::<usize>(" ");
    let mut dp = vec![vec![vec![INF; n]; n]; n+1];
    for i in 0..n {
        dp[0][i][i] = 0;
    }
    for _ in 0..m {
        let abc = readn::<usize>(" ");
        let a = abc[0] - 1;
        let b = abc[1] - 1;
        let c = abc[2];
        dp[0][a][b] = c;
        dp[0][b][a] = c;
    }

    for k in 1..n+1 {
        for i in 0..n {
            for j in 0..n {
                dp[k][i][j] = std::cmp::min(dp[k-1][i][j], dp[k-1][i][k-1] + dp[k-1][k-1][j]);
            }
        }
    }

    let p = permutation(r);
    let mut minl = INF;
    for v in p.iter() {
        let mut cand = 0;
        for i in 0..r-1 {
            cand += dp[n][rs[v[i]] - 1][rs[v[i+1]] - 1];
        }
        minl = std::cmp::min(minl, cand);
    }

    println!("{}", minl);
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

const int SIZE = 200010;

vector<int> dist(SIZE, -1);
vector<int> edges[SIZE];

// Returns the farthest node from the start.
// O(N)
int bfs(int start) {
    queue<int> q;
    q.push(start);

    dist.assign(SIZE, -1);
    dist[start] = 0;

    int cur = -1;
    while (!q.empty()) {
        cur = q.front();
        q.pop();

        for (int next : edges[cur]) {
            if (dist[next] == -1) {
                dist[next] = dist[cur] + 1;
                q.push(next);
            }
        }
    }

    return cur;
}

// Returns the length of the diameter of the tree.
// O(N)
int calcTreeDiameter(int root) {
    int far1 = bfs(root);
    int far2 = bfs(far1);
    return dist[far2];
}

int main() {
    int N, s;
    cin >> N;
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        if (i == 0)s = a;
    }

    int d = calcTreeDiameter(s);
    cout << ((d % 3 == 1) ? "Second" : "First") << endl;

    return 0;
}

Measured memory_bytes: 13556
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


N = int(input())
A = lmi()
Ay = [a - i for i, a in enumerate(A)]
Ax = [a + i for i, a in enumerate(A)]
# print(Ax,Ay)

d = collections.defaultdict(int)
ans  =0
for i in range(N):
    # check Ay
    ans += d[Ay[i]]
    # update d
    d[-Ax[i]] += 1
print(ans)


Measured memory_bytes: 71924
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	int n;
	int u,k,v;
	int[][] list;
	
	int[] ans;
	int[] color;
	
	Queue<Integer> Q = new ArrayDeque<Integer>();
	
	public void input() {
		n = sc.nextInt();
		list = new int[n][n];
		ans =  new int[n];
		color = new int[n];
		Arrays.fill(ans,-1);
		Arrays.fill(color,0);
		for(int i=0; i<n; i++) {
			u = sc.nextInt();
			k = sc.nextInt();
			while(k > 0) {
				v = sc.nextInt();
				list[u-1][v-1] = 1;
				k--;
			}
		}
	}

	public void bfs() {
		Q.add(0);
		ans[0] = 0;
		while(Q.size() != 0) {
			int u = Q.poll();
			for(int i=0; i<n; i++) {
				if(list[u][i] == 1 && color[i] == 0) {
					color[i] = -1;
					ans[i] = ans[u] +1;
					Q.add(i);
				}
			}
			color[u] = 1;
		}
	}
	
	public void output() {
		for(int i=0; i<n; i++) { System.out.println(i+1+" "+ans[i]); }
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.input();
		obj.bfs();
		obj.output();
	}
}



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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int x;
void solve(){
	cin >> x;
	
	i64 ans = 0, cnt = 0;
	for(int i = 1; i <= x && cnt < x; i++){
		cnt += i;
		ans++;
	}
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main(){
  ll n, d;
  cin >> n >> d;
  ll ans=0;
  rep(i,n){
    ll x, y;
    cin >> x >> y;
    if(x*x+y*y <= d*d) ans ++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
import itertools
import math
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

town = [i for i in range(n)]
route = list(itertools.permutations(town,n))
dis = 0
for i in route:
    for j in range(n-1):
        dis += math.sqrt((xy[i[j]][0] - xy[i[j+1]][0])**2 + (xy[i[j]][1] - xy[i[j+1]][1])**2)

print(dis/len(route))

Measured memory_bytes: 10020
# Author: cr4zjh0bp
# Created: Sun Mar 22 22:02:37 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import Counter
import string

s = ns()
c = Counter(s)
d = dict(c)

ans = '$'
for i in range(len(string.ascii_lowercase)):
    if d.get(string.ascii_lowercase[i], 0) == 0:
        ans = string.ascii_lowercase[i]
        break
print("None" if ans == "$" else ans)

Measured memory_bytes: 3832
#include<bits/stdc++.h> 
#define ll long long 
#define ld long double
using namespace std;
const int N = 1e5+5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;cin>>n;
	int s[n+1];

	int a[n];
	for(int i = 0; i < n; i++)
		cin>>a[i];

	for(int i = 1; i <= n; i++)
		cin>>s[i];

	int c[n];

	for(int i = 1; i < n; i++)
		cin>>c[i];

	int sum = 0;

	for(int i = 1; i <= n; i++)
		sum+=s[i];

	for(int i = 0; i < n-1; i++)
	{
		if(a[i]+1 == a[i+1])
			sum+=c[a[i]];
	}

	cout<<sum<<"\n";
	return 0;
}







Measured memory_bytes: 256
package main

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

type Dice struct {
	Faces []int
}

func NewDice(n []int) *Dice {
	return &Dice{
		Faces: n,
	}
}

func (d *Dice) move(direction string) {
	switch direction {
	case "E":
		d.Faces[0], d.Faces[2], d.Faces[5], d.Faces[3] =
			d.Faces[3], d.Faces[0], d.Faces[2], d.Faces[5]
	case "W":
		d.Faces[0], d.Faces[2], d.Faces[5], d.Faces[3] =
			d.Faces[2], d.Faces[5], d.Faces[3], d.Faces[0]
	case "N":
		d.Faces[0], d.Faces[1], d.Faces[5], d.Faces[4] =
			d.Faces[1], d.Faces[5], d.Faces[4], d.Faces[0]
	case "S":
		d.Faces[0], d.Faces[1], d.Faces[5], d.Faces[4] =
			d.Faces[4], d.Faces[0], d.Faces[1], d.Faces[5]
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	faces := make([]int, 6)
	for i, s := range strings.Split(sc.Text(), " ") {
		faces[i], _ = strconv.Atoi(s)
	}
	d := NewDice(faces)
	sc.Scan()
	inst := []rune(sc.Text())
	for _, r := range inst {
		d.move(string(r))
	}

	fmt.Println(d.Faces[0])
}



Measured memory_bytes: 1100