akhauriyash/Code-Regression huggingface dataset:
pi = 3.1415926

############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))
################################################################
n,k = invr()
nums = [0] + inlt()
cycle = [nums[1]]
s = set([cycle[0]])
bp = 0
for i in range(2*n):
    if nums[cycle[-1]] not in s:
        s.add(nums[cycle[-1]])
        cycle.append(nums[cycle[-1]])
        
    else:
        bp = nums[cycle[-1]]
        break

if k <= len(cycle):
    print(cycle[k - 1])
else:
    if bp != 0:
        for i in range(len(cycle)):
            if cycle[i] == bp:
                cycle = cycle[i:]
                break
    k -= i
    remain = k % len(cycle)
    print(cycle[remain - 1])

    


Measured memory_bytes: 126676
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

ans = 0
mod = 10 ** 9 + 7

for i in range(60):
    x, y = 0, 0
    B = A >> i & 1
    x = np.count_nonzero(B)

    y = N - x
    ans += (x * y) * (2 ** i)
print(ans%mod)

Measured memory_bytes: 48836
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int H, W;
    cin >> H >> W;

    int a[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
        }
    }

    vector<string> v;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(a[i][j] %2 == 0) continue;
            if(i == H-1 && j == W-1) continue;

            string ans = "";

            if(j != W-1){
                a[i][j+1]++;
                a[i][j]--;
                ans = to_string(i+1) + " " + to_string(j+1) + " " + to_string(i+1) + " " + to_string(j+2);
                v.push_back(ans);
                continue;
            }
            if(j == W-1){
                ans = to_string(i+1) + " " + to_string(j+1) + " " + to_string(i+2) + " " + to_string(j+1);
                v.push_back(ans);
                a[i][j]--;
                a[i+1][j]++;
                continue;
            }
        }
    }

    cout << v.size() << endl;
    for(auto l : v){
        cout << l << endl;
    }

    return 0;
}


Measured memory_bytes: 13556
from bisect import*
n,d,a,*t=map(int,open(0).read().split())
c=[0]*-~n
z=sorted(zip(*[iter(t)]*2))
s=0
for i,(x,h)in enumerate(z):
    c[i]+=c[i-1]
    h-=c[i]
    t=min(-h//a,0)
    c[i]-=t*a
    c[bisect(z,(x+d+d,10e9))]+=t*a
    s-=t
print(s)

Measured memory_bytes: 48852
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    ll x[1003] = {}, y[1003] = {}, r[1003] = {};
    double d[1003] = {};
    bool b[1003] = {};
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
    int n;
    cin >> x[0] >> y[0] >> x[1] >> y[1] >> n;
    x[n + 1] = x[1]; y[n + 1] = y[1];
    for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> r[i];
    for (int i = 1; i <= n + 1; i++) d[i] = 1ll * mod * mod;
    q.push({0, 0});
    while (!q.empty()) {
        int c = q.top().second;
        q.pop();
        if (b[c]) continue; b[c] = 1;
        for (int i = 0; i <= n + 1; i++) {
            double e = max(0.0, sqrt((x[c] - x[i]) * (x[c] - x[i]) + (y[c] - y[i]) * (y[c] - y[i])) - r[c] - r[i]);
            if (d[i] > d[c] + e + 1e-12) {
                d[i] = d[c] + e;
                q.push({d[i], i});
            }
        }
    }
    cout << setprecision(13) << d[n + 1];
}


Measured memory_bytes: 6256
n, m = map(int, input().split())
A = list(map(int, input().split()))

D0 = [0]*(2*m+10)
D1 = [0]*(2*m+10)
ans = 0

pa = A[0]-1
for a in A[1:]:
    a -= 1
    if a<pa:
        a += m
    ans += a-pa
    D1[pa+1] += 1
    D1[a] -= a-pa
    D1[a+1] += a-pa-1
    pa = a%m

for i, d1 in enumerate(D1):
    D0[i] = d1 + D0[i-1]

L = [0]*(2*m+10)

for i, d0 in enumerate(D0):
    L[i] = d0 + L[i-1]

for i, l in enumerate(L[m:]):
    L[i%m] += l

print(ans-max(L[:m]))


Measured memory_bytes: 28748
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 


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













bool compare(pi a,pi b){
     if(a.fi-a.se>b.fi-b.se)return  true;
     else if(a.fi-a.se==b.fi-b.se&&a.se<b.se)return true;
     return false;
}




const int N=1000005;
int pr[1000005];
int main()
{
     int n;
     cin>>n;
     int a[n],b[n];
     ll suma=0,sumb=0;
     for(int i=0;i<n;i++){cin>>a[i];suma+=a[i];}
     for(int i=0;i<n;i++){cin>>b[i];sumb+=b[i];}
     if(suma>sumb){cout<<"No";return 0;}
     ll dif=0;
     for(int i=0;i<n;i++){
          if(a[i]<b[i]){
               dif+=(b[i]-a[i]+1)/2;
          }
     }
     if(dif<=sumb-suma)cout<<"Yes";
     else cout<<"No";

    

}




 
 

















Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(var) (var).begin(), (var).end()
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000;

	return 0;
}

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


int main() {
    ll n,k;
    cin>>n>>k;
    ll now=1001001001001001001;

    rep(i,1001){
        if(n>=k){
            n%=k;
            now=min(now,n);
            if(now==0){
                cout<<0<<endl;
                return 0;
            }
        }
        else{
            n=k-n;
            now=min(now,n);
        }
    }
    cout<<now<<endl;
    return 0;
}

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

int solve(){
  int res=0,nlen=n.size(),memo[12][12]={};
  memset(memo,-1,sizeof(memo));
  vector <int> a,b;
  queue <int>Q[12][12];
  a.push_back(n[0]-'0'),a.push_back(n[0]-'0'),b.push_back(0);
  for(int i=2;i<nlen;i+=2) a.push_back((a.back()+n[i]-'0')%11),a.push_back(a.back());
  for(int i=1;i<nlen;i+=2) b.push_back((b.back()+n[i]-'0')%11),b.push_back(b.back());
  if(nlen%2==0) b.erase(--b.end());
  else a.erase(--a.end());
  
  for(int i=0,A=0,B=0;i<nlen-1;i++){
    if(n[i]=='0')continue;
    if(memo[A][B]==-1){
      memo[A][B]=0;
      for(int j=i+1;j<nlen;j++)
	if(((a[j]+A)-(b[j]+B))%11==0) memo[A][B]++,Q[A][B].push(j);
    }
    while(!Q[A][B].empty()&&Q[A][B].front()<i)Q[A][B].pop(),memo[A][B]--;
    res+=memo[A][B];

    if(i%2==0)A=11-a[i]%11;
    else B=11-b[i]%11;
  }  
  return res;
}


int main(){
  while(1){
    cin>>n;
    if(n=="0")break;
    cout<< solve()<<endl;
  }
  return 0;
}

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

A = []
max1 = 0
max1i = 0
max2 = 0
max2i = 0

for i in range(N):
  B = int(input())
  if B>max1:
    max1i = i
    max1 = B
  else:
    if B>max2:
      max2 = B
      max2i = i

for i in range(N):
  A.append(max1)
A[max1i] = max2

for i in range(N):
  print(A[i])




Measured memory_bytes: 6136
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int t,x;
	cin>>t>>x;
	cout<<(double)t/(double)x<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
int main() {
  cin >> n;
  double x = 0;
  for (i64 i = 1; i <= n; ++i) x += i % 2 == 1;
  printf("%.10f\n", x / n);
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int a,b;

  scanf("%d%d",&a,&b);

  if(a < b)

  {printf("a < b\n");

   }

  else if(a > b)

  {printf("a > b\n");

   }

  else

  {printf("a == b\n");

}

return 0;

}

Measured memory_bytes: 580
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

typedef pair<lint, VEC(int)> Entry;

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    VEC(lint) A(X), B(Y), C(Z);
    READVEC(A); sort(ALL(A));
    READVEC(B); sort(ALL(B));
    READVEC(C); sort(ALL(C));

    priority_queue<Entry> pq;
    set<VEC(int)> seen;

    auto heapAdd = [&](int x, int y, int z) {
        if (x < 0 || y < 0 || z < 0)
            return;

        VEC(int) tuple{x, y, z};
        if (seen.count(tuple))
            return;
        seen.insert(tuple);
        pq.push(PAIR(A[x] + B[y] + C[z], tuple));
    };

    heapAdd(X - 1, Y - 1, Z - 1);
    while (K--) {
        auto pr = pq.top();
        pq.pop();
        auto& i = pr.second;
        cout << pr.first << endl;
        int x = i[0], y = i[1], z = i[2];
        heapAdd(x - 1, y, z);
        heapAdd(x, y - 1, z);
        heapAdd(x, y, z - 1);
    }
    return 0;
};


Measured memory_bytes: 1280
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# MOD = 998244353


A, B, C = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(3)]
A = list(map(ord, A))
B = list(map(ord, B))
C = list(map(ord, C))

memo = {}
Q = ord('?')


def get_ok_idx(A, B):
    key = str(A) + str(B)
    if key in memo:
        return memo[key]
    ret = []
    for i in range(len(A) + 1):
        for a, b in zip(A[i:], B):
            if a != b and a != Q and b != Q:
                break
        else:
            ret.append(i)
    memo[key] = ret
    return ret


# A = np.array(A, dtype=int)
# B = np.array(B, dtype=int)
# C = np.array(C, dtype=int)

def solve(A, B, C):
    ok_ab = get_ok_idx(A, B)
    ok_bc = get_ok_idx(B, C)
    ok_cb = get_ok_idx(C, B)
    ok_ac = get_ok_idx(A, C)

    ok_ab_flags = [False] * (len(A) + 1)
    ok_bc_flags = [False] * (len(B) + 1)
    ok_cb_flags = [False] * (len(C) + 1)
    ok_ac_flags = [False] * (len(A) + 1)
    for i in ok_ab:
        ok_ab_flags[i] = True
    for i in ok_bc:
        ok_bc_flags[i] = True
    for i in ok_cb:
        ok_cb_flags[i] = True
    for i in ok_ac:
        ok_ac_flags[i] = True

    ret = INF
    for ab, bc in itertools.product(ok_ab, ok_bc):
        if ab + bc >= len(A) or ok_ac_flags[ab + bc]:
            ret = min(ret, max(len(A), ab + len(B), ab + bc + len(C)))
    for ac, bc in itertools.product(ok_ac, ok_bc):
        if ac - bc < 0:
            continue
        if ac - bc >= len(A) or ok_ab_flags[ac - bc]:
            ret = min(ret, max(len(A), ac - bc + len(B), ac + len(C)))
    for ab, ac in itertools.product(ok_ab, ok_ac):
        if ab < ac and (ac - ab >= len(B) or ok_bc_flags[ac - ab]):
            ret = min(ret, max(len(A), ab + len(B), ac + len(C)))
        elif ac < ab and (ab - ac >= len(C) or ok_cb_flags[ab - ac]):
            ret = min(ret, max(len(A), ab + len(B), ac + len(C)))
    return ret


ans = len(A) + len(B) + len(C)
ans = min(ans, solve(A, B, C))
ans = min(ans, solve(A, C, B))
ans = min(ans, solve(B, A, C))
ans = min(ans, solve(B, C, A))
ans = min(ans, solve(C, A, B))
ans = min(ans, solve(C, B, A))
print(ans)


Measured memory_bytes: 63964
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll read() {
	char c = getchar();
	ll x = 0, f = 1;
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (; isdigit(c); c = getchar())
		x = x * 10 + c - 48;
	return x * f;
}
const int N = 1e5 + 5;
ll a[N] = { 0 }, s[N], b[N] = { 0 }, n, n2, maxi, sum, flag = 0;
int main()
{
	n = read();
	for (ll i = 0; i <= n; ++i)
		a[i] = read();
	s[0] = a[0];
	if (n == 0)
		if (a[0] == 1){
			cout << 1 << endl;
			return 0;
		}
		else{
			printf("-1");
			return 0;
		}
	for (ll i = 1; i <= n; ++i)
		s[i] = a[i] + s[i - 1];{
		n2 = 1;
		if (a[0] != 0){
			for (ll i = 1; i <= n; ++i){
				if (a[i] != 0){
					cout << -1 << endl;
					return 0;
				}
			}
			b[0] = n2;
		}
		else{
			if (n == 0){
				cout << -1 << endl;
				return 0;
			}
			else
				b[0] = n2;
		}
	}
	for (unsigned long long i = 1; i <= n; i++){
		if (flag == 0){
			n2 = n2 * 2;
			if (a[i] > n2){
				cout << -1 << endl;
				return 0;
			}
			else{
				maxi = s[n] - s[i - 1];
				if (maxi <= n2){
					flag = 1;
					n2 = maxi;
					b[i] = n2;
					n2 = n2 - a[i];
				}
				else{
					b[i] = n2;
					n2 = n2 - a[i];
				}
			}
		}
		else{
			b[i] = n2;
			n2 = n2 - a[i];
		}
	}
	for (ll i = 0; i <= n; ++i)
		sum += b[i];
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 5920
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define inf 0x7fffffff
#define llinf 0x7fffffffffffffffll
using namespace std;
string s,t;
char a[30]={0},b[30];
int main()
{
	int i,j,k,n,m,x,y;
	cin>>s>>t;
	for(i=0;i<s.length();i++)
	{
		if(a[s[i]-'a']==0)
		{
			a[s[i]-'a']=t[i];
		}
		if(a[s[i]-'a']!=t[i])
		{
			printf("No");
			return 0;
		}
		if(b[t[i]-'a']==0)
		{
			b[t[i]-'a']=s[i];
		}
		if(b[t[i]-'a']!=s[i])
		{
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 776
N=int(input())
list1=[]
for i in range(1001):
    list1.append(0)

for j in range(1,N+1):
    A=j
    for k in range(2,N+1):
        for l in range(11):
            if A%k==0:
                list1[k]+=1
                A=A/k
            else:
                break
ans=1
for m in range(1,len(list1)):
    if list1[m]==0:
        pass
    else:
        ans*=list1[m]+1
        if ans>=10**9+7:
            ans=ans%(10**9+7)
            
print(ans)


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

int main(){
  long long n,k;
  cin >> n >> k;

  long long amari = n % k;
  long long amari2 = abs(amari - k);

  long long minnn = min(amari,amari2);
  minnn = min(minnn, n);

  cout << minnn << endl;
}


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

int main() {
	int k;
	cin >> k;
	if (k % 2 == 1) {
		cout << k / 2 * (k / 2 + 1) << endl;
	}
	else {
		cout << k / 2 * k / 2 << endl;
	}
	return 0;
}

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

int main (void) {
    int N;
    cin >> N;
    
    vector<pair<string, int>> eval(N);
    vector<pair<string, int>> eval_sorted(N);

    for (int i = 0; i < N; i++){
        string s;
        int p;
        cin >> s >> p;
        
        eval.at(i) = eval_sorted.at(i) = make_pair(s, -p);
    }
    sort(eval_sorted.begin(), eval_sorted.end());
    for (auto e : eval_sorted) {
        for (int i = 0; i < N; i ++) {
            if (e == eval.at(i)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
    
}

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

using namespace std;

string rotate(string str, int len)
{
  return str[len - 1] + str.substr(0, len - 1);
}

int main()
{
  string str1, str2;
  cin >> str1 >> str2;

  int len = str1.length();

  string str = str1;
  for (int i = 0; i < len; ++i)
  {
    if (str == str2)
    {
      cout << "Yes" << endl;
      return 0;
    }

    str = rotate(str, len);
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  vector<vector<vector<pii>>> A(N,vector<vector<pii>>(N));
  vii C(N,vi(N));
  rep(i,0,N){
    vi B(N-1);
    rep(j,0,N-1) cin>>B[j];
    rep(j,1,N-1){
      int P=i,Q=B[j]-1,R=B[j-1]-1,S=i;
      if(P>Q) swap(P,Q);
      if(S>R) swap(S,R);
      A[S][R].pb(mp(P,Q));
      C[P][Q]++;
    }
  }
  stack<pii> Q;
  rep(i,0,N){
    rep(j,i+1,N){
      if(C[i][j]==0) Q.push(mp(i,j));
    }
  }
  vector<pii> D;
  while(Q.size()>0){
    int X=Q.top().first,Y=Q.top().second;
    Q.pop();
    D.pb(mp(X,Y));
    rep(i,0,A[X][Y].size()){
      int P=A[X][Y][i].first,R=A[X][Y][i].second;
      C[P][R]--;
      if(C[P][R]==0) Q.push(mp(P,R));
    }
  }
  if(D.size()==N*(N-1)/2){
    vii dp(N,vi(N,1));
    rep(i,0,D.size()){
      int X=D[i].first,Y=D[i].second;
      rep(j,0,A[X][Y].size()){
        int P=A[X][Y][j].first,R=A[X][Y][j].second;
        dp[P][R]=max(dp[P][R],dp[X][Y]+1);
        }
      }
    int ans=0;
    rep(i,0,N){
      rep(j,0,N) ans=max(ans,dp[i][j]);
      }
    cout<<ans<<endl;
  }
  else cout<<-1<<endl;
  }



Measured memory_bytes: 72552
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
 
#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
 
#define MOD 1000000007
void init();
void solve();

signed main()
{
	init();
	solve();
}

bool dp[5010][10010];
vector<int> A;
int N, K;

void init()
{
	cin >> N >> K;
	rep(i, N) {
		int t;
		cin >> t;
		if (t < K) A.PB(t);
	}
	N = A.size();
	sort(all(A));
}

inline bool isok(int pos)
{
	if (pos == -1) return false;
	if (pos == N) return true;
	bool dp[2][5010];
	rep(i, 2) rep(j, 5010) dp[i][j] = false;
	dp[0][0] = true;
	int now = 1;
	rep(i, N) {
		if (i == pos) continue;
		int pre = 1 - now;
		rep(j, K) {
			if (dp[pre][j]) {
				dp[now][j] = true;
				if (j + A[i] < K) {
					dp[now][j+A[i]] = true;
					if (j + A[i] >= K - A[pos]) return true;
				}
			}
		}
		now = pre;
	}
	return false;
}

void solve()
{
	int ok = N;
	int ng = -1;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		if (isok(mid)) ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String split[] = line.split(" ", 0);
        int W =Integer.parseInt(split[0]);
        int H =Integer.parseInt(split[1]);
        int x =Integer.parseInt(split[2]);
        int y =Integer.parseInt(split[3]);
        int r =Integer.parseInt(split[4]);
        
        if (0<=x&&x+r<=W&&0<=y&&y+r<=H) {
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 17080
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
#define INF 1000000000

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define contains(a, x) (a.find(x) != end(a))
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)

using dbl = double;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvl = vector<long long>;
using pi = pair<int,int>;

#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
// #define log(x) cout << x << endl;


int dc(int a,int b) {
	int c = 0, d = 0;
	while (a) c+=1, a/=10;
	while (b) d+=1, b/=10;
	return max(c,d);
}

// int dc2(int a, int b) {
// 	dbl c = log(a)/log(10);
// 	dbl d = log(b)/log(10);
// 	return max(c+1,d+1);
// }


int main() {
	srand(time(NULL));

	ll n,a,b,mn=INF;
	cin >> n;

	for (int i=1; i<=sqrt(n); ++i) {
		a = i, b = n/i;
		if (a*b!=n) continue;
		mn = min<ll>(mn, dc(a, b));
	}

	cout << mn;

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long m,n,res=0,i,j=0;
cin>>n;
for(i=1;;i++)
{
    res+=i;
    if(res>=n)
    {
        m=i;
        break;
    }

}
cout<<m<<endl;

return 0;
}



Measured memory_bytes: 256
def resolve():
    
    N=int(input())
    A=list(map(int,input().split()))

    d={}
    for i in range(N):
        d[A[i]]=i+1

    dict2=sorted(d.items())

    for i in range(N):
        print(dict2[i][1], end=" ")        


resolve()

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

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


int main()
{
    long long  l , r , I=1e9+9 , S=1e9+200;
    cin>>l>>r;
    for( long long  i=l ; i<l+2019 && i<r ; i++ )
    {

        for(long long  j=i+1 ; j<=l+2019 &&j<=r ; j++  )
        {
            S=min( S , ( ((j%2019)*( i%2019))%2019 ) );
        }
    }
    cout<<S<<endl;;
    return 0;
}


Measured memory_bytes: 256
// Aizu 1016: Fibonacci Sets
// 2017.9.17 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int f[1005], a[1005];

int cmp(int *a, int *b) { return *a - *b; }

int main()
{
	int V, d, i, ans;

	f[0] = 2, f[1] = 3; for (i = 2; i <= 1000; i++) f[i] = (f[i-1] + f[i-2]) % 1001;
	while (scanf("%d%d", &V, &d) == 2) {
		memcpy(a, f, sizeof(int)*V);
		qsort(a, V, sizeof(int), cmp);
		for (ans = 1, i = 1; i < V; i++) if (a[i] - a[i-1] >= d) ans++;
		printf("%d\n", ans);
	}
	return 0;
}

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

int main(){
    int N, count = 0, minj, s;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        minj = i;
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        if(i != minj){
            s = A[i];
            A[i] = A[minj];
            A[minj] = s;
            count++;
        }
    }
    for(int i = 0; i < N; i++){
        if(i == N - 1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
#define endl             "\n"
// -----------------<Container manipulation / traversal macros>------------------
#define mp                 make_pair
#define pb                 push_back
#define ff                 first
#define ss                 second
#define sz(x)             ((int)((x).size()))
#define all(x)             (x).begin(),(x).end()
#define rep(i,n)         for(ll (i)=0;(i)<(n);(i)++)
#define forn(i,a,b)     for(ll (i)=(a);(i)<=(b);(i)++)
#define fill(l,a)        memset((l) , (a) , sizeof(l))
// -----------------<Some common useful functions>------------------
#define maX(a,b)        ( (a) > (b) ? (a) : (b))
#define miN(a,b)        ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)   ( (n >> b) & 1)
#define INDEX(arr,i)      ( lower_bound(all(arr),i)-arr.begin())
#define in(b,a)         ( (b).find(a) != (b).end())
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
ll lcm(ll a,ll b)
{
    return(a/gcd(a,b)*b);
}
/*ll power(ll a,ll b,ll p)
{
    ll res=1;
    a%=p;
    while(b>0)
    {
        if(b&1)
        res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return(res);
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
    ll l=0,r=n-1;
    while(l<=r)
    {
        ll mid=l+(r-l)/2;
        if(arr[mid]==s)
        return(mid);
        if(arr[mid]<s)
        l=mid+1;
        else
        r=mid-1;
    }
    return(-1);
}*/
void solve()
{
    ll n;
    cin>>n;
    ll cnt=0;
    ll arr[15][15]={0},brr[15][15]={0};
    for(ll i=1;i<=n;i++)
    {
        ll c1=i%10;
        ll c2;
        ll c3=i;
        while(c3/10)
            c3/=10;
        c2=c3;
        arr[c1][c2]++;
        brr[c2][c1]++;
    }
    for(ll i=1;i<=9;i++)
    {
        for(ll j=1;j<=9;j++)
        {
            cnt+=arr[i][j]*brr[i][j];
        }
    }
    cout<<cnt<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
//const int MAX=;

int main(){
	int N,M,a,b;
	cin>>N>>M>>a>>b;
	
	if(N%a==0 && M%b==0)cout<<"No"<<endl;
	else if(N%a==0){
      	cout<<"Yes"<<endl;
		int c=M%b;
		int d=b-c;
		int k=((N-N%a)*(M-M%b))/(N*M-(N-N%a)*(M-M%b))+3;
		int va=k*d;
		int vb=-k*c-1;
		
		rep(i,N){
			rep(j,M){
				if(j%b<c)cout<<va<<" ";
				else cout<<vb<<" ";
			}
			cout<<endl;
		}
	}
	else if(M%b==0){
      	cout<<"Yes"<<endl;
		int c=N%a;
		int d=a-c;
		int k=((N-N%a)*(M-M%b))/(N*M-(N-N%a)*(M-M%b))+3;
		int va=k*d;
		int vb=-k*c-1;
		
		rep(i,N){
			rep(j,M){
				if(i%a<c)cout<<va<<" ";
				else cout<<vb<<" ";
			}
			cout<<endl;
		}
	}
	else{
      	cout<<"Yes"<<endl;
		int d=(a-N%a)*(b-M%b);
		int c=a*b-d;
		int k=((N-N%a)*(M-M%b))/(N*M-(N-N%a)*(M-M%b))+3;
		int va=k*d;
		int vb=-k*c-1;
		
		rep(i,N){
			rep(j,M){
				if(i%a>=N%a && j%b>=M%b)cout<<vb<<" ";
				else cout<<va<<" ";
			}
			cout<<endl;
		}
	}
}

Measured memory_bytes: 2176
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <set>
#include <map>
#include <queue>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, m, fa[N];
map<pair<int, int> , int> h; 
queue<pair<int, int> > q;
set<int> s[N];
pair<int, int> code(int x, int y) { return make_pair(min(x, y), max(x, y)); }
int find(int x) { return fa[x] == x?x:fa[x] = find(fa[x]); }
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) fa[i] = i;
    for(int i = 1; i <= (n-1)<<1; ++i)
    {
        int x = read(), y = read();
        if(++h[code(x, y)] == 2) q.push(code(x, y));
        s[x].insert(y), s[y].insert(x);
    }
    while(q.size())
    {
        int x = q.front().first, y = q.front().second; q.pop();
        x = find(x), y = find(y);
        s[x].erase(y), s[y].erase(x);
        if(s[x].size() > s[y].size()) swap(x, y);
        for(set<int>::iterator it = s[x].begin(); it != s[x].end(); ++it)
        {
            h.erase(code(*it, x)), s[*it].erase(x), s[*it].insert(y), s[y].insert(*it);
            if(++h[code(*it, y)] == 2) q.push(code(*it, y));
        }
        s[x].clear(), fa[x] = y;
    }
    for(int i = 1; i <= n; ++i) m += i == find(i);
    if(m == 1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 38704
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int count = 0;

    while(true){
        if(*max_element(h.begin(), h.end()) == 0) break;

        int i = 0;
        while(i < n){
            if(h[i] == 0)i++;
            else{
                while(i < n && h[i] > 0){
                    h[i]--;
                    i++;
                }
                count++;  
            }
        }
    }
    cout << count << endl;
}

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

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

	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << "\n";
			return 0;
		}
	}

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int n, k;
vector<ll> v;
ll ans = 0ll;

ll tans(int a, int b)
{
    ll tans = 0ll;
    set<ll> s;
    int cd = k - a - b;
    REP(i,a) {
        s.insert(v[i]);
        tans += v[i];
    }
    REP(j,b) {
        s.insert(v[n-1-j]);
        tans += v[n-1-j];
    }
    for(auto itr : s) {
        if (cd < 1 || itr > 0) {
            break;
        } else {
            tans -= itr;
            cd--;
        }
    }
    return tans;
}

int main()
{
    cin>>n>>k;
    REP(i,n) {
        int tv;
        cin>>tv;
        v.push_back(tv);
    }
    REP(a,k+1) {
        REP(b,k+1-a) {
            if (a + b > n)
                break;

            ans = max(ans, tans(a,b));
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static int N;
  static final long INF = 1L << 60;

  public static void main(String[] args) {
    N = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    long a = INF;
    long sum = 0;
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
      if (A[i] > B[i]) {
        a = Math.min(a, B[i]);
      }
      sum += A[i];
    }
    System.out.println(a == INF ? 0 : sum - a);
  }
}


Measured memory_bytes: 50404
<?php
list($n, $m, $x) = explode(" ", trim(fgets(STDIN)));
$gArray = explode(" ", trim(fgets(STDIN)));

$a = $b = 0;
foreach($gArray as $g){
    if($g < $x){
        $a++;
    }else{
        $b++;
    }
}
echo min($a,$b);

Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    cin>>a;
    if(a[0]==a[a.size()-1])
		if(a.size()%2==1) puts("Second");
		else puts("First");
	else
		if(a.size()%2==0) puts("Second");
		else puts("First");
}

Measured memory_bytes: 512
N,K,Q = map(int,input().split())
M = []
for i in range(N):
  M.append(K - Q)

for j in range(Q):
  a = int(input())
  M[a - 1] += 1

for k in range(N):
  if M[k] <= 0:
    print('No')
  else:
    print('Yes')
  
  

Measured memory_bytes: 13072
N = int(input())
S = input()

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if 2 * j - i < N and S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):
            cnt += 1

ans = r_num * g_num * b_num - cnt
print(ans)

Measured memory_bytes: 9208
n = input()
k = int(input())

kt = len(n)
dp = [[[0] * 4 for _ in range(2)] for _ in range(kt+1)]
dp[0][1][0] = 1

for i in range(kt):
    x = int(n[i])
    dp[i+1][0][0] = 1
    
    for j in range(3):
        if x == 0:
            dp[i+1][1][j+1] = dp[i][1][j+1]
            dp[i+1][0][j+1] = dp[i][0][j] * 9 + dp[i][0][j+1]
        else:
            dp[i+1][1][j+1] = dp[i][1][j]  
            dp[i+1][0][j+1] = dp[i][0][j] * 9 + dp[i][0][j+1] + dp[i][1][j] * (x-1) +  dp[i][1][j+1]
            
print(dp[kt][0][k] + dp[kt][1][k])

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(ll i=0;i<N;i++){
		cin >> A[i];
	}
	int count = 0;
	ll check0 = 0;
	for(int i=0;i<N;i++){
		if(A[i] <= 0)count++;
		if(A[i] == 0)check0 = 1;
	}
	vector<ll> B(N);
	for(int i=0;i<N;i++){
		B[i] = abs(A[i]);
	}
	ll ans = 0;
	sort(B.begin(),B.end());
	if(check0){
		for(int i=0;i<N;i++){
			ans += B[i];
		}
	}
	else if(count % 2){
		ans -= B[0];
		for(int i=1;i<N;i++){
			ans += B[i];
		}
	}
	else{
		for(int i=0;i<N;i++){
			ans += B[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

S = one_str()

num_list = list(S)

start_bit=2**(len(S)-1)
end_bit = 2**(len(S))

def get_sums(array, bit):
    sums = 0
    start = 0
    end = 0
    for i,s in enumerate(bit):
        if s=="1":
            end = i+1
            sums+=int("".join(array[start:end]))
            start=i+1
    if end==start==0:
        return int("".join(array))
    else:
        sums+=int("".join(array[start:]))
    return sums

sums = 0
for i in range(start_bit, end_bit):
    bits = str(bin(i))[3:]
    sums += get_sums(num_list, bits)

print(sums)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int A, B;
	cin >> A >> B;
	string s = "Yes";
	if (A % 2 == 0 || B % 2 == 0)s = "No";
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 764
import sys
import math
N = int(sys.stdin.readline().rstrip())

# def create_money(i):
#     money = []
#     tmp = 1
#     for _ in range(math.floor(math.log(N, i))):
#         tmp *= i
#         money.append(tmp)
    
#     return money

# money = [1]
# money += create_money(6)
# money += create_money(9)

money = [1]
for i in range(20):
    if 100000 >= 6**i:
        money.append(6**i)
    if 100000 >= 9**i:
        money.append(9**i)


dp = [[10**18] * (N + 1) for _ in range(len(money) + 1)]
dp[0][0] = 0

for i in range(1, len(money) + 1):
    m = money[i - 1]
    for j in range(N + 1):
        if j - m >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - m] + 1, dp[i][j - m] + 1)
        else:
            dp[i][j] = dp[i - 1][j]

print(dp[len(money)][N])

Measured memory_bytes: 52720
'use strict';
(function(stdin) {
  var lines  = stdin.toString();
  var re = /\w+\n[\w\s]*?\n/g;
  var result = (function(data) {

    return data.map(stdev).join('\n');

    function stdev(scores) {
      var count = scores.length;
      var mean  = scores.reduce(sum) / count;

      return Math.sqrt(scores.map(function(v) {
          return Math.pow(v - mean,2);
        })
        .reduce(sum) / count).toFixed(8);
    }

    function sum(a,b) {
      return a + b;
    }
  }(lines.match(re).map(function(v) {
      return v.split('\n')[1].split(' ')
        .slice(0,v.split('\n')[0]).map(Number);
   })
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 9336
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N;
    cin>>N;
    long long A[102];
    long long B[102];
    rep(i,0,N-1)cin>>B[i];
    
    A[0]=B[0];
    A[1]=B[0];

    rep(i,0,N-2){
        if(B[i]>B[i+1]){
            A[i+1]=B[i+1];
        }
        A[i+2]=B[i+1];
    }

    long long ans=0;
    rep(i,0,N){
        ans+=A[i];

    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

ll nck(ll n, ll k) {
   if (n < k) return 0;
      k = min(k, n - k);
      ll res = 1;
      rep(i,1,k+1) res = res * (n - (k - i)) / i;
      return res; }

int main()
{
    ll n, k;
    cin >> n >> k;
    cout << n-k+1 << endl;
}


Measured memory_bytes: 256
let
    n::Int = parse(Int, readline())
    x = Int[parse(Int, x) for x in split(readline())]
    l::Int = parse(Int, readline())
    q::Int = parse(Int, readline())
    const lg = 20
    F = Array(Int, lg, n)
    B = Array(Int, lg, n)
    for i = 1:n
        F[1,i] = searchsortedlast(x, x[i]+l)
        B[1,i] = searchsortedfirst(x, x[i]-l)
    end

    for fe = 2:lg
        for i = 1:n
            F[fe,i] = F[fe-1,F[fe-1,i]]
            B[fe,i] = B[fe-1,B[fe-1,i]]
        end
    end

    for i = 1:q
        a, b = Int[parse(Int, x) for x in split(readline())]

        ans = 1
        if a < b
            for fe = lg:-1:1
                if F[fe,a] < b
                    a = F[fe,a]
                    ans += 2^(fe-1)
                end
            end
        else
            for fe = lg:-1:1
                if B[fe,a] > b
                    a = B[fe,a]
                    ans += 2^(fe-1)
                end
            end
        end
        println(ans)
    end
end


Measured memory_bytes: 121008
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int n,m;cin>>n>>m;
    vector<pair<long,long>>ab;
    for(int i = 0;i<n;i++){
       int a,b;cin>>a>>b;
       ab.push_back(make_pair(a,b));
    }
    sort(ab.begin(),ab.end());
    long g = 0;
    for(int i = 0;i<n;i++){
      if(m <= ab[i].second){
         g+=m*ab[i].first;
         cout<<g;
         return 0;
      }
      else{
      	g+= ab[i].second*ab[i].first;
        m=m-ab[i].second;
      }
    }
    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#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 FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

static const int N = 100;


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

    int a, b;
    cin >> a >> b;

    char field[N][N];
    rep(i, 50) {
        rep(j, 100) {
            field[i][j] = '.';
        }
    }

    for (int i = 49; i < 100; ++i) {
        rep(j, 100) {
            field[i][j] = '#';
        }
    }

    int c = 0, r = 0;
    rep (i, b - 1) {
        field[c][r] = '#';
        if (r + 2 > 99) {
            c += 2;
            r = 0;
        } else if (r == 97) {
            field[c][r + 2] = '#';
            c += 2;
            r = 0;
        } else {
            r += 2;
        }
    }

    c = 0;
    r = 0;
    rep (i, a - 1) {
        field[99 - c][r] = '.';
        if (r + 2 > 99) {
            c += 2;
            r = 0;
        } else if (r + 2 == 99) {
            field[99 - c][r + 2] = '.';
            c += 2;
            r = 0;
        } else {
            r += 2;
        }
    }

    cout << 100 << " " << 100 << endl;
    rep(i, 100) {
        rep(j, 100) {
            cout << field[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

using namespace std;

vector<int> par;
vector<int> dis;

vector<int> root(int x) {
  vector<int> res;
  if (par[x] == x) {
    res = {x, 0}; // 親ノード番号、
    return res;
  }
  res = root(par[x]);
  par[x] = res[0];
  dis[x] = dis[x] + res[1];
  res[1] = dis[x];
  return res;
}

bool unite(int x, int y, int d) {
  auto par1 = root(x);
  auto par2 = root(y);
  if (par1[0] == par2[0]) {
    return par1[1] + d == par2[1];
  }
  par[par2[0]] = par1[0];
  dis[par2[0]] = d - par2[1] + par1[1];
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  par = vector<int>(n + 1);
  dis = vector<int>(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    if (!unite(l, r, d)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int p, m ,c;
  cin >> p >> m >> c;
  cout << p + m + c << endl;

  return 0;
}


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

def factorize(n):
  i = 1
  j = 0 
  nums = []
  while i * i <= n:
    if n % i == 0:
      j = int(n / i)
      j = str(j)
      nums.append([i,j])
    i += 1
  return nums
  
factors = factorize(N)
print(len(factors[-1][1]))

Measured memory_bytes: 3188
Scanf.scanf "%s %s" (fun s t ->
    let n = String.length s in
    let tn = String.length t in

    let check p =
        let rec loop j =
            if j = tn then true else
                if s.[p + j] = t.[j] || s.[p + j] = '?' then loop (j + 1) else false
        in
        loop 0
    in

    let make p =
        String.init n (fun i ->
            if s.[i] <> '?' then s.[i] else
                if i < p || i >= p + tn then 'a' else t.[i - p]
        )
    in

    let rec loop i acc =
        if i < 0 then acc else
            let acc = if check i then min acc (make i) else acc in
            loop (i - 1) acc
    in
    let r = loop (n - tn) "{" in
    print_endline @@ if r = "{" then "UNRESTORABLE" else r
)

Measured memory_bytes: 3744