akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 87;
ll n, k, a[N];
ll c0, cn, cp;
ll solvene()
{
    vector<ll> x(a, a + cn);
    vector<ll> y(a + n - cp, a + n);
    ll lo = x[0] * y.back();
    ll hi = x.back() * y[0];
    //cerr << "lo hi "<< lo << ' '<< hi << endl;
    reverse(x.begin(), x.end());
    reverse(y.begin(), y.end());
    //cerr << "x= "; for (ll t : x) cerr << t << ' '; cerr << endl;
    //cerr << "y= "; for (ll t : y) cerr << t << ' '; cerr << endl;
    while (lo <= hi) {
        ll mi = lo + (hi - lo) / 2;
        ll c = 0;
        for (ll i = 0, j = 0; i < x.size(); ++i) {
            for (; j < y.size() && x[i] * y[j] <= mi; ++j);
            //cerr << "i,j,x[i] " << i << ' ' << j << ' ' << x[i]<< endl;
            c += j;
        }
        //cerr << "mi, c "<< mi << ' ' << c << endl;
        if (c < k)
            lo = mi + 1;
        else
            hi = mi - 1;
    }
    return lo;
}
ll solvenp(ll k)
{
    vector<ll> x(a, a + cn);
    reverse(x.begin(), x.end());
    vector<ll> y(a + n - cp, a + n);
    ll lo = LLONG_MAX;
    ll hi = LLONG_MIN;
    if (x.size() >= 2) {
        lo = min(lo, x[0] * x[1]);
        hi = max(hi, x[cn - 1] * x[cn - 2]);
    }
    if (y.size() >= 2) {
        lo = min(lo, y[0] * y[1]);
        hi = max(hi, y[cp - 1] * y[cp - 2]);
    }
    while (lo <= hi) {
        ll mi = lo + (hi - lo) / 2;
        ll c = 0;
        for (ll i = cp - 1, j = 0; i >= 0; --i) {
            for (; j < i && y[i] * y[j] <= mi; ++j);
            c += min(j, i);
        }
        for (ll i = cn - 1, j = 0; i >= 0; --i) {
            for (; j < i && x[i] * x[j] <= mi; ++j);
            c += min(j, i);
        }
        //cerr << "mi, c " << mi << ' ' << c << endl;
        if (c < k)
            lo = mi + 1;
        else
            hi = mi - 1;
    }
    return lo;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] == 0)
            ++c0;
        else if (a[i] > 0)
            ++cp;
        else
            ++cn;
    }
    sort(a, a + n);
    ll ne = cn * cp;
    ll n0 = c0 * (c0 - 1) / 2 + c0 * (n - c0);
    ll np = cp * (cp - 1) / 2 + cn * (cn - 1) / 2;
    ll ans;
    if (k <= ne) {
        ans = solvene();
    } else if (k <= ne + n0) {
        ans = 0;
    } else {
        ans = solvenp(k - ne - n0);
    }
    cout << ans << "\n";
}


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

int main(){
    int r, d, x0;
    cin >> r >> d >> x0;

    int x1 = x0;
    for (int i = 0; i < 10; ++i){
        x1 = r*x1 - d;
        cout << x1 << endl;
    }
}

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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

ll cnt(ll start, ll c, ll d)
{
	return start - start / c - start / d + start / lcm(c, d);
}

void solve()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	// cout << cnt(b, c, d) << ' ' << cnt(a - 1, c, d) << '\n';
	cout << cnt(b, c, d) - cnt(a - 1, c, d);
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
D = []
ans = 0
for i in range(M):
  a,b = map(int, input().split())
  a -= 1
  b -= 1
  D.append((a,b))
for i in range(M):
  visited = [0]*N
  x,y = D.pop(i)
  C = [[] for i in range(N)]
  for j in range(M-1):
    a,b = D[j]
    C[a].append(b)
    C[b].append(a)
  H = deque()
  H.append(0)
  while H:
    e = H.popleft()
    if visited[e] == 0:
      visited[e] = 1
      for k in range(len(C[e])):
        H.append(C[e][k])
  D.insert(i,(x,y))
  if all(visited):
    continue
  else:
    ans += 1
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;

    REP(i,10) REP(j,10) REP(k,10){
        bool fi = false, se = false;
        REP(l, N){
            if(!fi && S[l] == i + '0'){
                fi = true;
                continue;
            }
            if(fi && !se && S[l] == j + '0'){
                se = true;
                continue;
            }
            if(fi && se && S[l] == k + '0'){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct S {
    ll a, b, diff;
    
    bool operator<(const S &b) const {
        return diff > b.diff;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<S> exam(n);
    rep(i, n) cin >> exam[i].a;
    rep(i, n) cin >> exam[i].b;
    rep(i, n) exam[i].diff = exam[i].a - exam[i].b;
    sort(all(exam));
    deque<pair<ll, bool>> dq;
    ll cnt = 0;
    rep(i, n) {
        if (exam[i].diff == 0) {
            continue;
        }
        else if (exam[i].diff > 0) {
            dq.push_back(make_pair(exam[i].diff, false));
            cnt++;
        }
        else {
            while(exam[i].diff < 0) {
                // printf("i=%lld, v=%lld\n", i, exam[i].diff);
                if (sz(dq) == 0) {
                    cout << -1 << endl;
                    return 0;
                }
                pair<ll, bool> p = dq.front(); dq.pop_front();
                ll a = min(abs(exam[i].diff), p.first);
                exam[i].diff += a;
                p.first -= a;
                p.second = true;
                if (p.first > 0) dq.push_front(p);
            }
            cnt++;
        }
    }
    ll ans = cnt - sz(dq);
    rep(i, sz(dq)) {
        if (dq[i].second) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n>= 64){
    cout << 64 << endl;
  }else if(n >= 32){
    cout << 32 << endl;
  }else if(n >= 16){
    cout << 16 << endl;
  }else if(n >= 8){
    cout << 8 << endl;
  }else if(n >= 4){
    cout << 4 << endl;
  }else if(n >= 2){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 301
using namespace std;
int w[N],mem[N][N],used[N][N];

int dfs(int l,int r){
  if(l==r) return 0;
  if(r-l==1) return 2*(abs(w[l]-w[r])<=1);
  if(used[l][r]++) return mem[l][r];
  
  int res=0;
  if(abs(w[l]-w[r])<=1&&dfs(l+1,r-1)==r-l-1)res=2+dfs(l+1,r-1);
  
  for(int i=l;i<r;i++) res=max(res,dfs(l,i)+dfs(i+1,r));
  return mem[l][r]=res;
}

int main(){
  int n;
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>w[i];
    memset(used,0,sizeof(used));
    cout<<dfs(0,n-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

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; }
const int INF = 1LL << 60;

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

	cout << std::floor(std::log(n) / std::log(k) + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    vector<vector<ll>> rg(n,vector<ll>(n,0));
    vector<vector<bool>> p(n,vector<bool>(n,false));
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++) cin >>rg[i][j];
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++) {
            ll rgii=rg[i][j];
            for (int k=0;k<n;k++)
                if (k!=i and k!=j){
                    ll byp=rg[i][k]+rg[k][j];
                    if (rgii>byp) {
                        cout << -1 << endl;
                        return 0;
                    }
                    else if (rgii==byp)p[i][j]=true;
                }
        }
    ll rel=0;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (!p[i][j]) rel+=rg[i][j];
    cout << rel << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FL "a"
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=3005;
inline ll read(){
  ll d=0,w=1;char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')d=d*10+ch-48,ch=getchar();
  return d*w;
}
inline void file(){
  freopen(FL".in","r",stdin);
  freopen(FL".out","w",stdout);
}

inline void upd(int &a,int b){a+=b;if(a>=mod)a-=mod;}
inline void dec(int &a,int b){a-=b;if(a<0)a+=mod;}
inline int poww(int a,int b){
  int res=1;
  for(;b;b>>=1,a=1ll*a*a%mod)
    if(b&1)res=1ll*res*a%mod;
  return res;
}

int n,m,dp[N][N][2],ans;
int main()
{
  n=read();m=read();
  for(int i=0;i<=n;i++)dp[0][i][i==0]=1;
  for(int i=0;i<m;i++)
    for(int j=0;j<=n;j++)
      for(int k=0;k<2;k++){
	if(j){
	  upd(dp[i+1][j-1][k|(j==1)],dp[i][j][k]);
	  upd(dp[i+1][j][k|(j==1)],dp[i][j][k]);
	}
	if(j!=n){
	  upd(dp[i+1][j][k],dp[i][j][k]);
	  upd(dp[i+1][j+1][k],dp[i][j][k]);
	}
      }
  for(int i=0;i<=n;i++)upd(ans,dp[m][i][1]);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

struct cake{
	int w, d, p;
	cake(int w_, int d_, int p_){
		w = w_; d = d_; p = p_;
	}
	cake(){
		w = 0; d = 0; p = 0;
	}
};
typedef pair<cake,cake> P;

// c := 切ろうとしているケーキ, s := 切る位置
P cut(cake c, int s){
	int w1, w2, d1, d2;
	
	s %= c.w + c.d;
	if( s < c.w ){
		w1 = s;
		w2 = c.w - s;
		d1 = d2 = c.d;
	}else{
		s -= c.w;
		d1 = s;
		d2 = c.d - s;
		w1 = w2 = c.w;
	}
	if( w1 * d1 > w2 * d2 ){
		swap( w1 , w2 );
		swap( d1 , d2 );
	}
	// firstが小さいケーキ, secondが大きいケーキ
	cake c1( w1 , d1 , 0 );
	cake c2( w2 , d2 , 0 );
	P result( c1 , c2 );
	return result;
}

int main(){
	int n, w, d;
	while( cin >> n >> w >> d, n || w || d ){		
		vector<cake> now;
		vector<cake> next;
		
		next.push_back( cake(w,d,1) );
		for(int i=1 ; i <= n ; i++ ){
			int p, s;
			now = next;
			next.clear();
			
			cin >> p >> s;
			for(int j=0 ; j < now.size() ; j++ ){
				if( now[j].p == p ){
					P p_cake = cut( now[j] , s );
					// 小さいケーキ
					p_cake.first.p = i;
					next.push_back( p_cake.first );
					// 大きいケーキ
					p_cake.second.p = i+1;
					next.push_back( p_cake.second );
				}else{
					if( now[j].p > p ) 
						now[j].p--;
					next.push_back( now[j] );
				}
			}
		}
		vector<int> ans;
		for(int i=0 ; i < next.size() ; i++ ){
			ans.push_back( next[i].w * next[i].d );
		}
		sort( ans.begin() , ans.end() );
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << ans[i];
			if( i == ans.size()-1 )
				cout << endl;
			else
				cout << " ";
		}
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define fcout cout << fixed << setprecision(10)
array<array<bool,701>,701> road;
vector<tuple<int,int,int> > independ;
array<bool, 701>taka,hasi,used;
int n,m;
bool divide(int a){
    if(used[a])return false;
    int i;
    for(i=1;i<n+1;i++)if(taka[i]&&!road[a][i])break;
    if(i==n+1){
        taka[a]=used[a]=true;
        rep(i, 1, n+1)if(!road[a][i])if(divide(i))return true;
        return false;
    }
    for(i=1;i<n+1;i++)if(hasi[i]&&!road[a][i])break;
    if(i==n+1){
        hasi[a]=used[a]=true;
        rep(i, 1, n+1)if(!road[a][i])if(divide(i))return true;
        return false;
    }
    cout<<-1;
    return true;
}
int main(){
    cin>>n>>m;
    int a,b;
    rep(i,0,m){
        cin>>a>>b;
        road[a][b]=road[b][a]=true;
    }
    rep(i, 1, n+1){
        road[i][i]=true;
    }
    rep(i,1,n+1){
        if(divide(i))return 0;
        a=accumulate(taka.begin(), taka.end(), 0);
        b=accumulate(hasi.begin(), hasi.end(), 0);
        independ.push_back(make_tuple(abs(a-b),max(a,b),min(a,b)));
        rep(i, 1, n+1)taka[i]=hasi[i]=false;
    }
    sort(independ.begin(),independ.end());
    a=b=0;
    for(int i=independ.size()-1;i>=0;i--){
        if(a<b){
            a+=get<1>(independ[i]);
            b+=get<2>(independ[i]);
        }
        else{
            a+=get<2>(independ[i]);
            b+=get<1>(independ[i]);
        }
    }
    cout<<a*(a-1)/2+b*(b-1)/2;
}

Measured memory_bytes: 768
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")

#define DEBUG(x) cout << ">> " << #x << ": " << x << endl;
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
typedef long long ll;
typedef long double ld;

int main() { _
  ll n, m; cin >> n >> m;
  ll total = 0;
  priority_queue<ll> pq;
  for (ll i = 0; i < n; i++) {
    ll temp; cin >> temp;
    total += temp;
    
    for (;temp > 0; temp/=2) {
      ll diff = temp - temp/2;
      pq.push(diff);
    }
  }
  for (int i = 0; i < m; i++) {
    total -= pq.top();
    if (total < 0) {
      cout << 0 << endl;
      return 0;
    }
    pq.pop();
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 35044
#include <stdio.h>
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main(){
	int a,b,c,g;
	scanf("%d%d%d",&a,&b,&c);
	g=gcd(a,b);
	printf("%d\n",a/g*b/g*c);
}

Measured memory_bytes: 2716
from collections import deque

N, Q = map(int,input().split())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int,input().split())
    a -= 1
    b -= 1
    ad[a].append(b)
    ad[b].append(a)

cnt = [0] * N

for _ in range(Q):
    p, x = map(int,input().split())
    p -= 1
    cnt[p] += x

ans_list = [0] * N

dq = deque()
dq.append((0,-1,0))

while dq:
    v, pv, res = dq.popleft()
    res += cnt[v]
    ans_list[v] = res
    for nv in ad[v]:
        if nv == pv:
            continue
        dq.append((nv, v, res))

print(*ans_list)

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

using namespace std;
#define tam 100001
#define infinito 10001
int dp[tam],A[tam],n,k;
int solver(int index)
{
    if(dp[index] != -1)
        return dp[index];
    dp[index] = infinito;
    for(int j = 1 ; j <= k && index - j >= 0; j++)
    {
        if(dp[index-j] + abs(A[index]-A[index-j]) <  dp[index])
            dp[index] = solver(index-j) + abs(A[index]-A[index-j]);
    }
    return dp[index];
}
int main()
{
    cin>>n>>k;
    for(int i = 0;i < n;i++)
        cin>>A[i];
    memset(dp,-1,sizeof dp);
    dp[0]=0;
    cout<<solver(n-1)<<"\n";
    return 0;
}


Measured memory_bytes: 10572
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

// https://atcoder.jp/contests/abc070/tasks/abc070_b
// 200点

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

    string abt = "abcdefghijklmnopqrstuvwxyz";
    for (int i = 0; i < abt.size(); i++)
    {
        if (find(s.begin(), s.end(), abt[i]) == s.end())
        {
            cout << abt[i] << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

Measured memory_bytes: 512
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
char s[105];
int l;
bool f;
int main()
{
	scanf("%s",s);
//	l=strlen(s);
	for(int i=0;i<=101;i++)
	  for(int j=i+1;j<=101;j++)
	   if(s[i]=='C'&&s[j]=='F')
	   {
	   	f=1;	   	
	   //	break;
	   }
	if(!f)printf("No\n");
	else printf("Yes\n");
//	printf("%d",f);
	return 0;
}

Measured memory_bytes: 256
k,s=map(int,input().split())
a=0
b=0
c=0
l=0
while l*2<=s and l<=k:
    if s-l*2<=k:
        b+=1
    l+=1
if s%3==0:
    a+=1
    b-=1
for x in range(k+1):
    for y in range(x+1,k+1):
        if k>=s-x-y>y:
            c+=1
print(a+3*b+6*c)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
bool check[31];
int main(int argc, const char * argv[]) {
    
    
    int n;
    string h;
    
    scanf("%d",&n);
    cin >> h;
    int ans = 0;
    for(int i=0;i<n;i++){
        
        //왼쪽끝 i 번째까지
        int tmp = 0;
        for(int j=0;j<=i;j++){
            check[h[j]-'a']=true;
        }
        for(int j=i+1;j<n;j++){
            if(check[h[j]-'a']){
                check[h[j]-'a'] = false;
                tmp++;
            }
        }
        
        
        if(ans < tmp ) ans = tmp;
        for(int i=0;i<31;i++){
            check[i]=false;
        }
        
        
        
    }
    
    printf("%d\n",ans);
    return 0;
}


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

//BIAR MANTAB LAH YA
#define Willy using
#define Indrayana namespace
#define Komara std

Willy Indrayana Komara;

using ll = long long int;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.length() <= k) cout << s << endl;
    else
    {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	string s;
	cin >> s;
	if((s[0]==s[s.size()-1])==(s.size()%2==0)){
		cout << "First" << endl;
	}
	else{
		cout << "Second" << endl;
	}

	return 0;
}



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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    ll x, a, b; cin >> x >> a >> b;

    if (a >= b) {
        puts("delicious");
    } else if (b-a <= x) {
        puts("safe");
    } else {
        puts("dangerous");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 30010
const int MOD = 1000000007;

bool dp[maxn][4][1000];
void solve() {
    int n;
    cin >> n;

    string s;
    cin >> s;

    dp[0][0][0] = true;
    for(int i = 0; i < s.size(); i++){
        for(int j = 0; j <= 3; j++){
            for(int k = 0; k < 1000; k++){
                if(dp[i][j][k] == false)continue;

                dp[i + 1][j][k] = true;
                if(j <= 2)
                    dp[i + 1][j + 1][k * 10 + (s[i] - '0')] = true;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 1000; i++)
        ans += dp[n][3][i];
    cout << ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 117504
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int i1, i2, count = 0;
		Scanner sc = new Scanner(System.in);
		while(true){
			i1 = sc.nextInt();
			i2 = sc.nextInt();
			count++;
			if(i1 == 0 && i2 == 0)
				break;
			else{
				if(i1 < i2)
					System.out.println(i1 +" "+ i2);
				else
					System.out.println(i2 +" "+ i1);
			}
		}
	}

}

Measured memory_bytes: 27164
import std;

int calc(long x) {
    long s = 100;
    int k = 0;
    while (s < x) {
        s += s / 100;
        k++;
    }
    return k;
}

void main() {
    long x; scan(x);
    writeln(calc(x));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 3636
import numpy as np
all_students = int(input())
n_students_at = [int(x) for x in input().split()]

n_students_at = np.array(n_students_at, dtype=int)
order = np.argsort(n_students_at)
for i, sid in enumerate(order):
    if i < len(order) - 1:
        print(sid + 1, end=" ")
    else:
        print(sid + 1)

Measured memory_bytes: 23428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

const int MAX_V=1010;

int N,V;
vector<vector<double>> cost(MAX_V,vector<double>(MAX_V));
vector<double> d(MAX_V,IINF);
vector<bool> used(MAX_V,false);

void Dijkstra(int s){
    d[s]=0;
    while(true){
        int v=-1;
        rep(i,V) if (!used[i]&&(v==-1||d[i]<d[v])) v=i;
        if (v==-1) break;
        used[v]=true;
        rep(i,V) chmin(d[i],d[v]+cost[v][i]);
    }
}

int main(){
    ll xs,ys,xg,yg;
    cin >> xs >> ys >> xg >> yg;
    cin >> N;
    V=N+2;
    vector<ll> x(V),y(V),r(V);
    x[0]=xs,x[V-1]=xg,y[0]=ys,y[V-1]=yg,r[0]=r[V-1]=0;
    rep(i,N) cin >> x[i+1] >> y[i+1] >> r[i+1];
    rep(i,V) rep(j,V) cost[i][j]=max(0.0,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-(double)(r[i]+r[j]));
    Dijkstra(0);
    cout << fixed << setprecision(10);
    cout << d[V-1] << endl;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define print(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 998244353;

string to_string(char &c) {string x(1, c); return x;}
string to_string(const char s[]) {return (string)s;}
string to_string(string &s) {return s;}
string to_string(vb &v) {string res; for (const bool &x : v) res += to_string(x) + ' '; return res;}
template <class C> string to_string(C &v) {string res; for (auto &x : v) res += to_string(x) + ' '; return res;}
template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    vi p(n), q(n);
    cin >> p >> q;

    vi perm(n); REP(i, 0, n) perm[i] = i+1;
    int i=0, a, b;
    do {
        if (p == perm) a = i;
        if (q == perm) b = i;
        ++i;
    } while (next_permutation(perm.begin(), perm.end()));
    print(abs(a-b));
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  vector<long long> T(N), A(N);
  for(int i = 0; i < N; ++i) {
    cin >> T[i] >> A[i];
  }
  vector<pair<long long, long long>> v(N+1);
  v[0].first = 1;
  v[0].second = 1;
  for(int i = 1; i <= N; ++i) {
    long long f = v[i-1].first;
    long long s = v[i-1].second;
    long long n = max((f+T[i-1]-1)/T[i-1], (s+A[i-1]-1)/A[i-1]);
    n = max(n, 1LL);
    v[i].first = n * T[i-1];
    v[i].second = n * A[i-1];
  }

  cout << v[N].first + v[N].second << endl;

  return 0;
}


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

using namespace std;

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

    vector<int> p(N, 0);
    int count = 0;
    for(int i = 0; i < N; i++) {
        cin >> p[i];
        if(p[i] != i+1) count++;
    }

    if(count == 2 || count == 0) cout << "YES" << endl;
    else cout << "NO" << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){

  char s[51], t[51];
  scanf("%s %s",s,t);

  int sl,tl;
  sl = strlen(s);
  tl = strlen(t);

  int v,c;
  v = 0;
  for(int i = sl - tl; i >= 0 ; --i){
    c = 0;
    for(int j = 0; j < tl; ++j){
      if( (s[i+j] != t[j]) && (s[i+j] != '?') )
        c++;
    }

    if(c == 0){
      v = 1;
      for(int j = 0; j < tl; ++j){
        if(s[i+j] == '?'){
          s[i+j] = t[j];
        }
      }
      break;
    }
  }

  if( v == 0 ){
    printf("UNRESTORABLE\n");
    return 0;
  }

  for(int i = 0; i < sl; ++i){
    if(s[i] == '?') s[i] = 'a';
  }
  printf("%s\n",s);
  return 0;
}


Measured memory_bytes: 128
n = int(input())
a = [input() for i in range(n)]
m = int(input())
b = [input() for i in range(m)]
s = a + b
t = []
for i in s:
  t.append(a.count(i) - b.count(i))
  
print(0 if max(t) <= 0 else max(t))


Measured memory_bytes: 9124
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![0i64; n + 1];
    for i in 0..n {
        av[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    av[n] = read(&mut stdin_lock, &mut buf, b'\n');
    let mut bv = vec![0i64; n];
    for i in 0..n - 1 {
        bv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    bv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    let mut cv = vec![0i64; n + 1];
    for i in 0..n {
        let j = n - i - 1;
        let p = if bv[j] >= av[j + 1] - cv[j + 1] {
            av[j + 1] - cv[j + 1]
        } else {
            bv[j]
        };
        let c = if bv[j] - p >= av[j] { av[j] } else { bv[j] - p };
        cv[j + 1] += p;
        cv[j] += c;
    }

    let ans: i64 = cv.into_iter().sum();
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define ll long long
main() {
    while(1) {
        int t, d, l;
        cin >> t >> d >> l;
        if(!t) return 0;
        int pre = 0;
        int ans = 0;
        for(int i = 0; i < t; ++i) {
            int x;
            cin >> x;
            if(x >= l) {
                int nxt = i + d;
                if(pre < i)
                    ans += d;
                else
                    ans += nxt - pre;
                pre = nxt;
            }
        }
        t--;
        if(pre > t) ans -= pre - t;
        cout << ans << endl;
    }
}



Measured memory_bytes: 3000
#include<stdio.h>
int main(void){
	int n,a,f=1;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&a);
		if(a%2==0&&a%3!=0&&a%5!=0){
			f=0;
		}
	}
	printf(f?"APPROVED":"DENIED");
	return 0;
}

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

typedef long long ll;

int n; ll a[200010], b[200010];
ll sb, ans;

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%lld", &a[i]);
		b[i] = a[i] - i;
	}
	nth_element(b + 1, b + (n + 1) / 2, b + n + 1);
	sb = b[(n + 1) / 2];
	for(int i = 1; i <= n; ++i) ans += abs(a[i] - sb - i);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
 
int main() {
  int a;
  int b;
  cin >> a >> b ;
  int suma =0;
  int sumb =0;
  
  for (int i=0;  i<b; i++) {
   
    suma +=a*pow(10,i);
  }
   
  for (int i=0;  i<a; i++) {
   
    sumb +=b*pow(10,i);
  }
  
  
  if (suma >= sumb) {
    cout << suma << endl;
  }
  else {
    cout << sumb << endl;
  }
    
    
          
}      
         

Measured memory_bytes: 512
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in a:
  d[i] += 1

a.sort()
mx = max(a)

chk = [False for i in range(mx+1)]
cnt = 0
for i in range(n):
  if d[a[i]] >= 2:
    for j in range(a[i],mx+1,a[i]):
      chk[j] = True
    continue
  if chk[a[i]] == False:
    cnt += 1
  for j in range(a[i],mx+1,a[i]):
    chk[j] = True
print (cnt)





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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main(){

	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	if (k <= a) {
		cout << k << endl;
	}
	else if (k <= a + b) {
		cout << a << endl;
	}
	else {
		ll ans = a;
		k -= a + b;
		cout << ans - k << endl;
	}

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int m1,m2,d1,d2;
  cin>>m1>>d1>>m2>>d2;
  if(d2==1) cout<<1<<endl;
  else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int X;
    cin >> X;
    ll d = lcm(360, X) / X;
    cout << d << endl;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <math.h>
int main(void){
    int N, T, A;
    scanf("%d", &N);
    scanf("%d %d", &T, &A);
    int H[N];
    double min = 10000;
    int min_n = 0;
    for (int i = 0; i < N; i++){
        scanf("%d", &H[i]);
        if (min > fabs(A - (T - H[i] * 0.006))) {
            min = fabs(A - (T - H[i] * 0.006));
            min_n = i+1;
        }
    }
    printf("%d\n", min_n);
    return 0; 
}

Measured memory_bytes: 128
s = int(input())
n = s
a = [0]*1000001
a[n] = 1
i = 1
while True:
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    if a[n] == 1:
        ans = i + 1
        break
    a[n] = 1
    i += 1

print(ans)


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

fn main() {
    let s = read1::<String>().chars().collect::<Vec<char>>();
    let mut p = s.len();
    while p >= 5 {
        let mut flg = false;
        if p >= 7 {
            for (i, &c) in vec!['r', 'e', 'm', 'a', 'e', 'r', 'd'].iter().enumerate() {
                if s[p-i-1] != c { break; }
                if i == 6 {
                    flg = true;
                }
            }
            if flg {
                p -= 7;
                continue;
            }
        }
        if p >= 6 {
            for (i, &c) in vec!['r', 'e', 's', 'a', 'r', 'e'].iter().enumerate() {
                if s[p-i-1] != c { break; }
                if i == 5 {
                    flg = true;
                }
            }
            if flg {
                p -= 6;
                continue;
            }
        }
        
        for (i, &c) in vec!['m', 'a', 'e', 'r', 'd'].iter().enumerate() {
            if s[p-i-1] != c { break; }
            if i == 4 {
                flg = true;
            }
        }
        if flg {
            p -= 5;
            continue;
        }
        for (i, &c) in vec!['e', 's', 'a', 'r', 'e'].iter().enumerate() {
            if s[p-i-1] != c { break; }
            if i == 4 {
                flg = true;
            }
        }
        if flg {
            p -= 5;
        } else {
            break;
        }
    }
    if p == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
const int M=(1e5);
int n,a[maxn],b[maxn];
int sz[maxn],fa[maxn];
int in[maxn];
ll ans;
int find(int x) {
	if (fa[x]==x) return x;
	return fa[x]=find(fa[x]);
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x,y;
	for (int i=1;i<=n;i++)
		read(a[i]),read(b[i]);
	for (int i=1;i<maxn;i++) fa[i]=i;
	for (int i=M+1;i<maxn;i++) sz[i]=1;
	for (int i=1;i<=n;i++) {
		x=a[i]; y=b[i]+M;
		x=find(x); y=find(y);
		in[x]++; in[y]++;
		if (x==y) continue;
		//printf("%d %d\n",x,y);
		fa[x]=y;
		sz[y]+=sz[x];
	}
	for (int i=1;i<=M;i++)
		ans+=sz[find(i)]-in[i];
	for (int i=1;i<maxn;i++) fa[i]=i,sz[i]=0;
	for (int i=1;i<=M;i++) sz[i]=1;
	memset(in,0,sizeof(in));
	for (int i=1;i<=n;i++) {
		x=a[i]; y=b[i]+M;
		x=find(x); y=find(y);
		in[x]++; in[y]++;
		if (x==y) continue;
		//printf("%d %d\n",x,y);
		fa[x]=y;
		sz[y]+=sz[x];
	}
	for (int i=M+1;i<maxn;i++) {
		//if (in[i]) printf("%d %d\n",sz[find(i)],in[i]);
		ans+=sz[find(i)]-in[i];
	}
	printf("%lld\n",ans/2);
	return 0;
}

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

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(1) {
        C -= B;
        if(C <= 0) {
            cout << "Yes" << endl;
            break;
        }
        A -= D;
        if(A <= 0) {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

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

using namespace std;
#define N 100100
#define SIGMA 26

const string answer[2] = {"NO\n", "YES\n"};

int v[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int x;
int main()
{
    cin >> x;
    cout << v[x - 1];
    return 0;
}


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

int main() {
  int A,N;
  cin >> N;
  
//  vector<int> A(N);
 
  bool flag = true;

  for (int i=0; i<N; i++){
    cin >> A;
    if(A % 2 == 0){
      if((A % 3 == 0) || (A % 5 == 0)){
        flag = true;
      }
      else
      {
        flag = false;
        break;
      }
    }
  }
  if(flag){
    cout << "APPROVED" << endl;
  }
  else
  {
    cout << "DENIED" << endl;
  }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
vector<list<int>> v(100005);
vector<vector<ll>> dp(100005,vector<ll>(2));
vector<int>par(100005);
int n;
ll solve(int i,int pclr)
{
    if(dp[i][pclr])
    return dp[i][pclr];
    ll res=1,ans=0;
    for(auto x:v[i])
    {
        if(par[i]!=x){
        par[x]=i;
        res = (res%mod*solve(x,1)%mod)%mod;
        }
    }
    if(pclr){
        ans = 1;
        for(auto x:v[i])
        {
            if(par[i]!=x){
                par[x]=i;
             ans = (ans%mod*solve(x,0)%mod)%mod;
            }
        }
    }
    return dp[i][pclr]=(res%mod+ans%mod)%mod;
}
int main() {
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    cout<<solve(1,1)%mod;
}


Measured memory_bytes: 25960
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
	return *(long long int *)a-*(long long int *)b;
}
int main(void){
	int n,i,c=0;//,a[100000],s;
	long long int a[100000],s;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	qsort(a,n,sizeof(long long int),cmp);
	s=a[0];
	for(i=1;i<n;i++){
		if(a[i]>2*s){
			c=i;
		}
		s+=a[i];
	}
	printf("%d\n",n-c);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

vvl adj;
vl vals;

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

	ll n,q; cin >> n >> q;
	adj.assign(n, vl());
	vals.assign(n, 0);

	FOR(i,0,n-1) {
		ll a,b; cin >> a >> b;
		a--; b--;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	FOR(i,0,q) {
		ll p,x; cin >> p >> x;
		p--;
		vals[p] += x;
	}

	vb vis(n, false);
	priority_queue<ll> pq;
	pq.push(0);
	vis[0] = true;
	while(! pq.empty()) {
		ll cur = pq.top(); pq.pop();
		for(const auto &it: adj[cur]) {
			if (vis[it]) {
				continue;
			}
			vis[it] = true;
			vals[it] += vals[cur];
			pq.push(it);
		}
	}
	FOR(i,0,n) {
		cout << vals[i] << " ";
	}
	cout << endl;
}


Measured memory_bytes: 18032
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {a: i128, b:i128};
    let mut sum: i128 = 1;

    for i in a..b {
        sum *= i;
    }

    if b < 0 {
        let x = a.abs() - b.abs();
        if x % 2 == 0 {
            println!("Negative")
        } else {
            println!("Positive")
        }
    } else if a < 0 && b > 0 {
        println!("Zero")
    } else {
        let x = a.abs();

        if x % 2 == 0 {
            println!("Negative")
        } else {
            println!("Positive")
        }
    }
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n, k, p[N];
double q[N], sum[N];

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    q[i] = (double)(p[i] + 1) / 2.0;
    sum[i] = sum[i-1] + q[i];
  }

  double ans = 0;
  for (int i = 1; i <= n - k + 1; ++i) {
    ans = max(ans, sum[i + k - 1] - sum[i - 1]);
  }
  cout << fixed << setprecision(10) << ans;
  return 0;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) {
				break;
			}

			TreeSet<Integer> taro, hana, turn;
			taro = new TreeSet<Integer>();
			hana = new TreeSet<Integer>();
			//配る
			for (int i = 0; i < n; i++) {
				taro.add(Integer.parseInt(br.readLine()));
			}
			for (int i = 1; i < 2 * n + 1; i++) {
				hana.add(i);
			}
			hana.removeAll(taro);
			//遊ぶ
			Integer deck = 0;
			turn = taro;
			while (true) {
				if ((deck = turn.ceiling(deck)) != null) {
					turn.remove(deck);
				} else {
					deck = 0;
				}
				if (turn.isEmpty()) break;
				turn = (turn == taro) ? hana : taro;
			}
			System.out.println(hana.size() + "\n" + taro.size());
		}
	}
}

Measured memory_bytes: 18404
///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull insigned lon long
///////////////////////////////////////////////////////////
int absolute(int n);
void input(vector<int>& vec);
void print(vector<int> vec);
void print(vector<double> vec);
double sum(vector<int> vec);
void upsort(vector<int>& vec);
void downsort(vector<int>& vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main()
{
    int n;
    cin>>n;
    vector<int>a(n);
    input(a);
    vector<double>b(n);
    for(int i=0;i<n;++i){
        b.at(i)=1.0/(a.at(i));
    }
    double s=0.0;
    for(int i=0;i<n;++i){
        s+=b.at(i);
    }
    cout << 1/s << endl;
    return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n)
{
    if (n < 0) {
        return (-n);
    }
    return n;
}

void input(vector<int>& vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cin >> vec.at(i);
    }
}

void print(vector<int> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

void print(vector<double> vec)
{
    for (size_t i = 0; i < vec.size(); ++i) {
        cout << vec.at(i) << " ";
    }
    cout << endl;
}

double sum(vector<int> vec)
{
    double s = accumulate(vec.begin(), vec.end(), 0);
    return s;
}

void upsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end());
}

void downsort(vector<int>& vec)
{
    sort(vec.begin(), vec.end(), greater<int>());
}

int maxvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = max(m, vec.at(i));
    }
    return m;
}

int minvec(vector<int> vec)
{
    int m = vec.at(0);
    for (size_t i = 0; i < vec.size(); ++i) {
        m = min(m, vec.at(i));
    }
    return m;
}
///////////////////////////////////////////////////////////

Measured memory_bytes: 384