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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
char s[55][55];
int dx[4] = {0,0,1,-1};
int dy[4] = {-1,1,0,0};
int d[55][55];
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int h,w,white = 0;
    cin >> h >> w;
    rep(i,h)rep(j,w){
        cin >> s[i][j];
        if(s[i][j]=='.')white++;
    }
    queue<pair<int,int>> q;
    d[0][0] = 1;
    q.push({0,0});
    while(!q.empty()){
        auto f = q.front();q.pop();
        rep(i,4){
            int nx = f.first + dx[i];
            int ny = f.second+ dy[i];
            if(nx<0||ny<0||nx>=h||ny>=w)continue;
            if(s[nx][ny]=='#')continue;
            if(d[nx][ny])continue;
            if(nx==h-1 && ny==w-1){
                cout << white - 1 - d[f.first][f.second] << endl;
                return 0;
            }else{
                d[nx][ny] = d[f.first][f.second] + 1;
                q.push({nx,ny});
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = list(map(lambda x:-x,map(int,readline().split())))

import heapq
heapq.heapify(A)

for i in range(M):
  val = heapq.heappop(A)
  heapq.heappush(A,((val * (-1))// 2) * (-1))

print(-sum(A))

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

int main()
{
  int N;
  cin >> N;
  typedef long long ll;
  vector<ll> A(N), C(N + 1);
  for (auto & a : A)
  {
    cin >> a;
    ++C[a];
  }
  ll sum = 0;
  for (const auto & c : C)
    sum += c*(c - 1)/2;
  for (const auto & a : A)
    cout << sum - (C[a] - 1) << endl;
  return 0;
}


Measured memory_bytes: 5760
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<fstream>
#include<complex>
#include<algorithm>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
int dp[10010];
pair<int,int> pii[1010];
set<int> st;
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int h,n;
	cin>>h>>n;
	for(int i=1;i<=n;i++){
		cin>>pii[i].second>>pii[i].first;
	}
	//cout<<pii[6].first<<endl;
	memset(dp,INF,sizeof dp);
	dp[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=pii[i].second;j<=h;j++){
			dp[j]=min(dp[j],dp[j-pii[i].second]+pii[i].first);
		}
	}
	n++;
	pii[n].first=0,pii[n].second=0;
	for(int i=0;i<=h;i++){
		if(dp[i]!=INF){
			for(int j=1;j<=n;j++){
				if(i+pii[j].second>=h){
					//cout<<pii[6].first<<" "<<pii[6].second<<endl;
					//cout<<i<<" "<<j<<" "<<i+pii[j].second<<" "<<dp[i]+pii[j].first<<" "<<pii[j].first<<endl;
					st.insert(dp[i]+pii[j].first);
				}
			}
		}
	}
	cout<<*st.begin()<<endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
vector<pair<ll, ll>> prime_fact(ll n) {
    vector<pair<ll, ll>> v;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0)
            continue;
        ll cnt = 0;
        while (n % i == 0) {
            cnt++;
            n /= i;
        }
        v.emplace_back(i, cnt);
    }
    if (n != 1)
        v.emplace_back(n, 1);
    return v;
}
int main(){
    ll A, B;
    cin >> A >> B;
    ll x = gcd(A, B);
    const auto &v = prime_fact(x);
    cout << v.size() + 1 << endl;
}

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

int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  int A[Q],P[N]={};
  for(int i=0;i<Q;i++){
    cin>>A[i];
  }
  for(int i=0;i<Q;i++){
    ++P[A[i]-1];
  } 
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=P[i];
  }
  for(int i=0;i<N;i++){
    if(K-(sum-P[i])>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 1408
k, a, b = map(int, input().split())

if b - a <= 2:
    print(k + 1)
else:
    change = max(0, k - (a - 1))
    if change == 0:
        print(k+1)
    elif change % 2 == 1:
        print(change // 2 * (b-a) + 1 + a)
    else:
        print(change // 2 * (b-a) + a)


Measured memory_bytes: 2940
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,ll> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999999;

void dfs(vector<ll> &distance, int now, vector<vector<P> > &G){
    //cout<<"debug"<<endl;
    for(P p:G[now]){
        int to=p.first;
        ll cost=p.second;
        if(distance[to]!=INF) continue;
        distance[to]=distance[now]+cost;
        dfs(distance,to,G);
    }
    return ;
}


int main(){
    int n;
    cin>>n;
    vector<vector<P> > G(n);
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        ll c; 
        cin>>c;
        a--; b--;
        G[a].push_back(P(b,c));
        G[b].push_back(P(a,c));
    }
    int q,k;
    cin>>q>>k;
    k--;
    vector<ll> distance(n);
    for(int i=0;i<n;i++) distance[i]=INF;
    distance[k]=0;
    dfs(distance, k, G);
    vector<ll> ans(q);
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        a--; b--;
        ans[i]=distance[a]+distance[b];
    }
    for(int i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
    
}

Measured memory_bytes: 17968
#include<iostream>
#include<cmath>
#include<complex>
using namespace std;

complex<double> p[300];

complex<double> core(int a,int b){
  complex<double> res,mid,norm;

  mid = (p[a]+p[b]) / 2.0;

  norm = (p[a] - p[b]) * complex<double>(0,1);
  norm = norm / abs(norm);
  norm = norm * sqrt(1.0 - abs(mid-p[a])*abs(mid-p[a]));

  res = norm + mid;
  return res;
}
  

int main(){
  int n;
  complex<double> o,r;
  int max,tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> p[i].real() >> p[i].imag();

    max = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i!=j && abs(p[i]-p[j]) < 2.0){
	  o = core(i,j);
	  tmp = 2;
	  for(int k=0;k<n;k++){
	    if(k!=i && k!=j){
	      r = o-p[k];
	      if( r.real()*r.real() + r.imag()*r.imag() <1.0)tmp++;
	    }
	  }
	  if(max < tmp)max = tmp;
	}
      }
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 980
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
N^2は無理

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  vector<ll> pos(400010, 0), sum(400010, 0);
  vector<pair<ll, ll>> jump;
  ll N, K, MOD = 998244353;
  cin >> N >> K;
  rep(i, K){
    ll L, R;
    cin >> L >> R;
    jump.push_back({L, R});
  }
  pos[200001] = 1;
  sum[200001] = 1;
  for(ll i=2; i<=N; i++){
    rep(j, K){
      ll L = jump[j].first;
      ll R = jump[j].second;
      pos[200000 + i] += sum[200000 + i - L];
      pos[200000 + i] -= sum[200000 + i - R - 1];
      pos[200000 + i] += MOD;
      pos[200000 + i] %= MOD;
    }
    sum[200000 + i] = sum[200000 + i - 1];
    sum[200000 + i] += pos[200000 + i];
    sum[200000 + i] %= MOD;
//    cout << "i:" << i << " pos:" << pos[200000 + i]
//      << " sum:" << sum[200000 + i] << endl;
  }
  cout << pos[200000 + N] << endl;
}


Measured memory_bytes: 9476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){


	ll n; cin >> n;


	for(ll a = 1; a <= 3500; a++){
		for(ll b = a; b <= 3500; b++){
			ll d = 4*a*b - n*b - n*a;

			if(d==0 && n*a*b == 0){
				printf("%lld %lld %lld\n",a,b,1);
				return 0;
			}
			
			if(d>0 && n*a*b % d == 0 && n*a*b / d > 0){
				printf("%lld %lld %lld\n",a,b,n*a*b / d);
				return 0;				
			}
			
		}
	}


	assert(false);
}

int main(){

	return mainsolve();
}

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

int main() {
    int h,w;
    cin >> h >> w;
    cout << h*w << " " << 2*(h+w) << endl;
}


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

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,total = 0; cin >> n >> m;
    FOR(i,m){
        int a; cin >> a;
        total += a;
    }
    if(total > n) cout << -1 << endl;
    else cout << n-total << endl;
    return 0;
}


Measured memory_bytes: 3652
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_c

n = int(input())

strings = []
for _ in range(n):
    strings.append(input())

ab = 0 # ABが内部にあるもの
tail_a = 0 # 末尾がAのもの
head_b = 0 # 先頭がBのもの
both = 0
for s in strings:
    ab += s.count('AB')
    if s[-1] == 'A' and s[0] != 'B':
        tail_a += 1
    if s[0] == 'B' and s[-1] != 'A':
        head_b += 1
    if s[-1] == 'A' and s[0] == 'B':
        both += 1
ans = ab 
if both == 0:
    ans += min(tail_a, head_b)
elif tail_a + head_b > 0:
    ans += both + min(tail_a, head_b)
elif tail_a == 0 and head_b == 0:
    ans += max(both - 1, 0)
print(ans)

Measured memory_bytes: 44504
import bisect
N = int(input())
L = sorted(list(map(int, input().split())))
cnt = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        v = bisect.bisect_left(L, a + b)
        cnt += v - j - 1
print(cnt)


Measured memory_bytes: 3188
/****************************************************************************
Is this the real life? Is this just fantasy?
Caught in a landslide, no escape from reality
Open your eyes, look up to the skies and see
I'm just a poor boy, I need no sympathy
Because I'm easy come, easy go, little high, little low
Any way the wind blows doesn't really matter to me, to me!!!
--------------------------------------------------
CP is quite cool.It becomes cooler when you enjoy learning new things
******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define pool(i,a,b) for(int i=a;i>=b;i--)
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(a) a.size()
#define ff first
#define ss second
#define debug(x) cout<<#x<<" = "<<x<<endl;
const int mod=1e9+7;

void solve()
{
  int n;
  cin>>n;
  vi a(n);

  rep(i,n)  
    cin>>a[i];

  vll pref(n+1,0);
  for(int i=n-1;i>=0;i--)
  {
    pref[i]+=pref[i+1]+a[i];
  }


  ll ans=0;
  for(int i=0;i<n;i++)
  {
    ll res=pref[i+1];
    res%=mod;
    res*=a[i];
    ans+=res;
    ans%=mod;

  }

  cout<<(ans+mod)%mod<<endl;


} 

int main()
{

  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif

  ios::sync_with_stdio(false);
  cin.tie(0);

  int t=1;
  // cin>>t;
  while(t--)
  {
    solve();
  }

  return 0;
}


Measured memory_bytes: 5556
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
int n;
int a[20], b[20], c[20];

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n-1) cin >> c[i];
    int ans = 0;
    rep(i,n) {
        a[i]--;
        ans += b[a[i]];
        if (i > 0 && a[i] == a[i-1]+1) ans += c[a[i-1]];
    }
    cout << ans << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int a , b , k ;
  cin >> a >> b >> k ;
  int now = 0 ;
  vector<int> v(max(a,b));
  
  rep(i,max(a,b)+1){
    if(a%i==0 && b%i==0){
      v.at(now) = i;
      now++;
    }
  }
  
  sort(all(v));
  reverse(all(v));
  
  cout << v.at(k-1);
    
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MEM(x,v) memset(x,v,sizeof(x))
#define MEC(x,y) memcpy(x,y,sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
const int M=1e5+5,P=(int)1e9+7;
template <class T>
inline void Rd(T &p){
	p=0;char c;
	while(c=getchar(),c<48);
	do p=p*10+(c&15);
	while(c=getchar(),c>47);
}
template <class T>
inline void pfn(T p,bool f=true){
	if(p<0)putchar('-'),p=-p;
	else if(p==0)putchar('0');
	static int num[100],tot;
	while(p){num[++tot]=p%10;p/=10;}
	while(tot)putchar(num[tot--]^'0');
	putchar(f?'\n':' ');
}
template <class T>
inline void Max(T &a,T b){if(a<b)a=b;}
template <class T>
inline void Chk(T &a,T b){if(!~b&&(!~a||a>b))a=b;}
ll pow(ll n,int m){
	ll ans=1;
	while(m){
		if(m&1)ans=ans*n%P;
		m>>=1;n=n*n%P;
	}return ans;
}
int n,a[M],cnt[M];
int main(){
	Rd(n);
	int p=-1,l=1,r=n+1;
	for(int i=1;i<=n+1;++i){
		Rd(a[i]);
		cnt[a[i]]++;
		if(cnt[a[i]]==2)p=a[i];
	}
	while(a[l]!=p)++l;--l;
	while(a[r]!=p)--r;++r;
	r=(n+2)-r;
	int sum=l+r+1;
	ll k1=1ll,k2=1ll;
	for(int i=1;i<=n+1;++i){
		k1=k1*(n+1-i+1)%P*pow(1ll*i,P-2)%P;
		if(i==1)k2=1ll;
		else if(i<=sum)k2=k2*(sum-i+1)%P*pow(1ll*(i-1),P-2)%P;
		if(i<=sum)pfn((k1-k2+P)%P);
		else pfn(k1);
	}
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }

typedef struct {
  int v;
  int d;
  int c;
} op_t;

#define debug(x) cout << #x << "==" << x << endl;

const int inf = 1e+8;

typedef long long ll;

#define MAX_N 100000
vector<int> G[MAX_N];


vector<int> color(MAX_N+1, 0);
// vector<int> colored_dist(MAX_N, 0);
bool visited[MAX_N+1][11];
void dfs(int v, int d, int c) {

  if( visited[v][d] ) return;
  visited[v][d] = true;

  if( color[v] == 0 ) {
    color[v] = c;
  }


  if( d == 0 ) return;

  vector<int> to = G[v];

  for( int w : to ) {
    dfs(w, d-1, c);
  }


}

int main() {
  ios::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;

  for(int i = 0; i < M; i++) {
    int v, w;
    cin >> v >> w;
    v--; w--;
    G[v].push_back(w);
    G[w].push_back(v);
  }

  int Q;
  cin >> Q;

  vector<int> v(Q), d(Q), c(Q);
  for(int i = 0; i < Q; i++) {
    cin >> v[i] >> d[i] >> c[i];
    v[i]--;
  }

  for(int i = Q-1; i >= 0; i--) {
    dfs(v[i], d[i], c[i]);
  }


  for(int i = 0; i < N; i++) {
    cout << color[i] << "\n";
  }


  return 0;
}


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

int main(){
    int r, g, b;
    cin >> r >> g >> b;
    int p = g*10 + b;
    if(p % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    bool v1[100],v2[100];
    for (int i = 0; i < 100; i++) {
        v1[i] = false;
        v2[i] = false;
    }
    for (int i = a; i < b; i++) {
        v1[i] = true;
    }
    for (int i = c; i < d; i++) {
        v2[i] = true;
    }
    int ans = 0;
    for (int i = 0; i < 100; i++) {
        if (v1[i] && v2[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))

ans=[0]*n

ans[0]=0
ans[1]=abs(h[1]-h[0])

for i in range(2,n):
  ans[i]=min(ans[i-2]+abs(h[i]-h[i-2]),ans[i-1]+abs(h[i]-h[i-1]))

print(ans[n-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
	{
		cout<<k;
		return 0;
	}
	else if(k<=a+b)
	{
		cout<<a;
		return 0;
	 } 
	else 
	{
		cout<<a-(k-a-b);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 3588
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    for(int i = 0; i < n; i++){
        a[i]--;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += a[a[i]] == i;
    }

    cout << ans/2 << endl;
}



Measured memory_bytes: 768
import sys
N,M = map(int,input().split())

ans = [0] * N
if N != 1:
    ans[0] = 1
flag = [True] * N


for i in range(M):

    s,c = map(int,input().split())
    s -= 1

    if flag[s]:
        ans[s] = c
        flag[s] = False

    elif ans[s] != c:
        print (-1)
        sys.exit()

if len(ans) != 1 and ans[0] == 0:
    print (-1)
    sys.exit()
print ("".join(map(str,ans)))


Measured memory_bytes: 38256
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var N, K, Q int
	fmt.Scan(&N, &K, &Q)
	A := make([]int, Q)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	P := make([]int, N)
	for i := 0; i < Q; i++ {
		A[i] = nextInt(sc)
		A[i]--
		P[A[i]]++
	}
	for i := range P {
		var pass string
		if P[i]+K-Q > 0 {
			pass = "Yes"
		} else {
			pass = "No"
		}
		fmt.Println(pass)
	}
}


Measured memory_bytes: 4736
/**
 *    author:  FromDihPout
 *    created: 2020-07-14
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		int MAX = 1250; // 8%で100円の消費税になる値

		for (int i = 0; i < MAX; i++) {
			if (Math.floor(i * 0.08) == A && Math.floor(i * 0.1) == B) {
				System.out.println(i);
				return;
			}
		}

		System.out.println(-1);
	}
}


Measured memory_bytes: 25044
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 100 + 4;
int cnt, n;
int M[MAXN][MAXN];
int d[MAXN], f[MAXN], status[MAXN];

void dfs( int u )
{
    status[u] = 1;
    d[u] = ++cnt;
    for ( int i = 1; i <= n; i++ ) {
        if ( M[u][i] == 0 ) continue;
        if ( status[i] == 0 ) dfs(i);
    }
    status[u] = -1;
    f[u] = ++cnt;
}

int main()
{
    int u, k, m;
    cnt = 0;
    memset ( M, 0, sizeof(M) );
    memset ( d, 0, sizeof(d) );
    memset ( f, 0, sizeof(f) );
    memset ( status, 0, sizeof(status) );
    cin>>n;
    for ( int i = 0; i < n; i++ ) {
        cin>>u>>k;
        for ( int j = 0; j < k; j++ ) {
            cin>>m;
            M[u][m] = 1;
        }
    }

    for ( int u = 1; u <= n; u++ ) {
        if ( status[u] == 0 ) dfs(u);
    }

    for(int i = 1; i <= n; i++){
        cout<<i<<' '<<d[i]<<' '<<f[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S=in<string>();
    isYes(S[2]==S[3]&&S[4]==S[5]);
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

  vector<int> X(N + 1);
  for (int i = 0; i < N; ++i) X[i + 1] = X[i] ^ A[i];

  for (int i = 0; i < N; ++i) {
    int l = X[i];
    int r = X[N] ^ X[i + 1];
    cout << (l ^ r) << " \n"[i + 1 == N];
  }

  return 0;
}



Measured memory_bytes: 4692
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;


int main()
{
  long long int M=10E16,sum1=0,sum2=0,A[200001],x1,x2,ok=10E9,ng=-10E9,s;
  int N;
  cin >> N;
  REP(i,N) cin >> A[i];
  REP(i,N) A[i] = A[i] - (i+1);
  while(abs(ok-ng) > 3){
    sum1 = 0;
    sum2 = 0;
    x1 = ng + (ok-ng)/3;
    x2 = ng + (2*(ok-ng))/3;
    REP(i,N)sum1 += abs(A[i] - x1);
    REP(i,N)sum2 += abs(A[i] - x2);
    if(sum1 > sum2){
      ng = x1;
    }else
      ok = x2;
    M = min(M,min(sum1,sum2));
  }
  for(long long int j = ok;ok<=ng;j++){
    sum1 = 0;
    sum2 = 0;
    x1 = ng + (j-ng)/3;
    x2 = ng + (2*(j-ng))/3;
    REP(i,N)sum1 += abs(A[i] - x1);
    REP(i,N)sum2 += abs(A[i] - x2);
    M = min(M,min(sum1,sum2));
  }
  
  cout << M << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using ll = long long;
#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
// const int MOD = 1000000007;

template <typename T>
void __print__(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void __print__(std::ostream &os, const char *del, const char *tail, const Fst &fst,
               const Rst &... rst) {
    os << fst << del;
    __print__(os, del, tail, rst...);
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __print__(os, ", ", "\n", __VA_ARGS__);           \
        std::cerr << os.str();                            \
    } while (0)
#else
#define dump(...)
#endif

template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    __print__(std::cout, " ", "\n", fst, rst...);
}

template <typename iter>
void println_(iter bgn, iter end) {
    while (bgn != end) println(*bgn++);
}

template <typename iter>
void print_(iter bgn, iter end) {
    while (bgn != end) {
        std::cout << *bgn++;
        std::cout << (bgn == end ? "\n" : " ");
    }
}

int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
         std::ios::sync_with_stdio(0), 0);

template <typename T>
std::vector<T> ndarray(int n, T v) {
    return std::vector<T>(n, v);
}
template <typename... Args>
auto ndarray(int n, Args... args) {
    auto val = ndarray(args...);
    return std::vector<decltype(val)>(n, move(val));
}

template <typename T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, true : false;
}

template <typename T>
bool umin(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

using namespace std;

signed main() {
    ll n;
    while (cin >> n) {
        FOR(a, 1, 4000) {
            FOR(b, 1, 4000) {
                int x = a*b*n;
                int y = 4*a*b - n*b - n*a;
                if (y == 0) continue;
                int c = x / y;
                if (c * y == x && c >= 1) {
                    print(a, b, c);
                    a = b = 10000;
                }
            }
        }
    }
}


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

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

int min(vector<int> x) {
    int min = -1;
    rep(i, x.size()) {
        if(min == -1 || min > x[i])
            min = x[i];
    }
    return min;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    vector<int> x(M);
    vector<int> y(M);
    vector<int> c(M);

    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) cin >> x[i] >> y[i] >> c[i];
    int amin = min(a);
    int bmin = min(b);
    int ans = amin+bmin;

    rep(i,M){
        ans = min(ans,a[x[i]-1]+b[y[i]-1]-c[i]); 
    }
    cout << ans <<endl;
}

Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n,m; cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i,m){
        cin >> s[i] >> c[i]; s[i]--;
    }
    rep(i, pow(10,n)){
        bool flag = true;
        string S = to_string(i);
        if(S.size() != n) flag = false;
        rep(k,m){
            if((S[s[k]] - '0') != c[k]){
                flag = false;
            }
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }

    cout << "-1" << endl;
}


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

def factorization_in_prime_number(x):
    prime_factor = []
    degree = 0
    while x % 2 == 0:
        x //= 2
        degree += 1
    if degree:
        prime_factor.append((2, degree))
    m = int(x**.5) + 1
    for i in range(3, m, 2):
        degree = 0
        while x % i == 0:
            x //= i
            degree += 1
        if degree:
            prime_factor.append((i, degree))
    if x != 1:
        prime_factor.append((x, 1))
    return prime_factor


z = factorization_in_prime_number(N)
ans = 0
for x, i in z:
    cnt = 0
    while cnt*(1+cnt)/2 < i:
        cnt += 1
    if cnt*(1+cnt)/2 > i:
        cnt -= 1
    # print(cnt, i)
    ans += cnt
print(ans)


Measured memory_bytes: 9420
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_tuple() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn main() {
    let n: usize = input();
    let mut c_vec: Vec<u64> = Vec::new();
    let mut s_vec: Vec<u64> = Vec::new();
    let mut f_vec: Vec<u64> = Vec::new();
    for i in 0..(n-1) {
        let (c, s, f) = input_tuple();
        c_vec.push(c);
        s_vec.push(s);
        f_vec.push(f);
    }

    for i in 0..n {
        let mut t = 0;
        // println!("i = {}", i);
        for j in (i+1)..n {
            if t < s_vec[j - 1] {
                t = s_vec[j - 1] + c_vec[j - 1];
            } else {
                if t % f_vec[j - 1] == 0 {
                    t += c_vec[j - 1];
                } else {
                    t = t - (t % f_vec[j - 1]) + f_vec[j - 1] + c_vec[j - 1];
                }
            }
            // println!("{} {}", j, t);
        }
        println!("{}", t);
    }
}


Measured memory_bytes: 2144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int k = nextInt();
        int[][][] q = new int[2][2 * k + 1][2 * k + 1];
        for (int i = 0; i < n; i++) {
            int x = nextInt() % (2 * k);
            int y = nextInt() % (2 * k);
            int c = "BW".indexOf(next());
            q[c][x + 1][y + 1]++;
        }
        for (int c = 0; c < 2; c++) {
            for (int x = 1; x <= 2 * k; x++) {
                for (int y = 1; y <= 2 * k; y++) {
                    q[c][x][y] += q[c][x - 1][y] + q[c][x][y - 1] - q[c][x - 1][y - 1];
                }
            }
        }
        int res = Integer.MIN_VALUE;
        for (int x = 1; x <= k; x++) {
            for (int y = 1; y <= k; y++) {
                for (int c = 0; c < 2; c++) {
                    int s = calc(q[c], 0, 0, x, y) + calc(q[1 - c], x, 0, x + k, y) + calc(q[c], x + k, 0, 2 * k, y) +
                            calc(q[1 - c], 0, y, x, y + k) + calc(q[c], x, y, x + k, y + k) + calc(q[1 - c], x + k, y, 2 * k, y + k) +
                            calc(q[c], 0, y + k, x, 2 * k) + calc(q[1 - c], x, y + k, x + k, 2 * k) + calc(q[c], x + k, y + k, 2 * k, 2 * k);
                    res = Math.max(res, s);
                }
            }
        }
        out.println(res);
    }

    private int calc(int[][] q, int x1, int y1, int x2, int y2) {
        return q[x2][y2] + q[x1][y1] - q[x1][y2] - q[x2][y1];
    }

    // ------------------

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 97756
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<complex>
#include<set>
#include<map>
#include<algorithm>

using namespace std;

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

const int R = 22;
const int N = 101;
const int INF = 1000000000;
const int M = N*222;

int n,m,r,s,g;

int cost[R][M];
int dplen[R][N][N];
int dpcost[N][N];

void init(){
	reps(i,1,r+1){
		reps(j,1,n+1)reps(k,1,n+1)dplen[i][j][k]=INF;
		reps(j,1,n+1)dplen[i][j][j]=0;
	}
	reps(i,1,n+1)reps(j,1,n+1)dpcost[i][j]=INF;
}

void wf_length(){
	reps(p,1,r+1){
		reps(k,1,n+1){
			reps(i,1,n+1){
				reps(j,1,n+1){
					dplen[p][i][j] = min(dplen[p][i][j], dplen[p][i][k] + dplen[p][k][j]);
				}
			}
		}
	}
}

void wf_cost(){
	reps(k,1,r+1){
		reps(i,1,n+1){
			reps(j,1,n+1){
				if(dplen[k][i][j]==INF)continue;
				dpcost[i][j] = min(dpcost[i][j], cost[k][dplen[k][i][j]]);
			}
		}
	}
	
	reps(k,1,n+1){
		reps(i,1,n+1){
			reps(j,1,n+1){
				dpcost[i][j] = min(dpcost[i][j], dpcost[i][k]+dpcost[k][j]);
			}
		}
	}
}
int solve(){
	init();
	
	rep(i,m){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		dplen[d][a][b] = min(dplen[d][a][b],c);
		dplen[d][b][a] = min(dplen[d][b][a],c);
	}
	
	
	int p[R];
	reps(i,1,r+1)cin>>p[i];
	reps(i,1,r+1){
		int change[55];
		int c[55];
		rep(j,p[i]-1)cin>>change[j];
		rep(j,p[i])cin>>c[j];
		
		int pos = 0;
		reps(j,1,M){
			cost[i][j] = cost[i][j-1]+c[pos];
			if(pos!=p[i]-1 && j==change[pos])pos++;
		}
	}
	
	wf_length();
	wf_cost();
	
	int ans = dpcost[s][g];
	if(ans==INF)return -1;
	return ans;
}

int main(){
	while(1){
		cin>>n>>m>>r>>s>>g;
		if(n==0 && m==0)break;
		printf("%d\n",solve());
		//break;
	}
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, p=0;
  cin >> n >> m;
  vec2ll a(n, vecll(2));
  forll(i, 0, n)
	cin >> a[i][0] >> a[i][1];
  sort(a.begin(), a.end());
  forll(i, 0, n){
	if (m < 0)
	  break;
	p += min(m * a[i][0], a[i][1] * a[i][0]);
	m -= a[i][1];
  }
  cout << p << endl;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    ll a, b;
    cin >> n >> a >> b;
    ll c = a - b;
    vector<ll> v(n);
    for(auto& i : v){
        cin >> i;
    }
    sort(all(v));
    ll left = 0, right = v.back()/b  + 1;
    while(left <= right){
        ll mid = (left + right)/2;
        ll cnt1 = 0, cnt2 = 0;
        for(auto i : v){
            cnt1 += max(0LL, (i - b*(mid-1) + c - 1)/c);
            cnt2 += max(0LL, (i - b*mid + c - 1)/c);
        }
        if(cnt1 <= mid-1){
            right = mid - 1;
        }else if(cnt2 > mid){
            left = mid + 1;
        }else{
            cout << mid << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S, T;
    cin >> S >> T;
    ll ans = 0;
    Rep (i, 3) {
        if (S[i] == T[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<cstdlib>
using namespace std;
int get(int a, int b){
    if(a>b)return 2e9;
    return b-a;
}
int main()
{
    int a, b;
    scanf("%d%d",&a,&b);
    printf("%d\n",min(min(get(a,b),get(-a,b)+1),min(get(-a,-b)+2,get(a,-b)+1)));
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define N 100005
#define ll long long
#define db double
#define dbg1(x) cout<<#x<<"="<<x<<" "
#define dbg2(x) cout<<#x<<"="<<x<<"\n"
int n,A[N],ans1,ans2;
db fac[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	sort(A+1,A+1+n),ans1=A[n];
	int pos=lower_bound(A+1,A+1+n,ans1+1>>1)-A;
//	dbg2(pos);
	if(pos==1) ans2=A[1];
	else if(pos==n) ans2=A[n-1];
	else ans2=A[pos-1]<ans1-A[pos]?A[pos]:A[pos-1];
	printf("%d %d\n",ans1,ans2);
	return 0;
}


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


int main()
{
    string S, T, U;
    int A, B;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if (U == S)
    {
        A = A - 1;
        cout << A <<"  " << B;
    }
    else if (U == T)
    {
        B = B - 1;
        cout << A <<"  "<< B;
    }

    system("pause");
    return 0;
}

Measured memory_bytes: 504
#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;

    string keyence = "keyence";
    string value;

    if (S == keyence)
    {
        cout << "YES" << endl;
        return 0;
    }
    rep(i, S.size())
    {
        for (int j = i + 1; j < S.size(); j++)
        {
            if (S.substr(0, i) + S.substr(j, S.size()) == keyence)
            {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static int ans[] ;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int list[] = new int[n];

        for(int i=0;i<n;i++){
            list[i] = sc.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            for(int i=0;i<n;i++){
                if(list[i]%2 == 1){
                    flag = false;
                }
                list[i] = list[i]/2;
                if(i == n-1 && flag){count++;}
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359


ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b % a;  b = c;
	}
	return b;
}

int main() {
	ll N=0;
	string S;
	cin >> S;
	REP(i, 4) {
		if (S[i] == '+') {
			N++;
		}
		else {
			N--;
		}
	}
	
	cout << N;

	return 0;



}

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

using namespace std;

const int MAX = 1000 * 1000 + 11;
int divv[MAX];

int res = 0;
void Seive()
{
    for(int i = 2; i <= MAX; i++)
    {
        if(divv[i] == 0)
        {
            for(int j = i; j <= MAX; j += i)
            {
                divv[j] = i;
            }
        }
    }
}

int findPairs(int n)
{   
    map<int, int> mp;
    while(n != 1)
    {   
        int x = divv[n];
        mp[x]++;
        n /= x;
    }

    int totalDiv = 1;
    for(auto it: mp)
    {
        totalDiv *= (it.second + 1);
    }

    return totalDiv;
}

int main()
{
    Seive();
    int n; cin >> n;

    for(int i = 1; i < n; i++)
    {
        int pairs = findPairs(n - i);
        res += pairs;
    }

    cout << res;
    return 0;
}


Measured memory_bytes: 7540
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>

using namespace std;

int main()
{
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i < 1000010; ++i) {
    if ((N - i) % i == 0) {
      long long x = (N - i) / i;
      if (i < x) ans += x;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int64_t N,M;
    cin >> N >> M;
    vector<int64_t> P(M),Y(M);
    for ( int64_t i = 0; i < M; ++i){
        cin >> P[i] >> Y[i];
    }
    
    
    vector<vector<int64_t>> X(M,vector<int64_t>(2)); // year, number
    for ( int64_t i = 0; i < M; ++i){
        X[i][0] = Y[i];
        X[i][1] = i;
    }
    sort(X.begin(),X.end());
    
    //vector<vector<int64_t>> Z(M,vector<int64_t>(2)); // number, fast
    map<int64_t,int64_t> m,m2;
    for ( int64_t i = 0; i < M; ++i){
        int64_t x = X[i][1];
        int64_t p = P[X[i][1]];
        m[p] = m[p] + 1;
        // 市pができたのはm[p]番目
        m2[x] = m[p];
    }
    
    for ( int64_t i = 0; i < M; ++i){
        int64_t a = P[i]; // 何市にあるか
        int64_t b = m2[i]; // 何番目にできたか
        int64_t ak = unsigned (log10(a) + 1);
        int64_t bk =unsigned (log10(b) + 1);
        for ( int64_t i = 0; i < 6-ak; ++i){
            cout << "0";
        }
        cout << a;
        for ( int64_t i = 0; i < 6-bk; ++i){
            cout << "0";
        }
        cout << b << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 22560
N = int(input())
A = list(map(int, input().split()))


# dp[i]: 
# i日目時点で，
# あらゆる売買の組み合わせを考慮したときの
# 最適な(最大化された)所持金の値
dp = [0] * N

dp[0] = 1000 # 初日は1000円が最適
for i in range(1, N):
  
  for j in range(0, i):
    # j日目に買える最大株数vは？
    v = int(dp[j] / A[j])
    
    # j日目にv株買って(マイナスv*A[j]円)，
    # i日目までガチホして，
    # i日目の株価で全部売った時(プラスv*A[i]円)，
    # i日目の所持金wはいくらになる？
    w = dp[j] - v*A[j] + v*A[i]
    
    dp[i] = max(dp[i-1], w)
    
print(max(dp))   
    
 

Measured memory_bytes: 9136
N=int(input())
L=[int(i) for i in input().split()]
L=sorted(L)
ans=0
import bisect

for i in range(N-2):
    for j in range(i+1,N-1):
        insert_index = bisect.bisect_left(L,L[i]+L[j])
        ans+=insert_index-j-1
        
print(ans)

Measured memory_bytes: 44796
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
# while 1:
if len(S)==26:
    end = S[-1]
    lis = [end]
    for i in range(24, -1, -1):
        if ord(S[i])<ord(end):
            for s in lis:
                if ord(S[i])<ord(s):
                    S[i] = s
                    break
            S = S[:i+1]
            print(''.join(S))
            break
        else:
            lis.append(S[i])
            end = S[i]
    else:
        if S[0]=='z':
            print(-1)
        else:
            S = [chr(ord(S[0])+1)]
            print(S[0])
else:
    check = [0]*26
    for s in S:
        check[ord(s)-97] = 1
    for i in range(26):
        if not check[i]:
            S.append(chr(i+97))
            break
    print(''.join(S))



Measured memory_bytes: 61848
n, k = map(int, input().split())
ans = ""
if n % 2 == 0:
  if n / 2 >= k:
    ans = "YES"
  else:
    ans = "NO"
else:
  if n // 2 + 1 >= k:
    ans = "YES"
  else:
    ans = "NO"
print(ans)

Measured memory_bytes: 3060