akhauriyash/Code-Regression huggingface dataset:
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

char buf[2097152];
int bufl;
inline char bufr(void){
	return buf[bufl++];
}

#define getchar bufr

void rsort_d32(void *base, const int count){
	int32_t *a=base;
	int32_t *b=malloc(count*sizeof(int32_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))+0x80]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }

#define P 1000000007

int k[100001];
int rk[100001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int a[100000];
int main(void){
	read(STDIN_FILENO, buf, sizeof(buf));
	int n=nextint();
	int k=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	rsort_d32(a, n);
	comb_init(n);
	long ans=0;
	for(int i=0; i<=n-k; i++){
		int c = comb(n-i-1, k-1);
		ans+=(long)(a[n-i-1]-a[i])*c%P;
	}
	ans=(ans+(long)(n-k)*P)%P;
	printf("%ld\n", ans);
}


Measured memory_bytes: 2424
#include <iostream>
#include <cstring>

using namespace std;
const int maxn = int(100) + 5;

const int d[4][2] = {{0, 1}, {0, -1}, {1, 0 }, {-1, 0}};
//                     {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
char G[maxn][maxn];
int n, m;
int visited[maxn][maxn];

bool check(int x, int y, char c) {
    return x < n and x >= 0 and y < m and y >= 0
            and G[x][y] == c and not visited[x][y];
}

void dfs(int x, int y, char c) {
    for (int i = 0; i < 4; i++) {
        int dx = x + d[i][0];
        int dy = y + d[i][1];
        if (check(dx, dy, c)) {
            visited[dx][dy] = true;
            dfs(dx, dy, c);
        }
    }
}


int main() {
    while (cin >> n >> m and (n or m)) {
        memset(visited, false, sizeof(visited));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> G[i][j];
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (not visited[i][j]) {
                    ans ++;
                    visited[i][j] = true;
                    dfs(i, j, G[i][j]);
                }
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n),dp(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0] = 0;
    for(int i=1;i<n;i++){
        int val = INT_MAX;
        for(int j=1;j<=k;j++){
            if(i-j < 0){
                break;
            }
            val = min(val,dp[i-j] + abs(a[i] - a[i-j]));
        }
        dp[i] = val;
    }
    cout<<dp[n-1];
    return 0;
}

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

using namespace std;

#define ll long long int

int main()
{
	ll a,b,c,d;
	cin >> a;
	ll v1[a],v2[a],v3[a],ve1[a],ve2[a],ve3[a];
	for(ll i=0;i<a;i++)
	{
		cin >> v1[i];
		cin >> v2[i];
		cin >> v3[i];
	}
	ve1[a-1]=v1[a-1];
	ve2[a-1]=v2[a-1];
	ve3[a-1]=v3[a-1];
	for(ll i=a-2;i>=0;i--)
	{
		ve1[i]=max(ve2[i+1],ve3[i+1])+v1[i];
		ve3[i]=max(ve2[i+1],ve1[i+1])+v3[i];
		ve2[i]=max(ve1[i+1],ve3[i+1])+v2[i];
	}
	
	cout << max(ve1[0],max(ve2[0],ve3[0]));
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static int[] uf;
	public static int[] dp;

	public static int Root(int n) {
		int tmp = n;
		while(uf[tmp] != tmp) {
			tmp = uf[tmp];
		}
		return tmp;
	}

	public static void Union(int m, int n) {
		if(Root(m) != Root(n)) {
			int x = Root(m);
			int y = Root(n);
			if(dp[x] < dp[y]) {
				uf[x] = y;
			} else if(dp[x] > dp[y]) {
				uf[y] = x;
			} else {
				uf[x] = y;
				dp[y]++;
			}
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt() - 1;
		}
		uf = new int[n];
		dp = new int[n];
		for(int i = 0; i < n; i++) {
			uf[i] = i;
			dp[i] = 0;
		}
		for(int i = 0; i < m; i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			Union(x, y);
		}
		int ans = 0;
		for(int i = 0; i < n; i++) {
			if(Root(i) == Root(p[i]))
				ans++;
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 93448
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;


int main(){
  int n, m;
  cin >> n >> m;
  long long ans = 0;
  long long drink = 0;
  vector<pair<long long, long long> > a(n);
  for(int i = 0; i < n; ++i){
    cin >> a[i].first >> a[i].second;
  }

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

  for(int i = 0; i < n; ++i){
    ans += a[i].first * a[i].second;
    drink += a[i].second;
    if(drink >= m){
      ans -= (drink - m) * a[i].first;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
n, m = [int(item) for item in input().split()]
query = []
appeared = set()
for i in range(n):
    line = [int(item) for item in input().split()]
    appeared.update(line[1:])
    query.append(line[1:])
    
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1] * n
        self.rank = [0] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

uf = UnionFind(m)
for q in query:
    if len(q) == 1:
        continue
    for item in q[1:]:
        if not uf.same_check(q[0]-1, item-1):
            uf.union(q[0]-1, item-1)
    
par = uf.find(appeared.pop() - 1)
for item in appeared:
    if uf.find(item - 1) != par:
        print("NO")
        exit()
print("YES")

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll K, S;
    cin >> K >> S;
    
    ll cnt = 0;
    REP(x,0,K+1) {
        REP(y,0,K+1) {
            ll z = S - x - y;
            cnt += (0 <= z && z <= K);
        }
    }
    PR(cnt);

    return 0;
}






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

int main() {
  int n, x, a = 1000;
  cin >> n >> x;
  int m;
  for (int i = 0;i < n;i++) {
    cin >> m;
  	x -= m;
    a = min(a, m);
  }
  
  cout << n + x/a << endl;
  return 0;
}

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

using namespace std;
typedef long long int ll;
int main()
{
   int n,d;
   cin>>n>>d;
   double x[n];
   double y[n];
   for(int i=0;i<n;i++)
   {
       cin>>x[i]>>y[i];
   }
   int sum=0;
   for(int i=0;i<n;i++)
   {
       double a=(x[i]*x[i])+(y[i]*y[i]);
       a=sqrt(a);

       if(a<=d) sum++;
   }
   cout<<sum<<endl;

   return 0;
}


Measured memory_bytes: 6744
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] H = new int[N];
        for (int i=0; i<N; i++) {
            H[i] = sc.nextInt();
        }

        System.out.println(solve(N, K, H));
    }

    private static long solve(int N, int K, int[] H) {
        long count = 0;

        Arrays.sort(H);

        for (int i=0; i<N-K; i++) {
            count += H[i];
        }

        return count;
    }
}

Measured memory_bytes: 87860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define pf push_front
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
int main(){
    string s; cin>>s;
    ll n=s.length();
    ll c=0;
    for(ll i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1])
            c++;
    }
    cout<<c;
    return 0;
}


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

int main(){
  int N,K,count=0;
  cin>>N>>K;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin>>h.at(i);
    if(K<=h.at(i)){
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define N 100001
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
vector<P> G[N];

int cnt[2*N];


void Plus(int pos,int pre,int goal){
  if(pos == goal) return ;

  for(P nx:G[pos])
    if(nx.first!=pre) {
      cnt[nx.second]++;
      Plus(nx.first,pos,goal);
    }
}

int main(){
  int n,m;
  cin>>n>>m;

  while(m--){
    int a,b;
    cin>>a>>b;a--,b--;
    if(a) cnt[a-1]++;
    if(b) cnt[b-1]++;
    // Plus(a,-1,b);
  }

  int ans = 1;
  for(int i=0;i<2*N;i++) if(cnt[i]%2) ans = 0;
  cout<<(ans? "YES":"NO")<<endl;
  
  return 0;
}


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

using namespace std;

int main()
{
  string a;
  int b;
  int c;
  string out;

  while(1)
  {
    cin >> a;
    if(a == "-")break;
    cin >> b;
    for(int i = 0; i < b; i ++)
    {
      cin >> c;
      out = a.substr(0,c);
      a.erase(0,c);
      a += out;
    }
    cout << a << endl;
  }
  return 0;
}



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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define dbg(x)                       cout << #x << " is " << x << endl;
#define endl                           '\n'

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll i,j,n,m,k,cnt=0,ans=0,t=1;
    cin>>n>>k;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    sort(a,a+n);
    ans=LLONG_MAX;
    rep(i,0,n)
    {
    	if(i+k-1>=n) break;
    	ans=min(ans,a[i+k-1]-a[i]);
    }
    ret(ans)

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	static ArrayList<Route>[] lists;
	static long[] costs; // Kへのコスト
	
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		lists = new ArrayList[n + 1];
		for (int i = 1; i <= n; i++) {
			lists[i] = new ArrayList<Route>();
		}
		for (int i = 1; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			lists[a].add(new Route(b, c));
			lists[b].add(new Route(a, c));
		}
		costs = new long[n + 1];
		Arrays.fill(costs, -1);
		int q = sc.nextInt();
		int k = sc.nextInt();
		setCost(0, k);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			sb.append(costs[x] + costs[y]).append("\n");
		}
		System.out.print(sb);
	}
	
	static void setCost(long total, int idx) {
		if (costs[idx] == -1) {
			costs[idx] = total;
			for (Route r : lists[idx]) {
				setCost(total + r.cost, r.point);
			}
		}
	}
	
	static class Route {
		public int point;
		public long cost;
		
		public Route(int point, long cost) {
			this.point = point;
			this.cost = cost;
		}
	}
	
}


Measured memory_bytes: 190432
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//ios_base& scientific (ios_base& str);
    ll n, k, d, temp;
    map<ll, ll> mp;
    cin >> n >> k;
    while (k--)
    {
        cin >> d;
        while (d--)
        {
            cin >> temp;
            mp[temp] = 1;
        }
    }
    cout << n - mp.size() << "\n";
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> X(N), Y(N);
    REP(i,N){
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
    }
    vector<pair<int,int>> P(N);
    REP(i,N){
        P[i] = {X[i], Y[i]};
    }
    sort(ALL(P));


    dsu d(N);//xでやる

    stack<int> S;
    S.push(P[0].second);

    FOR(i,1,N){
        int y = S.top();
        if(y < P[i].second){
            d.merge(y,P[i].second);
        
            S.pop();
            while(!S.empty() && S.top() < P[i].second){
                d.merge(S.top(),P[i].second);
                S.pop();
            }
            S.push(y);
        }else{
            S.push(P[i].second);
        }
    }

    REP(i,N){
        cout << d.size(Y[i]) << endl;
    }

    return 0;
}

Measured memory_bytes: 7224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll D;
    cin >> D;
    if (D == 25)
    {
        puts("Christmas");
    }
    else if (D == 24)
    {
        puts("Christmas Eve");
    }
    else if (D == 23)
    {
        puts("Christmas Eve Eve");
    }
    else if (D == 22)
    {
        puts("Christmas Eve Eve Eve");
    }
    return 0;
}

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

def calc_score(h):
    return abs(A - (T - h*0.006))

ans_id = 0
ans_score = calc_score(H[0])

for i in range(1, N):
    score = calc_score(H[i])
    if ans_score > score:
        ans_id = i
        ans_score = score

print(ans_id + 1)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1)*(m - 1) << endl;
	return 0;
}

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

using namespace std;
using ll=long long ;

void solve() {
    ll a,b;
    cin >> a >> b;
    if (a>b) swap(a,b);
    ll res;
    if (a==b) {
        res = (a-1)*2;
    } else if (a+1==b) {
        res = (a-1)*2;
    } else {
        ll c = floor(sqrt(a*b));
        if (c*c==a*b)c--;
        if (c*(c+1) >= a*b) res=2*c-2;
        else res = 2*c-1;
    }
    cout << res << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    while(t--) solve();
    cout << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	string s;
	cin>>s;
	n=s.size();
	if(s[n-1]=='1' || s[0]=='0'){
		cout<<-1<<endl;
		return 0;
	}
	for(int i=0; i<n-1; i++){
		if(s[i]!=s[n-2-i]){
			cout<<-1<<endl;
			return 0;
		}
	}
	vector<int> v;
	for(int i=0; i<=(n-2)/2; i++){
		if(s[i]=='1') v.push_back(i);
	}
	vector<P> ans;
	int p=2;
	ans.push_back(P(1, 2));
	for(int i=1; i<v.size(); i++){
		for(int c=p+1; c<=p+v[i]-v[i-1]-1; c++){
			ans.push_back(P(p, c));
		}
		ans.push_back(P(p, p+v[i]-v[i-1]));
		p=p+v[i]-v[i-1];
	}
	for(int i=p+1; i<=n; i++){
		ans.push_back(P(p, i));
	}
	for(int i=0; i<n-1; i++){
		cout<<ans[i].first<<" "<<ans[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 2740
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    cin>>s;
    rep(i,s.size()){
        if((i+1)%2!=0) cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using static System.Console;
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{   
    class Template
    {
        static void Main(string[] args)
        {
            string sa, sb, sc;
            sa = IO.ReadStr();
            sb = IO.ReadStr();
            sc = IO.ReadStr();

            char turn = 'a';
            char pop;
            while (true)
            {
                switch (turn)
                {
                    case 'a':
                        if (sa.Length == 0)
                        {
                            WriteLine("A");
                            return;
                        }
                        turn = sa[0];
                        sa = sa.Remove(0, 1);
                        break;
                    case 'b':
                        if (sb.Length == 0)
                        {
                            WriteLine("B");
                            return;
                        }
                        turn = sb[0];
                        sb = sb.Remove(0, 1);
                        break;
                    case 'c':
                        if (sc.Length == 0)
                        {
                            WriteLine("C");
                            return;
                        }
                        turn = sc[0];
                        sc = sc.Remove(0, 1);
                        break;
                    default:
                        break;
                }
            }

        }
    }

    public class IO
    {
        public static string ReadStr() => Console.ReadLine();
        public static string[] ReadStrArr() => ReadStr().Split(' ');
        public static int ReadInt() => int.Parse(ReadStr());
        public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        public static double ReadDouble() => double.Parse(ReadStr());
        public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
        public static long ReadLong() => long.Parse(ReadStr());
        public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
    }
}


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

int main(){
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(),a.end());
  sort(f.rbegin(),f.rend());
  ll l = -1, r = 1e12;
  while(l+1<r){
    ll mid = (l+r)/2;
    ll s = 0;
    bool ok = [&]{
    rep(i,n){
      s += max(0ll,a[i]-mid/f[i]);
    }
      return s<=k;
    }();
    if(ok) r = mid; else l = mid;
  }
  
  cout << r << endl;
}


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

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

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

const long long INF=1LL<<60;
const int MAX_V=100010;

int main(){
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
    }
    vector<vector<long long>> dp(N+1, vector<long long>(MAX_V, INF));
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=MAX_V;j++){
            if(j >= v[i]) chmin(dp[i+1][j], dp[i][j-v[i]]+w[i]);
            chmin(dp[i+1][j], dp[i][j]);
        }
    }
    int res=0;
    for(int i=0; i<MAX_V; i++){
        if(dp[N][i] <= W) res=i;
    }
    cout << res << endl;
}

Measured memory_bytes: 80256
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int h = sc.nextInt();
        int a = sc.nextInt();

        if (h==a)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


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

int main(){
  int n;
  cin >> n;
  auto v = vector<int>(n,0);
  for (int i = 0; i < n; i++)
  {
      cin >> v[i];
  }

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

  auto ans = static_cast<double>((v[0]+v[1]))/2.0;
  for (int i = 2; i < n; i++)
  {
      ans = (ans + v[i])/2.0; 
  }
  
  cout << ans;
}

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

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


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

#define ll long long

int main()
{
    int n,m;
    cin>>n>>m;
    ll sum=0;
    int a;
    while(m--)
    {
        cin>>a;
        sum+=a;
    }
    if(sum>n)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;
}


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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    rep(i, N){
        if(A[i] % 2 == 1) {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 640
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())

c = [[0 for i in range(10)] for _ in range(10)]
def f(n):
    x = 0
    while n > 0:
        n //= 10
        x +=1
    return x

for i in range(1, N + 1):
    d = f(i)
    front = i // (10 ** (d - 1)) 
    back = i % 10
    c[front][back] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += c[i][j] * c[j][i]
print(ans)


Measured memory_bytes: 40936
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	ll w = 0;
	ll n = s.size();
	ll ans = 0;
	for(ll i = n - 1; i >= 0; i--) {
		if(s[i] == 'W') w++;
		else {
			ans += w;
		}
	}
	cout << ans << endl;
	return 0;
}

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


Measured memory_bytes: 1356
S = list(raw_input())[::-1]

T = [list('dream')[::-1],list('dreamer')[::-1],list('erase')[::-1],list('eraser')[::-1]]

while True:
    flag = True
    if len(S) >= 5 and T[0] == S[0:5]:
        del S[0:5]
        flag = False
    if len(S) >= 7 and T[1] == S[0:7]:
        del S[0:7]
        flag = False
    if len(S) >= 5 and T[2] == S[0:5]:
        del S[0:5]
        flag = False
    if len(S) >= 6 and T[3] == S[0:6]:
        del S[0:6]
        flag = False
    if flag:
        break

if len(S) == 0:
    print 'YES'
else:
    print 'NO'

Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	string S;
	S = a + b;
	int s = stoi(S);
	for (int i = 1; i <= 1000; ++i) {
		if (s == i * i) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


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

using namespace std;

const int maxn = 100010;

int n,m,p[maxn],dd[maxn],is[maxn];
vector<int> g[maxn],st;

void vis(int u) {
    dd[u] = 1;
    st.push_back(u);
    for (int j=0;j<g[u].size();j++) {
        int v=g[u][j];
        if (!dd[v]) vis(v);
    }
}

int calc() {
    int tmp =0;
    memset(is,0,sizeof(is));
    for (int i=0;i<st.size();i++) is[p[st[i]]] = 1;
    for (int i=0;i<st.size();i++) tmp += is[st[i]];
    return tmp;
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>p[i];
    for (int i=1;i<=m;i++) {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int res=0;
    for (int i=1;i<=n;i++)
        if (!dd[i]) {
            st.clear();
            vis(i);
            res+=calc();
        }
    cout<<res<<endl;
}



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

using namespace std;

int main(){
	int t,n;
	int max,min;
	cin>>t;
	vector< vector<int> > a;
	vector<int> b(t);
	a.resize(t);
	
	for(int i=0;i<t;i++){
		cin>>n;
		a[i].resize(n);
		for(int j=0;j<n;j++)
			cin>>a[i][j];
		b[i]=n;
	}
	
	
	
	for(int i=0;i<t;i++){
		 max=0;min=0;
		for(int j=1;j<b[i];j++){
		if(a[i][j]>a[i][j-1]){
		if(max<a[i][j]-a[i][j-1])
			max=a[i][j]-a[i][j-1];
		}
		else{
		if(min<a[i][j-1]-a[i][j])
			min=a[i][j-1]-a[i][j];
	}
		
		}
		cout<<max<<" "<<min<<endl;
	}
	
	}

Measured memory_bytes: 1224
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}

	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	list := make([]int, n)
	var max, min, tmp int
	max = -1
	min = 999
	for i := 0; i < n; i++ {
		tmp = nextInt()
		list[i] = tmp

		if max < tmp {
			max = tmp
		}
		if min > tmp {
			min = tmp
		}
	}

	var ans, sum int
	ans = max * max * max
	for loc := min; loc <= max; loc++ {
		sum = 0
		for i := 0; i < n; i++ {
			sum += (list[i] - loc) * (list[i] - loc)
		}
		if ans > sum {
			ans = sum
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    String str;
    char[] ch;
    int i, n, m;

    for(;;){
      str = sc.nextLine();
      m = str.length();
      ch = new char[m];
      n = 0;
      for(i = 0;i < m;i++){
        ch[i] = str.charAt(i);
        n += (int)(ch[i] - '0');
      }

      if(n == 0)break;
      System.out.println(n);
    }


    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///


void _case()
{
    ll n,i,ans=0,k,c=0;
    string a;
    cin>>n>>k>>a;
    for(i=1;i<n;i++){
        ans+=(a[i]==a[i-1]);
    }
    ans+=k*2;
    ans=min(ans,n-1);
    cout<<ans el;
}

main()
{
    fastio();
    _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3772
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

ll fastPow(ll base, ll expo, ll mod)
{
    ll ans = 1;
    while (expo > 0)
    {
        if (expo & 1)
            ans = ans * base % mod;
        base = base * base % mod;
        expo >>= 1;
    }
    return ans % mod;
}
ll inv(ll x, ll mod)
{
    return fastPow(x, mod - 2, mod);
}
ll C(ll n, ll m, ll mod)
{
    if (n < m)
        return 0;
    ll up = 1, down = 1;
    for (int i = n - m + 1; i <= n; ++i)
        up = up * i % mod;
    for (int i = 1; i <= m; ++i)
        down = down * i % mod;
    return up * inv(down, mod) % mod;
}
ll Lucas(ll n, ll m, ll mod)
{
    if (m == 0)
        return 1;
    else
        return Lucas(n / mod, m / mod, mod) * C(n % mod, m % mod, mod) % mod;
}
int main(void)
{
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    printf("%lld\n", ((fastPow(2, n, mod) - 1ll - Lucas(n, a, mod) + mod) % mod - Lucas(n, b, mod) + mod) % mod);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int A, B, C;
int X;
int solve(){
int ans = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) ans++;
}
}
}
return ans;
}
int main(){
scanf("%d%d%d%d", &A, &B, &C, &X);
int ans = solve();
printf("%d\n", ans);
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
//#include <functional>
#include <cstdio>
#include <queue>
#include <fstream>
using namespace std;

#define START 'S'
#define CANTGO 'X'
#define NONE '.'
#define FINUM field[i][j] - '0'

struct Point
{
	int x;
	int y;
};

int dx[] = {0,-1,0,1};//ã©çvñè
int dy[] = {1,0,-1,0};
string field[1000];
int mfield[1001][1001] = {};
int life=1;
int csum = 0;
int H,W,N;


int open(Point gool)
{
	int counter=0;
	queue<Point> tp;
	tp.push(gool);
	int i,j;
	Point inp;
	Point p;
	while(1)
	{
		counter++;
		int size = tp.size();
		for(i=0;i<size;i++)
		{
			p = tp.front();
			tp.pop();
			for(j=0;j<4;j++)
			{
				inp.x = p.x+dx[j];
				inp.y = p.y+dy[j];
				if(inp.x<0 || inp.y<0 || inp.y>=H || inp.x>=W)
					continue;
				if(field[inp.y][inp.x] != CANTGO && mfield[inp.y][inp.x] != life)
				{
					//v·éÉÅZ£Ú®Â\][
					if(field[inp.y][inp.x] == life + '0' ) //©ªÉ©Á½`[YÌ­©
					{
						return counter;
					}
					else
					{
						tp.push(inp);
						mfield[inp.y][inp.x] = life;
					}
				}
			}
		}
		/*for(i=0;i<H;i++)
		{
			for(j=0;j<W;j++)
			{
				cout << mfield[i][j];
			}
			cout << endl;
		}*/
	}
	//copy(tp.begin() , tp.end() , tp.begin());
	return 0;
}

int main(void)
{
	int i,j;
	queue<Point> tp;
	Point top[10];
	Point inp;
	int count = 0;
	int counter=0;
	cin >> H >> W >> N;

	for(i=0;i<H;i++)//üÍ
	{
		cin >> field[i];
		for(j=0;j<W;j++)
		{
			if(field[i][j] == 'S')
			{
				top[0].y = i;
				top[0].x = j;
				mfield[i][j] = life;
			}
			if(field[i][j] >= '0' && field[i][j] <= '9')
			{
				top[field[i][j] - '0'].y = i;
				top[field[i][j] - '0'].x = j;
			}
		}
	}//üÍIíè

	while(1)
	{
		if((counter = open(top[life-1])) != 0)
		{
			life++;
			csum += counter;
		}
		if(life > N)
			break;
	}
		cout << csum << endl;

	return 0;
}

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

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;

void solve()
{   
    int a, b;
    cin >> a >> b;

    int i = 0;

    for (int i = 0; i <= 1500; i++)
    {
        int x = (i * 8) / 100;
        int y = (i * 10) / 100;

        if (x == a && y == b)
        {
            cout << i << '\n';
            return;
        }
    }

    cout << -1 << '\n';
} 

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

    // int t; cin >> t; while (t--)
    solve();

    return 0;
}

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

using namespace std;
using ll = long long;
const long long INF = 1LL << 60;


int main(){
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;
    rep(i, n){
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <math.h>

#define POW(x) ((x) * (x))

int main(){
  double x1, y1, x2, y2;
  scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
  printf("%.8f\n", sqrt(POW(x2 - x1) + POW(y2 - y1)));
  return 0;
}



Measured memory_bytes: 2096
#include <stdio.h>
int main(){
    int a,b=0,c,n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        b=b+a;
    }
    b=b-n;
    printf("%d\n",b);
    return 0;
}


Measured memory_bytes: 128
/* به نام یزدان */
#include <bits/stdc++.h>
using namespace std;

const int MAX_N = 300 + 5;
long double dp[MAX_N][MAX_N][MAX_N];
int n, a[MAX_N];

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

void solve() {
	for (int k = 0; k <= n; k++)
		for (int j = 0; j <= n; j++)
			for (int i = 0; i <= n; i++) {
				if (i)
					dp[i][j][k] = 1. * i / n * (dp[i - 1][j][k] + 1);
				if (j)
					dp[i][j][k] += 1. * j / n * (dp[i + 1][j - 1][k] + 1);
				if (k)
					dp[i][j][k] += 1. * k / n * (dp[i][j + 1][k - 1] + 1);
				long double p = 1. * (n - i - j - k) / n;
				if (i | j | k) {
					dp[i][j][k] += p;
					dp[i][j][k] /= 1 - p;
				}
			}
}

void print_output() {
	int cnt[3] = {};
	for (int i = 0; i < n; i++)
		cnt[a[i] - 1]++;
	cout << fixed << setprecision(13);
	cout << dp[cnt[0]][cnt[1]][cnt[2]];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	solve();
	print_output();
}


Measured memory_bytes: 438528
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){

	int a[100000];
	int b[100000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;


	scanf("%d", &n);


	for (int i = 1; i < 45000; i++){
		x = (i*(i + 1)) / 2;
		if (x >= n){
			m = i;
			break;
		}
	}

	printf("%d\n", m);

	return 0;
}

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

signed main(void)
{
	int n;
	cin >> n;
	set<int> d;
	for (int i = 0; i < n; i++) {int a; cin >> a; d.insert(a);}
	cout << d.size() << endl;
	return 0; 
}


Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())
d = [list() for _ in range(N+1)]
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

queue=deque([1])
vs = set([1])
vs_bfs = list()
parents = [0] * (N+1)
while queue:
    v = queue.popleft()
    vs_bfs.append(v)
    for u in d[v]:
        if u in vs:
            continue
        parents[u] = v
        vs.add(u)
        queue.append(u)

dp = [0 for _ in range(N+1)]
dpl = [1 for _ in range(N+1)]
dpr = [1 for _ in range(N+1)]
for v in vs_bfs[::-1]:
    t = 1
    for u in d[v]:
        if u == parents[v]:
            continue
        dpl[u] = t
        t = (t * (dp[u]+1)) % M
    t = 1
    for u in d[v][::-1]:
        if u == parents[v]:
            continue
        dpr[u] = t
        t = (t * (dp[u]+1)) % M
    dp[v] = t

dp2 = [0]*(N+1)
for v in vs_bfs:
    if v == 1:
        dp2[v] = 1
        continue
    p = parents[v]
    dp2[v] = (dp2[p] * (dpl[v]*dpr[v]) +1)% M
#    print(dp2[p] * (dpl[v]*dpr[v]))
#    dp2[v] = dp2[p] %M
r = [0]*N
for i in range(1, N+1):
    r[i-1] = str(dp[i] * dp2[i] % M)
print("\n".join(r))


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

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll MIN(ll a,int b){ll ans;(a>=b)?ans=b:ans=a;return ans;}
ll MAX(ll a,int b){ll ans;(a>=b)?ans=a:ans=b;return ans;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}

int main()
{
    FIO;
    ll n,t,x,y,m,k;
    cin>>x>>y>>n>>m;
    cout<<max(x*m,max(x*n,max(y*m,y*n)));
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);

    using Pi = pair< T, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
        auto next_cost = cost + e.cost;
        if(dist[e.to] <= next_cost) continue;
        dist[e.to] = next_cost;
        que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

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

    WeightedGraph<int> g(10);
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            int cost;
            cin >> cost;
            g[j].emplace_back(i, cost);
        }
    }
    auto distance = dijkstra(g, 1);

    int ans = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            int A;
            cin >> A;
            if(A != -1) {
                ans += distance[A];
            }
        }
    }

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define ll long long

const int maxn = 200000 + 5;
int a[maxn];
int b[maxn];

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

	int a, b;
	cin >> a >> b;
	int k = a + b;
	k /= 2;

	if (abs(a) == abs(b)) {
		cout << 0 << endl;
	}
	else if (abs(a - k) == abs(b - k)){
		cout << k << endl;
	}
	else cout << "IMPOSSIBLE" << endl;

	//system("pause");
	return 0;
}


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

h,n=map(int,input().split())
A=[]
AB=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    AB.append((a,b))
    
maA=max(A)
dp=[float("inf")]*(h+maA+1)
dp[0]=0

for i in range(h+1):
    for a,b in AB:
        dp[i+a]=min(dp[i+a],dp[i]+b)
print(min(dp[h:]))

Measured memory_bytes: 41948
o = str(input())
e = str(input())
lst = []

if len(o)==len(e):
    for i in range(len(o)):
        lst.append(o[i])
        lst.append(e[i])
    print(''.join(lst))
else:
    for i in range(len(e)):
        lst.append(o[i])
        lst.append(e[i])
    lst.append(o[-1])
    print(''.join(lst))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    int n,m;
    cin >> n >> m;
    
    vector<int> x(m);
    rep(i,m) cin >> x[i];
    if(n>=m){
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(),x.end());
    vector<int> d(m-1);
    rep(i,m-1) d[i] = x[i+1]-x[i];
    sort(d.begin(),d.end());
    ll ans = 0;
    rep(i,m-n) ans += d[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024