akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


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

n,m = getNM()

pres = [[] for i in range(n)]
cities = []
for i in range(m):
    n,m = getNM()
    cities.append([i, n,m]) #num, pre,year

cities.sort(key=lambda x:x[2])
#print(cities)
for i, c in enumerate(cities):
    pres[c[1]-1].append([c[0]])

buf = []
for i, p in enumerate(pres):
    for j, c in enumerate(p):
        buf.append([c[0], "{0:06d}".format(i+1) + "{0:06d}".format(j+1)])


buf.sort(key=lambda x:x[0])
for b in buf:
    print(b[1])



Measured memory_bytes: 62596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  ll N,K;
  cin>>N>>K;
  VI A(N),F(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>F[i];
  sort(all(A));
  sort(all(F));
  ll ok=1000000000000,ng=-1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    vector<ll> B(N);
    rep(i,N) B[i]=mid/F[i];
    sort(all(B));
    ll X=1,sum=0;
    rep(i,N){
      if(A[i]>B[i]) sum+=(A[i]-B[i]);
    }
    if(sum>K) X=0;
    if(X){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  cout<<ok<<endl;
}



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

using namespace std;

int main(){
	int n,cnt=0;
	int a[100];
	cin >> n;
	for (int i=0;i<n;i++){
		cin >> a[i];
		if ((i+1)%2==1 && a[i]%2==1) cnt++;
	}
	cout << cnt ;
	return 0;
}

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

int main(){
    string S; 
    cin>>S;
    int q; 
    cin>>q;
    rep(i,q){
        string T; 
        cin>>T;
        int a,b;
        cin>>a>>b;
        if(T=="replace"){
            string c;
            cin>>c;
            S.replace(a,b-a+1, c);
        }
        else if(T=="print"){
            rep(j,b-a+1){
                cout<<S[a+j];
            }
            cout<<endl;
        }
        else if(T=="reverse"){
            reverse(S.begin()+a, S.begin()+b+1);
        }
    }
    return 0;
}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,mi,x,ans=0;scanf("%d",&n),mi=n;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(mi>=x)mi=x,ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAX=10005;
const int NIL=-1;
int l[MAX],r[MAX],p[MAX],s[MAX],d[MAX],height[MAX];
void print(int i)
{
    cout<<"node "<<i<<": ";
    int x=0;
    if(l[i]!=NIL)x++;
    if(r[i]!=NIL)x++;
    cout<<"parent = "<<p[i]<<", sibling = "<<s[i];
    cout<<", degree = "<<x<<", depth = "<<d[i];
    cout<<", height = "<<height[i];
    cout<<", ";
    if(p[i]==NIL)cout<<"root";
    else if(x==0)cout<<"leaf";
    else cout<<"internal node";
        cout<<endl;
}
void setD(int i,int t)
{
    if(i==NIL)return ;
    d[i]=t;
    setD(l[i],t+1);
    setD(r[i],t+1);
}
int setH(int i)
{
    int h1=0,h2=0;
    if(l[i]!=NIL)
        h1=setH(l[i])+1;
    if(r[i]!=NIL)
        h2=setH(r[i])+1;
    return height[i]=max(h1,h2);
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)p[i]=l[i]=r[i]=s[i]=NIL;

    for(int i=0;i<n;i++)
    {
        int v=0;
        cin>>v;
        cin>>l[v]>>r[v];
        s[l[v]]=r[v],s[r[v]]=l[v];
        if(l[v]!=NIL)p[l[v]]=v;
        if(r[v]!=NIL)p[r[v]]=v;
    }
    int root=0;
    for(int i=0;i<n;i++)if(p[i]==NIL)root=i;
    if(root==-1)cout<<"error"<<endl;
    else
    {
        setD(root,0);
        setH(root);
    }
    for(int i=0;i<n;i++)print(i);
    return 0;
}



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

int main(){
    ll x;
    cin>>x;
    ll n =100;
    int y = 0;
  
    while (n<x){
        n= n+ n/100;
     
       
        y++;
    }
    cout << y <<endl;
}

Measured memory_bytes: 3636
#include <cstdio>

int main(){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int num_5 = 0, num_7 = 0;

    if (a == 5)
        num_5 += 1;
    else if (a == 7)
        num_7 += 1;

    if (b == 5)
        num_5 += 1;
    else if (b == 7)
        num_7 += 1;

    if (c == 5)
        num_5 += 1;
    else if (c == 7)
        num_7 += 1;

    if (num_5 == 2 && num_7 == 1)
        printf("YES");
    else
        printf("NO");

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 5e5 + 5;
typedef long long ll;
const ll INF = 1e15; 
using namespace std;

int n, a[N]; 
ll f[N], g[N], ans = -INF;
priority_queue<int, vector<int>, greater<int> > q; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

ll mabs(ll x) { return x > 0 ? x : -x; }

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> (); 
	for(int i = 1; i <= 3 * n; i++) a[i] = read <int> (); 
	for(int i = 1; i <= 3 * n + 1; i++) f[i] = -INF, g[i] = INF; 
	f[n] = 0; 
	for(int i = 1; i <= n; i++) q.push(a[i]), f[n] += a[i]; 
	for(int i = n + 1; i <= 3 * n; i++)
	{
		f[i] = f[i - 1]; 
		if(a[i] > q.top()) f[i] -= q.top(), f[i] += a[i], q.pop(), q.push(a[i]); 
	}
	while(!q.empty()) q.pop();
	g[2 * n + 1] = 0; 
	for(int i = 2 * n + 1; i <= 3 * n; i++) q.push(-a[i]), g[2 * n + 1] += a[i]; 
	for(int i = 2 * n; i >= 1; i--)
	{
		g[i] = g[i + 1]; 
		if(a[i] < -q.top()) g[i] += q.top(), g[i] += a[i], q.pop(), q.push(-a[i]); 
	}
	for(int i = 1; i <= 3 * n; i++) g[i] = g[i + 1]; 
	for(int i = 1; i <= 3 * n; i++) ans = max(ans, f[i] - g[i]); 
	printf("%lld\n", ans); 
	return 0; 
}


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

int main(){
	int n;
	int count=0;
	unordered_map<int, int> m;
	cin >> n;
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		m[tmp]++;
	}
	for(auto i: m){
		if(i.second > i.first) count += (i.second - i.first);
		else if (i.second < i.first) count += i.second;
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 4260
#include <iostream>
#include <cctype>

using namespace std;

int main(){
    string len;

    cin >> len;

    if(len[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    bool flag = false;
    int point;
    for(int i = 2; i < len.size() - 1; i++){
        if(flag && len[i] == 'C'){
            cout << "WA" << endl;
            return 0;
        }
        if(!flag && len[i] == 'C'){
            flag = true;
            point = i;
        }
    }
    if(!flag){
        cout << "WA" << endl;
        return 0;
    }
    for(int i = 1; i < len.size(); i++){
        if(i == point) continue;
        if(isupper(len[i])){
            cout << "WA" << endl;
            return 0;           
        }
    }
    cout << "AC" << endl;
}

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

int main(){
  int W,a,b;
  cin >> W >> a >> b;
  if(a<b){
    cout << max(0,b-(a+W)) << endl;
  }else{
    cout << max(0,a-(b+W)) << endl;
  }
  return 0;
}


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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

ll MOD=1000000007;

signed main() {
	llin(n);
	llin(m);
	vll a(n+1,0);
	vll b(m+1,0);
	ll s=0;
	ll x=1;
	ll y=1;
	ll t=1;
	FOR(i,0,n-1){
		cin >>a[i];
	}
	FOR(i,0,m-1){
		cin >>b[i];
	}
	rSORT(a);
	rSORT(b);
	ll o=a[0];
	while(x<m||y<n){
        if(o==a[y]||o==b[x]){
            t=0;
            break;
        }
		if(a[y]==b[x]){
			FOR(j,1,o-a[y]-1){
				t=(t*s)%MOD;
				s--;
			}
            o=a[y];
			s+=x+y;
			x++;
			y++;
		}
		if(a[y]>b[x]){
			t=(t*x)%MOD;
			FOR(j,1,o-a[y]-1){
				t=(t*s)%MOD;
				s--;
			}
            o=a[y];
			s+=x-1;
			y++;
		}
		if(a[y]<b[x]){
			t=(t*y)%MOD;
			FOR(j,1,o-b[x]-1){
				t=(t*s)%MOD;
				s--;
			}
            o=b[x];
			s+=y-1;
			x++;
		}
	}
    rFOR(j,1,s){
        t=(t*j)%MOD;
    }
	sal(t);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& (a) : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _per(i, n) peri(i, 0, n)
#define peri(i, a, n) for (int i = (n) - 1; i >= (a); --i)
#define per(...) _overload3(__VA_ARGS__, peri, _per)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {each(in, v) is >> in; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) {os << v[i] << (i + 1 != sz(v) ? " " : "");} return os;}
struct Init {Init() {ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);}} init;

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (sz(s) <= k) print(s);
    else print(s.substr(0, k) + "...");
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    string s; cin >> s;
    cout << s.substr(0, 3) << endl;
    return 0;
}

Measured memory_bytes: 3596
import math

N = int(input())
A = [math.floor(a/400) if a < 3200 else 3200 for a in list(map(int, input().split()))]

set_A = set([a for a in A if a != 3200])
print(*[max(1, len(set_A)), len(set_A) + A.count(3200)], sep=" ")

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

int main() {
   int n,d;
   cin>>n>>d;
   int ans = 0,i=1;
   while(i <= n){
       i = i + d;
       i = i + d;
       i++;
       ans++;
   }
   cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long i=0;i<(long)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
ll mod=1e10+7;

void merge(vector<pair<char,long> > &a,long p,long mid,long r){
    long n1=mid-p;
    long n2=r-mid;
    vector<pair<char,long> > L(n1);
    vector<pair<char,long> > R(n2);
    for(long i=0;i<n1;i++) L.at(i)=a.at(p+i);
    for(long i=0;i<n2;i++) R.at(i)=a.at(mid+i);
    pair<char, long> data('a',mod);
    L.push_back(data);
    R.push_back(data);
    long i=0;
    long j=0;
    for(long k=p;k<r;k++) {
        if(L.at(i).second<=R.at(j).second){
            a.at(k)=L.at(i);
            i++;
        }
        else{
            a.at(k)=R.at(j);
            j++;
        }
    }
    return;
}

void mergesort(vector<pair<char,long> > &a,long p,long r){
    if(p+1<r){
        long mid=(p+r)/2;
        mergesort(a,p,mid);
        mergesort(a,mid,r);
        merge(a,p,mid,r);
    }
}


long partition(vector<pair<char,long> > &a,long p,long r){
    long i=p-1;
    for(long j=p;j<r;j++){
        if(a.at(j).second<=a.at(r).second) {
            i++;
            swap(a.at(i),a.at(j));
        }
    }
    swap(a.at(r),a.at(i+1));
    return i+1;
}

void quick(vector<pair<char,long> > &a,long f,long r){
    if(f<r){
        long mid=partition(a,f,r);
        quick(a,f,mid-1);
        quick(a,mid+1,r);
    }
}

int main(void){
    long n;
    cin>>n;
    vector<pair<char,long> > a(n);
    vector<pair<char,long> > b(n);
    for(long i=0;i<n;i++) cin>>a.at(i).first>>a.at(i).second;
    b=a;
    quick(a,0,n-1);
    mergesort(b,0,n);
    cout<<(a==b?"Stable":"Not stable")<<endl;

    for(long i=0;i<n;i++)cout<<a.at(i).first<<" "<<a.at(i).second<<endl;
    return 0;
}



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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

signed main() {
  ll N, ans = 1000000000000;
  cin >> N;
  for (ll a=1; a*a<=N; a++) {
    ll b = N/a;
    if (a*b != N)
      continue;
    // cout << a << " " << b << endl;
    ans = min(ans, (a-1)+(b-1));
  }
  cout << ans << endl;
}


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

using namespace std;

using lli = long long int;
std::vector<int> vv;

lli hantei(int a, int b, lli count){
	std::vector<int> v(vv);
	lli subcount = count;
	lli nokori = 0;
	// 全ての敵の体力をcount * b減らす
	for (size_t i = 0; i < v.size(); i++) {
		v[i] = v[i] - subcount * b;
	}
	// (a-b) * countだけ0以下になっていない敵の体力を減らす
	for (size_t i = 0; i < v.size(); i++) {
		if (v[i] > 0) {
			if (subcount > 0) {
				lli num = min(subcount, 1LL * (v[i]/(a-b) + !!(v[i]%(a-b))));
				subcount -= num;
				v[i] = v[i] - num * (a-b);
			}
		}
	}
	for (size_t i = 0; i < v.size(); i++) {
		if (v[i] > 0) {
			nokori += v[i];
		}
	}
	return nokori / (b * v.size() + a-b) + !!(nokori%(b * v.size() + a-b));
}


int main(int argc, char const *argv[]) {
	int n,a,b;
	std::cin >> n >> a >> b;
	vv.resize(n);
	lli sum = 0;
	lli count;
	for (size_t i = 0; i < n; i++) {
		std::cin >> vv[i];
		sum += vv[i];
	}
	/*
	 * 敵の体力を合計して、それを削りきれる攻撃をしないとまず倒せないので、
	 * ここから考える
	 */
	count = sum / (b * vv.size() + a-b);

	int x = 1;
	while (x != 0) {
		x = hantei(a, b, count);
		count += x;
	}

	std::cout << count << '\n';
	return 0;
}


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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

#ifndef __SOULTCH
#define endl '\n'
#define debug(x) 
#else
#define debug(x) cout << " [+] " << #x << " = " << x << endl
#endif

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << pai.first << ' ' << pai.second;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> s) {
    for (T p : s) cout << p << ' ';
    return os;
}

template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> s) {
    for (auto p : s) cout << '(' << p << ") ";
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

int N, X;
int A[200];

int dp[200][100001];
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> N >> X;
    rep(i, N) cin >> A[i];

    sort(A, A+N);
    
    repp(i, X) dp[0][i] = i%A[0];
    repp(i, N-1) {
        repp(j, X) {
            dp[i][j] = ((ll)dp[i-1][j]*i+dp[i-1][j%A[i]])%MOD;
        }
    }

    cout << dp[N-1][X] << endl;
}






Measured memory_bytes: 78336
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,T,c,t;
    vector<int>v1;
    cin>>n>>T;
    for(int i=0;i<n;i++)
    {
        cin>>c>>t;
        if(t<=T)
            v1.push_back(c);
    }
   if(v1.size()!=0)
   cout<<*min_element(v1.begin(),v1.end())<<endl;
   else
    cout<<"TLE"<<endl;
   return 0;
}


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

#define int long long

int memo[20][(1 << 18)];
int n;
int a[20];
int b[20];

int get(int i, int j){
    if(abs(j-i)%2 == 0){
        return a[j];
    }else{
        return b[j];
    }
}

int dp(int i, int bit, int last, int num){
    if(i == n){
        return 0;
    }

    if(memo[last][bit] != -1) return memo[last][bit];

    int ans = INT_MAX;
    int cnt = 0;
    for(int j = 0;j < n;j++){
        if((bit & (1 << j)) == 0){
            if(num <= get(i, j)){
                ans = min(ans, dp(i+1, bit | (1 << j), j, get(i, j)) + j-cnt);
            }
        }else{
            cnt++;
        }
    }

    return memo[last][bit] = ans;
}

signed main(){
    cin >> n;

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

    memset(memo, -1, sizeof(memo));

    cout << (dp(0, 0, n, 0) == INT_MAX ? -1 : dp(0, 0, n, 0)) << endl;
    return 0;
}


Measured memory_bytes: 41216
fun main(args: Array<String>) {
        val input = read()
        println(daydream(input))
    }

    enum class Choices { dream, dreamer, erase, eraser }

    fun read(): String {
        return readLine()!!
    }

    fun daydream(input: String): String {
        val reversed = input.reversed()
        val reversedChoices = Choices.values().map { it.name.reversed() }

        tailrec fun erasing(str: String): Boolean {
            if (str.isEmpty()) return true
            val found = reversedChoices.find { it.substring(0, 3) == str.substring(0, 3) }
            if (found == null || str.length < found.length || str.substring(0, found.length) != found)
                return false
            else
                return erasing(str.drop(found.length))
        }

        return if (erasing(reversed)) "YES" else "NO"
    }

Measured memory_bytes: 117020
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int dis[55][55];
char arr[55][55];
int dx[]={-1,+1,0,0};
int dy[]={0,0,-1,+1};
int main(){
    //~ freopen("file.in", "r", stdin);
    int n,m,free=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			scanf(" %c",&arr[i][j]),dis[i][j]=INF;
	for(int i=0;i<n;i++)		
		for(int j=0;j<m;j++)
			free+=(arr[i][j]=='.');
	queue<PII>q;
	q.push(mp(0,0));
	dis[0][0]=1;
	while(!q.empty()){
		PII nd=q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int nx=nd.ff+dx[i];
			int ny=nd.ss+dy[i];
			if(nx>=0 and ny>=0 and nx<n and ny<m and arr[nx][ny]!='#' and umin(dis[nx][ny],dis[nd.ff][nd.ss]+1))
				q.push(mp(nx,ny));
		}
	}	
	if(dis[n-1][m-1]==INF)
		puts("-1");
	else
		printf("%d\n",free-dis[n-1][m-1]);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    long A,B,X,R,tmp;
    cin >> A >> B;
    X = A * B;
    if(A<B){
        tmp = A;
        A = B;
        B = tmp;
    }
    R = A % B;
    while(R!=0){
        A = B;
        B = R;
        R = A % B;
    }
    cout << X/B << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Measured memory_bytes: 179084
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll k;
    cin>>n>>m>>k;
    vector<ll> v(n);
    vector<ll> w(m);
    vector<ll> x(m);

    rep(i,n) cin>>v[i];
    rep(i,m) cin>>w[i];
    x[0]=w[0];
    //cout<<"xのるいせきわ"<<endl;
    for(ll i=1;i<m;i++) {
        x[i]=x[i-1]+w[i];
        //cout<<x[i]<<" ";
    }
   // cout<<endl;
    ll wi=0;
    rep(i,n){
        wi+=v[i];
        if(wi<=k) maxi=i+1;
    }
    ll wu=0;
    rep(i,m){
        wu+=w[i];
        if(wu<=k) maxi=max(maxi,i+1);
    }

    ll wa=0;
    rep(i,n){
        ll books=0;
        wa+=v[i];
        if(wa>k)  continue;
        books=i+1;               //index的に1を足す

        if(wa!=k){
        auto xbooks=lower_bound(x.begin(),x.end(),k-wa);
        if(*xbooks!=k-wa) xbooks--;
        //Bの棚から本を選ぶ場合
        if(xbooks!=x.end()){
        
            ll index=xbooks-x.begin();
            index++;
            ////cout<<k-wa<<"以下で検索"<<*xbooks+wa<<"<"<<k<<"のはず"<<endl;
            //cout<<"index:"<<index<<"数"<<*xbooks<<endl;
            books+=index;
        }

        }
        maxi=max(books,maxi);
    }

cout<<maxi<<endl;
    return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T &b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T &b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;
const int mod = 1e9+7;


const int maxn = 1e6+5;
int N,H,D;
int facN;
int mult(LL x,LL y){return x*y%mod;}
int add(LL x,LL y){return (x+y)%mod;}
int sub(LL x,LL y){return (x-y+mod)%mod;}
int dp[maxn];
int sumN[maxn];
int sumdp[maxn];

int fpow(int a,int p){
    if(p == 0) return 1;
    int ret = fpow(a,p/2);
    ret = mult(ret,ret);
    if(p&1) ret = mult(ret,a);
    return ret;
}

int searching(int n){
    dp[0] = 1;
    sumdp[0] = 0;

    _rep(i,1,n){
        int k;
        if(i - D <= 0){
            k = sumdp[i-1];
            dp[i] = mult(sumN[N],k);
            dp[i] = add(dp[i],1);
        }
        else{
            k = sub(sumdp[i-1],sumdp[i - D -1]);
            dp[i] = mult(k,sumN[N]);
        }
        sumdp[i] = add(sumdp[i-1],dp[i]);
    }

    return mult(dp[n],facN);
}

int main(){
    cin >> N >> H >> D;
    facN = 1;
    _rep(i,1,N){
        facN = mult(i,facN);
        sumN[i] = add(sumN[i-1],facN);
    }
    cout << searching(H) << endl;
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 105;

int N;
int W[MAX_N];

signed main()
{
  cin >> N;
  REP(n,N) {
    cin >> W[n];
  }

  int ans = 1145141919810;
  FOR(k,1,N) {
    int a = 0;
    REP(n,k) {
      a += W[n];
    }
    int b = 0;
    FOR(n,k,N) {
      b += W[n];
    }
    ans = min(ans, abs(a-b));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
p = gets.chomp.split(" ").map(&:to_i)

count = 0
for i in 2...N do
  if (p[i-2] < p[i-1] && p[i-1] < p[i]) || (p[i-2] > p[i-1] && p[i-1] > p[i]) then
    count +=1
  end
end

p count


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

int main(){
	int n;
	cin >> n;
	
	int p[n]={};
	for(int i=0; i<n; i++) cin >> p[i];
	
	int ans=0;
	for(int i=1; i<n-1; i++){
		if(p[i-1]<p[i] && p[i]<p[i+1]) ans++;
		else if (p[i-1]>p[i] && p[i]>p[i+1]) ans++;
		else ans=ans;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("d.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    ll n;
    cin >> n;
    ll ans = 0;

    ans = (1+n)*n/2 - n;

    cout << ans;

    return 0;
}

/*
  - 1e9 : 10^9
  - vector
    vector<int> A(N);
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - string
    - loop
      for (char& c : s) {}
 */



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

using namespace std;
using ll = long long;

int main() {
	ll N;
	cin>>N;
	ll ans = 0;
	for (ll k = 1;k*k <= N;++k) {
		if ((N-1)%k == 0) {
			if ((N-1)/k != k) {
				ans += 1;
			}
		
			if (k != 1) {
				ans += 1;
			}
		}
	}

	function<void(ll)> compute = [&] (ll x) {
		if (x == 1) return;
		ll z = N;
		while (z%x == 0) {
			z /= x;
		}

		if (z%x == 1) {
			ans += 1;
		}
	};

	for (ll k = 1;k*k <= N;++k) {
		if (N%k == 0) {
			compute(k);
			if (N/k != k) {
				compute(N/k);
			}
		}
	}

	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 10'000;
const int LOGN = 19;

int n, m, k;

void solve(int test) {
  int64 n;
  cin >> n;
  int64 ans = inf64;
  for (int64 i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      ans = min(ans, i + n / i);
    }
  }
  cout << ans - 2 << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
//A
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while(true)
int main(){
    
    int K;
    cin >> K;
    cout << K/2 * ((K+1)/2) << endl;
    
    return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define RREP(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define endl '\n'

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define Pi 3.14159265358979
#define A first
#define B second

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vl;
typedef pair <int, int> pi;
typedef pair <ll, int> pl;
typedef pair <ll, ll> pll;
typedef pair <double, double> pd;

//change these according to prob constraints
const int INF = 0x3f3f3f3f;
const int MAX = 100005;
const int MAX1 = 1005;
const int MAX2 = 105;
const int LEN = 105;
const int BASE = 1000000000;
const double EPS = 1e-7;
const int MOD = 1000000007;
//g++ -std=c++11 your_file.cpp -o your_program

ll mypow(ll a, ll b){
	ll ans=1;
	while(b){
		if(b&1)
			ans=(ans*a)%MOD;
		b/=2;
		a=(a*a)%MOD;
	}
	return ans;
}

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ifstream in("");
	ofstream out("");
	clock_t begin = clock();
	int n;
	cin >> n;
	double sum = 0.0;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		sum += (1.0 / (double)tmp);
	}
	cout << fixed << setprecision(10) << 1.0 / sum << endl;
	clock_t end = clock();
    double esecs = double(end - begin) / CLOCKS_PER_SEC;
    //cout << esecs << " seconds" << endl;
	return 0;	
}

Measured memory_bytes: 384
N = int(input())
A = [int(i) for i in input().split()]
B = [A[i]-(i+1) for i in range(N)]
C = sorted(B)
from bisect import bisect
from bisect import bisect_right
from bisect import bisect_left

ans=0

for i in range(N):
    target = -2*(i+1)-B[i]
    l=bisect_left(C, target)
    r=bisect_right(C, target)
    ans+=r-l
print(ans)




Measured memory_bytes: 100980
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

template<class T> void swap(T &a, T &b ){
    T temp;
    temp = a;
    a = b;
    b = temp;   
}

int main(){
    int N;
    double x;
    cin >> N;
    x = N / 1.08;
    //cout << x << endl;
    if( floor(floor(x) * 1.08) == N){
        cout << floor(x);
    }else if( floor(ceil(x) * 1.08) == N){
        cout << ceil(x);
    }else{
        cout << ":(";
    }
    cout << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL rou(LL a,LL d){if((a*10/d)%10<5)return a/d;else return a/d+1;}
LL ten(LL a){return (LL)pow(10,(LL)log10(a));}
LL two(LL a){return (LL)pow(2,(LL)log2(a));}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}

LL lpow(LL a,LL n){
  LL ans=pow(a,n)*10;
  if(ans%10<5)return ans/10;
  return ans/10+1;
}

LL pid=0,pnum=0,rpid[NUM];LL co[NUM],cpid[NUM],que[NUM];
LL judge(LL a,LL b){if(pnum<b||b==1)return 0;return cpid[que[a]]>cpid[que[b]]?1:0;}
void push(LL a,LL n){LL i=++pid,j=++pnum;rpid[i]=n,cpid[i]=a,que[j]=i;while(judge(j/2,j))que[j]=que[j/2],que[j/=2]=i;}
LL pop(){LL ans=rpid[que[1]],i=1,j;LL n=que[pnum--];que[1]=n;while(judge(i,j=i*2+judge(i*2,i*2+1)))que[i]=que[j],que[i=j]=n;return ans;}
bool pri(LL p){LL i,j,n[8]={7,11,13,17,19,23,29,31},r=(LL)sqrt(p),flag=0;if(p%2==0||p%3==0||p%5==0)flag=1;FOR(i,0,8){if(p<=1)flag=1;if(p==2||p==3||p==5){flag=0;break;}if(flag==1)break;for(j=n[i];j<=r;j+=30)if(p%j==0){flag=1;break;}}if(flag==0)return true;return false;}
LL LCMM(LL* a,LL n){
  push(INF,INF);
  LL b[n],i,j,m=0,num,max,l=0,lcm=1;
  FOR(i,0,n)b[i]=a[i],l=MAX(l,b[i]);
  LL r=sqrt(l),p[r];
  FOR(i,2,r+1)if(pri(i))p[m++]=i;
  FOR(i,0,m){
    max=0;
    FOR(j,0,n){
      num=0;
      while(b[j]%p[i]==0)b[j]/=p[i],num++;
      max=MAX(max,num);
      if(i==m-1&&b[j]!=1)push(b[j],b[j]);
    }
    lcm=(lcm*lpow(p[i],max))%MOD;
  }
  m=0;
  while(r!=INF)b[m++]=r=pop();
  FOR(i,0,m-1)if(b[i]!=b[i+1])lcm=(lcm*b[i])%MOD;
  return lcm;
}

int main(){
  LL N,i,lcm,ans=0;
  scanf("%lld",&N);
  LL A[N];
  FOR(i,0,N)scanf("%lld",&A[i]);
  lcm=LCMM(A,N);
  FOR(i,0,N)ans=(ans+DIV(lcm,A[i]))%MOD;

  printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2560
//NotFound.cpp (B)
#include <iostream>
#include <cstring>
using namespace std;

int main(){
  char s[1000001];
  cin >> s;
  int b[28];
  for(int i = 0; i < strlen(s); i++){
    if(b[s[i]-'a'+1] == 0){
      b[s[i]-'a'+1] = 1;
    }
  }
  for(int i = 1; i <= 26; i++){
    if(b[i] == 0){
      printf("%c\n",'a'-1+i);
      return 0;
    }
  }
  printf("None\n");

}


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

int main() {
    char x,y;
    cin >> x >> y;
    if(x>y){
        cout << ">" << endl;
    }else if(x<y){
        cout << "<" <<endl;
    }else{
        cout << "=" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char str[100];
  scanf("%s",str);
  if(str[0]=='S'){
    printf("Cloudy");
  }
  else if(str[0]=='C'){
    printf("Rainy");
  }
  else{
    printf("Sunny");
  }
  
  return 0;
}

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

template<typename T1,typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 & a, T2 b) { if (a < b) a = b; }

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;
const long long kMod = 1000000007;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

template <typename T>
struct RMQ {
  using F = function<T(T, T)>;
  T dat[kMax5][20];
  F f;

  RMQ() {}
  RMQ(F f): f(f) {}

  void init(const vector<T> & a) {
    auto n = a.size();
    rep(i, 0, n - 1) { dat[i][0] = a[i]; }
    for (auto j = 1; (1 << j) <= n; ++j) {
      for (auto i = 0; i + (1 << j) - 1 < n; ++i) {
        dat[i][j] = f(dat[i][j - 1], dat[i + (1 << (j - 1))][j - 1]);
      }
    }
  }

  T query(ll l, ll r) {
    if (l > r) {
      return 0;
    }

    auto k = 0;
    while (l + (1 << (k + 1)) - 1 <= r) { ++k; }
    return f(dat[l][k], dat[r - (1 << k) + 1][k]);
  }
};

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

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

  auto f = [&](int x, int y) {
    int tmp;
    while (y != 0) {
      tmp = x;
      x = y;
      y = tmp % y;
    }
    return x;
  };
  RMQ<int> solver(f);
  solver.init(a);
  ll ans = 0;
  rep(i, 0, n - 1) {
    chmax(ans, f(solver.query(0, i - 1), solver.query(i + 1, n - 1)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>
#include<string.h>
int main(){
	int a,b,c;
	char suu[20];
	while(scanf("%d %d",&a,&b)!=EOF){
		c=a+b;
		sprintf(suu,"%d",c);
		c=strlen(suu);
		printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;

int main() 
{
    int n, m, i;
    scanf("%d", &n);
    
    vector<int> v1;
    vector<int> v2;
    
    for(i = 0; i < n; i++)
    {
        scanf("%d", &m);
        v1.emplace_back(m);
    }
    
    scanf("%d", &m);
    
    for(i = 0; i < m; i++)
    {
        scanf("%d", &n);
        v2.emplace_back(n);
    }
    
    bool cond = true;
    
    for(i = 0; i < m; i++)
    {
        if(!binary_search(v1.begin(), v1.end(), v2[i]))
        {
            cond = false;
            break;
        }
    }
    
    printf("%d\n", cond);
    
    return 0;
}


Measured memory_bytes: 5240
let m = 1000000007
let ( +^ ) x y = (x + y) mod m
let ( *^ ) x y = (x * y) mod m

let rec power ( * ) e m n =
  if n <= 0 then e
  else power ( * ) (if n land 1 = 0 then e else m * e) (m * m) (n lsr 1)

let () = Scanf.scanf "%d %d" @@ fun n k ->
  let fact = Array.make (min n k + 2) 1 in
  let perm_n = Array.make (min n k + 2) 1 in
  for i = 0 to min n k do
    fact.(i + 1) <- (i + 1) *^ fact.(i);
    perm_n.(i + 1) <- (n - i) mod m *^ perm_n.(i)
  done;
  let inv_n = power ( *^ ) 1 n (m - 2) in
  Printf.printf "%d\n" @@
  Array.fold_left ( +^ ) 0 @@
  Array.init (min n k + 1) @@ fun i ->
    let inv_fact = power ( *^ ) 1 fact.(i) (m - 2) in
    let comb_n_i = perm_n.(i) *^ inv_fact in
    let comn_n1_i = perm_n.(i + 1) *^ inv_n *^ inv_fact in
    comb_n_i *^ comn_n1_i

Measured memory_bytes: 6144
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    if c > '0':
        r = range(0, p * 10, p) if c == '?' else (p * int(c),)
        a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])


Measured memory_bytes: 46428
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 - y2 + y1
y3 = y2 - x1 + x2
x4 = x3 + x1 - x2
y4 = y3 + y1 - y2
print(x3,y3,x4,y4)

Measured memory_bytes: 2940
N = int(input())
sp = []
for i in range(N):
    si, pi = input().split()
    pi = -int(pi)
    sp.append([i + 1, si, pi])

#print(sp)

sorted_sp = sorted(sp, key=lambda x:(x[1], x[2]))
#print(sorted_sp)
for i in sorted_sp:
      print(i[0])

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split;
	auto N = data[0].to!int, M = data[1].to!int;
	
	alias City = Tuple!(int, "i", int, "p", int, "y");
	City[] cities;
	foreach (i; 0 .. M) {
		data = readln.split;
		cities ~= City(i, data[0].to!int, data[1].to!int);
	}
	cities = sort!((a,b) => a.p<b.p || a.p==b.p && a.y < b.y)(cities).array;
	
	int x, prefecture;
	Tuple!(int, "i", string, "id")[] result;
	foreach (city; cities) {
		if (city.p != prefecture) x = 1, prefecture = city.p;
		else ++x;
		result ~= Tuple!(int, "i", string, "id")(city.i, to_str(city.p) ~ to_str(x));
	}
	sort!((a,b) => a.i < b.i)(result).each!(x => x.id.writeln);
	
}

string to_str(int n) {
	auto result = n.to!string;
	if (result.length < 6) result = "0".repeat(6-result.length).reduce!"a~b" ~ result;
	return result;
}

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

int main(){
    int N, K, num;
    int ans = 0, count = 0;
    map<int, int> dic;
    std::cin >> N >> K;

    for(int i = 0; i < N; i++){
        std::cin >> num;
        if(dic.count(num)){
            dic[num] = dic[num] + 1;
        }else{
            dic[num] = 1;
        }
    }

    auto iter = dic.begin();
    while(count < K){
        if(iter->second + count <= K){
            ans = ans + iter->second * iter->first;
            count = count + iter->second;
        }else{
            ans = ans + (K-count) * iter->first;
            count = count + (K-count);
        }
        iter = std::next(iter, 1);
    }

    std::cout << ans;

}

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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)

// policy-based
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;	


using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
 
const ll MAX = 2e5;
const ll inf = 1e12;
const ll mod = 1e9+7;

ll a[MAX];

int main(){
	fastio;
	ll k,n;
	cin >> n >> k;
	f(i,1,n+1) cin >> a[i];
	f(i,k+1,n+1){
		if(a[i] > a[i-k]) cout << "Yes\n";
		else cout << "No\n";
	}

}

Measured memory_bytes: 5204
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 998244353
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;
struct UF
{
  vector<ll> par;
  vector<ll> sz;
  vector<ll> rank;
  UF(ll n):par(n),sz(n),rank(n){
    for(ll i = 0; i < n; i++){
      par[i] = i;sz[i] = 1;rank[i] = 0;
    }
  }
  ll find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  void merge(ll x, ll y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if(rank[x] < rank[y]){
      par[x] = y;
      sz[y] += sz[x];
    }
    else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x] == rank[y])rank[x]++;
    }
  }
  bool same(ll x, ll y) { return find(x) == find(y); }
  ll size(ll n){return sz[find(n)];}
};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  UF uni(n);
  for(int i=0;i<m;i++){
    ll a,b;cin>>a>>b;
    a--;b--;
    uni.merge(a,b);
  }
  set<ll>se;
  for(int i=0;i<n;i++){
    se.insert(uni.find(i));
  }
  cout<<se.size()-1<<endl;
  return 0;
}

Measured memory_bytes: 9188
A, B = map(int, input().split())

ans = 0
if B - A < 2:
    for i in range(A, B + 1):
        ans ^= i
else:
    if A ^ (A + 1) == 1:
        if (A % 2) == (B % 2):
            ans ^= B
            ans ^= 1 if (((B - 1) - (A - 1)) // 2) % 2 == 1 else 0
        else:
            ans ^= 1 if ((B - (A - 1)) // 2) % 2 == 1 else 0
    else:
        # (A + 1) ^ (A + 2) == 1
        if ((A + 1) % 2) == (B % 2):
            ans ^= A
            ans ^= B
            ans ^= 1 if (((B - 1) - A) // 2) % 2 == 1 else 0
        else:
            ans ^= A
            ans ^= 1 if ((B - A) // 2) % 2 == 1 else 0
print(ans)


Measured memory_bytes: 3064