akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		for(int i=1; i<=n; i++){
			if(i%10==0){
				continue;
			}
			int k=10;
			int p=1;
			if(i/10==0){
				ans++;
				while(n/(i*k)>0){
					if(n/(i*k)>1){
						ans+=2*p;
					}else{
						int tt=0;
						if((n%(i*k))%10>=i){
							tt++;
						}
						ans+=2*Math.min(p,(n%(i*k))/10+tt);
					}
					k*=10;
					p*=10;
				}
			}else{
				String s=String.valueOf(i);
				int f=s.charAt(0)-'0';
				int b=s.charAt(s.length()-1)-'0';
				while(n/(b*k)>0){
					if(n/(b*k)>1){
						ans+=p;
					}else{
						int tt=0;
						if((n%(b*k))%10>=f){
							tt++;
						}
						ans+=Math.min(p,(n%(b*k))/10+tt);
					}
					k*=10;
					p*=10;
				}
			}
		}
		System.out.println(ans);
}
}


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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

int main(){

	int n, k;
	int v[200010] = { 0 };
	int ans = 0;

	cin >> n >> k;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v[a]++;
	}
	sort(v,v+200000, greater<int>());

	for (int i = k; i < n; i++) {
		ans += v[i];
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1024
from collections import Counter

n = int(input())
q_list = []
a_list = []
for i in range(n):
    q = []
    x, y = map(int, input().split())
    q.append(x)
    q.append(y)
    q_list.append(q)
    if i != 0:
        for j in range(i):
            difx1 = q_list[j][0] - q_list[i][0]
            dify1 = q_list[j][1] - q_list[i][1]
            difx2 = q_list[i][0] - q_list[j][0]
            dify2 = q_list[i][1] - q_list[j][1]
            a_list.append(str(difx1)+str(dify1))
            a_list.append(str(difx2)+str(dify2))
if n != 1:
    zero = Counter(a_list).most_common()[0][1]
    print(n-zero)
else:
    print(1)

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n, r; cin>>n>>r;
	if(n<10)cout<<r+(100*(10-n))<<'\n';
	else cout<<r<<'\n';
	return 0;
}	

Measured memory_bytes: 256
from collections import defaultdict
def main():
    n,p=map(int,input().split())
    S=[int(x) for x in tuple(input().strip())]
    if p==2 or p==5:
        ans=0
        for i,s in enumerate(S):
            if s%p==0:
                ans+=(i+1)
        return ans
    d=defaultdict(int)
    tmp=0
    digit=1
    ans=0
    for i,s in enumerate(reversed(S)):
        tmp+=s*digit
        digit*=10
        digit%=p
        r=tmp%p
        ans+=d[r]
        d[r]+=1
    ans+=d[0]
    return ans
    
if __name__=='__main__':
    print(main())

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
#define MOD 1000000007

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<ll> llStack;
typedef queue<ll> llQueue;
typedef vector<ll> llVector;
typedef list<ll> llList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll N, K;
  cin >> N >> K;
  ll A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  
  ll now = 1;
  ll next = A[0];
  ll count = 0;
  ll f[N];
  ll start;
  ll l;
  for(int i=1;i<N;i++){
    f[i] = 0;
  }
  while(1){
    now  = next;
    next = A[now-1];
    count++;
    K--;
    if((f[now-1] > 0) || (now == 1)){
      start = f[now-1];
      l = count-start;
      K = K%l;
    }
    if(K == 0){
      break;
    }
    f[now-1] = count;
  }
  
  cout << now << endl;
}


Measured memory_bytes: 6760
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int dy[2] = {1,0};
int dx[2] = {0,1};
int h,w;
vector<string>s(10);

int main(){
    int n;cin>>n;
    VEC(int,a,n);
    int now = a[0];
    int cnt = 1;
    int res = 0;
    rep(i,n){
        if(i==0)continue;
        if(now==a[i]){
            cnt++;
        }
        else {
            res += cnt/2;
            cnt = 1;
            now = a[i];
        }
    }
    res += cnt/2;
    cout<<res<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

#define MAX 200000

int max(int a,int b) { return a>b ? a: b;}
int min(int a,int b) { return a<b ? a: b;}

int main(void) {
    int R[MAX], i, n;
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&R[i]);
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1; i<n; i++) {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }
    
    printf("%d\n",maxv);

    return 0;
}



Measured memory_bytes: 2564
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1ll<<(x))
#define inf 2005000
#define MOD 1000000007
#define N 2005
#define M 1000005
#define LOG 60
#define KOK 4000000
using namespace std;

ll a,b,tut;

int main() {

	//freopen("input.txt","r",stdin);

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

	if(a==b) {printf("1");return 0;}

	for(int i=LOG-1;i>=0;i--) {

		bool f=(a&pw(i))>0;
		bool s=(b&pw(i))>0;

		if(f && s) {

			a-=pw(i);
			b-=pw(i);

		}
		else if(s) {

			b-=pw(i);
			tut=pw(i);

			break ;

		}


	}	

	ll comp2=1;

	ll ra=tut-a;

	for(int i=LOG-1;i>=0;i--) {

		if(b&pw(i)) {

			comp2=pw(i+1);

			break ;

		}

	}

	ll ans=ra*2+comp2-max(0ll,comp2-1-a+1);

	printf("%lld",ans);

}

Measured memory_bytes: 256
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	map<int,int> num;
	for(int i=0;i<N;++i){
		int A;
		cin >> A;
		num[A]++;
	}

	map<int,int>::iterator itr,end;
	itr = num.begin();
	end = num.end();
	int ans = 0;
	for(;itr!=end;++itr){
		if( itr->second & 1 ){
			++ans;
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

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

using namespace std;
using ll = long long;

const int N = 3e5 + 5;
#define int long long

mt19937 rnd(51515);

ll n, d, a;
ll f[N], x[N], h[N];

void modify(int x, int val)
{
  while (x < n)
  {
    f[x] += val;   
    x |= x + 1;
  }
}

ll get(int x)
{
  ll res = 0;
  while (x >= 0)
  {
    res += f[x];
    x = (x & (x + 1)) - 1;
  }
  return res;
}

main() {
#ifdef ONPC
  freopen("a.in", "r", stdin);
#endif
  ios :: sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> d >> a;
  vector <pair <int, int> > v;
  vector <int> cor;
  for (int i = 1; i <= n; ++i)
  {
    cin >> x[i] >> h[i];
    cor.push_back(x[i]);
    v.push_back(make_pair(x[i], h[i]));
  }
  sort(cor.begin(), cor.end());
  sort(v.begin(), v.end());
  int kol = 0;
  for (int i = 0; i < n; ++i)
  {
    int kek = lower_bound(cor.begin(), cor.end(), v[i].first - d * 2) - cor.begin();
    if (v[i].second - (get(i) - get(kek - 1)) <= 0) continue;
    v[i].second -= (get(i) - get(kek - 1));
    if (v[i].second <= 0) continue;
    int lol = upper_bound(cor.begin(), cor.end(), v[i].first + d * 2) - cor.begin() - 1;
    kol += (v[i].second + a - 1) / a;
    modify(i, ((v[i].second + a - 1) / a) * a);
  }
  cout << kol;
  return 0;
}

Measured memory_bytes: 11360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> H(N);
    for (int i=0; i<N; ++i) cin >> H[i];
    sort(H.rbegin(), H.rend());

    if (N <= K) {
        cout << 0 << endl;
        return 0;
    }

    ll res = 0;
    for (int i=K; i<N; ++i) {
        res += H[i];
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
static const int64_t INF = 1000000000;


int main(){
	int H, N;
	cin >> H >> N;
	vector<int> A(N), B(N);
	rep(i, N) cin >> A[i] >> B[i];
	
	int64_t dp[H+1];
	rep(i, H+1) dp[i] = INF;
	dp[0] = 0;
	
	rep(i, N){
      rep(j, H+1){
		dp[min(j + A[i], H)] = min(dp[min(j + A[i], H)], dp[j] + B[i]);
      }
	}
	cout << dp[H] << endl;
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

int main() {
	int a, b, d, r;
	double a1, b1, f;
	cin >> a >> b;
	a1 = a;
	b1 = b;
	d = a / b;
	r = a % b;
	f = a1 / b1;
	cout << d << " " << r << " " << fixed << setprecision(5) << f << endl;
}


Measured memory_bytes: 3296
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB") cout << "No\n";
  else cout << "Yes\n";
}

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;
  vector<vector<int>> pos(30);
  for (int i = 0; i < (int)S.size(); i++) {
    pos[S[i] - 'a'].emplace_back(i);
  }

  for (int i = 0; i < 30; i++) {
    pos[i].emplace_back(1 << 28);
    sort(pos[i].begin(), pos[i].end());
  }

  int p = -1, res = 0;
  for (int i = 0; i < (int)T.size(); i++) {
    if ((int)pos[T[i] - 'a'].size() == 1) {
      cout << -1 << '\n';
      return 0;
    }
    int t = upper_bound(pos[T[i] - 'a'].begin(), pos[T[i] - 'a'].end(), p) -
            pos[T[i] - 'a'].begin();

    if (t >= (int)pos[T[i] - 'a'].size() - 1) {
      res++;
      p = pos[T[i] - 'a'][0];
    } else {
      p = pos[T[i] - 'a'][t];
    }
  }

  cout << 1LL * res * S.size() + 1LL * p + 1 << '\n';
  return 0;
}


Measured memory_bytes: 1228
//-----------------------
// author : xyqkoala
// time : 2020-07-27
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


LL qp(LL m,LL n){
	LL ans = 1;
	while(n){
		if(n&1){
			ans = (ans*m)%MOD;
		}
		m = (m*m)%MOD;
		n = n/2;
	}
	return ans;
}

void solve(){
	LL n,k;
	cin>>n>>k;
	vector<LL> dp(k+1,0);
	for(LL i=k;i>0;i--){
		dp[i] = qp(k/i,n);
		// cout<<dp[i]<<endl;
	}
	LL res = 0;
	for(int i=k;i>0;i--){
		int j = 2;
		while((i*j)<=k){
			dp[i] = (dp[i]-dp[i*j]+MOD)%MOD;
			j++;
		}

		res = (res+1ll*dp[i]*i)%MOD;
		// cout<<res<<endl;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3984
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables)]

use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;

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

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u64) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let line: Vec<u64> = read_vec();
    let n = line[0];
    let a = line[1];
    let b = line[2];

    let time = n / (a + b);

    println!("{}", time * a + min(n - time * (a + b), a))
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin >> N;
	int M;
	cin >> M;
	int nombre[N];
	for (int i = 0 ; i <N ; i++) nombre[i] = -1;
	for (int i = 0 ; i < M ; i++)
	{
		int a , b;
		cin >> a >> b;
		a--;
		if (nombre[a] != -1 && nombre[a] != b)
		{
			cout<<-1<<endl;
			exit(0);
		}
		nombre[a] = b;
	}
	if (N == 1)
	{
		if (nombre[0] != -1) cout<<nombre[0]<<endl;
		else cout<<0<<endl;
		exit(0);
	}
	if (nombre[0] == 0)
	{
		cout<<-1<<endl;
		exit(0);
	}
	bool ok = false;
	for (int i = 0 ; i < N ; i++)
	{
		if (nombre[i] != -1)
		{
			ok = true;
			cout<<nombre[i];
		}
		else
		{
			if (!ok) {cout<<1; ok = true;}
			else cout<<0;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char>> board(3,vector<char>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>board.at(i).at(j);
    }
  }
  for(int i=0;i<3;i++){
    cout<<board.at(i).at(i);
  }
  cout<<endl;
  return 0;
}

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

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

    string s;
    cin >> s;

    bool bad = false;

    for  (int i = 1; i < s.size(); i++)
    {
        if (s[i-1] == s[i])
        {
            bad = true;
        }
    }

    if(bad) cout << "Bad";
    else    cout << "Good";


    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
max_val = A[0]
min_val = float("inf")
for i in range(1,N):
    tmp_min = abs(max_val / 2 - A[i])
    if min_val > tmp_min:
        min_val = tmp_min
        ans_min = A[i]
print(max_val , ans_min)

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

int main() {
	int A, B, cnt = 0;
	cin >> A >> B;
	
	for(int i = 0; i < 2; i++) {
		if(A < B) {
			cnt += B;
			B--;
		} else {
			cnt += A;
			A--;
		}
	}
	cout << cnt << endl;
}

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

#define rep(n)      for (int i = 0; i < n; ++i)
#define rep2(n)     for (int j = 0; j < n; ++j)
#define mp          make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;

int main() {    
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    while (true) {
        c-=b;
        if (c<=0) {
            cout << "Yes\n";
            break;
        }
        a-=d;
        if (a<=0) {
            cout << "No\n";
            break;
        }
    }
        
    return 0;
}


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

int main(){
    int w, h, n;
    cin >> w >> h >> n;
    int a[n], x[n], y[n];
    int p[4]={0,w,0,h};
    rep(i,n){
        cin >> x[i] >> y[i] >> a[i];
        //大小比較わすれ
        if((a[i]==1&&p[0]<x[i])||(a[i]==2&&p[1]>x[i]))
            p[a[i] - 1] = x[i];
        if((a[i]==3&&p[2]<y[i])||(a[i]==4&&p[3]>y[i]))
            p[a[i] - 1] = y[i];
    }
    if(p[0]>=p[1]||p[2]>=p[3])
        cout << 0 << endl;
    else
        cout << (p[1] - p[0]) * (p[3] - p[2]) << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
t=[0]*n
p=[]
g=0
for i in range(n-1,-1,-1):
    if sum(t[i::i+1])%2!=a[i]:
        t[i]=1
        p.append(i+1)
        g+=1
print(g)
print(*p[::-1])

Measured memory_bytes: 14780
import sys

N, M = map(int,sys.stdin.readline().split())
L = 1
R = N

for _ in range(M):
  l, r = map(int, sys.stdin.readline().split())

  if L < l:
    L = l
  if R > r:
    R = r
  
if R-L+1 >= 0:
  print(R-L+1)
else:
  print(0)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  long double sum=0.0;
  long double x;
  string u;
  for(int i=0;i<n;i++){
    cin>>x>>u;
    if(u=="JPY"){
      sum+=x;
    }
    else{
      sum+=x*380000.0;
    }
  }
  cout<<sum<<endl;
  return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

    int x,cnt=0;
    cin>>x;

    rep(i,1,x+1){
        cnt += i;
        if(cnt >= x){
            cout<<i<<'\n';
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

void solve(){
  ll n,m;
  cin >> n >> m;
  
  vll ans(n,0);
  
  vvll G(n);
  
  while(m--){
   ll a,b;
    cin >> a >> b;
    --a;
    --b;
    if(a>b) swap(a,b);
    G[b].eb(a);
    G[a].eb(b);
  }
  
  vll flag(n,0);
  
  queue<ll> que;
  que.push(0);
  flag[0]=1;
  while(!que.empty()){
    ll now=que.front();
    que.pop();
    for(auto v:G[now]){
     if(flag[v]) continue;
     flag[v]=1;
     ans[v]=now+1;
     que.push(v); 
    }
  }
  
  ll f=1;
  for(auto a:flag) if(a==0) f=0;
  
   
  
  if(f){
    cout << "Yes" << endl;
   rep(i,1,n) cout << ans[i] << endl;
  }else{
    cout << "No" << endl;
  }
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

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

int main(){
  int n,k,a;
  cin >> n;
  k = n;
  a = n%10;
  for(int i = 0;;i++){
    if(k==0){
      break;
    }
    k /= 10;
    a += k%10;
  }
  if(n%a==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define mod 1000000007
#define pa(a,b) make_pair(a,b)
#define LL  long long int

using namespace std;
bool check(string s , int temp )
{
    for(int i=0;i<temp;i++)if(s[0]!=s[i])return false;
    return true;
}

int main()
{
    string s; int ans=1e9; cin>>s; int num[30]={0}; int mx=-1;
    for(int i=0;i<s.size();i++)num[s[i]-'a']++; int n=s.size();
    for(int i=0;i<26;i++)
    {
        if(num[i])
        {
            int temp=n; int t=0; string x=s;
            while(1&&temp)
            {
            if(check(x,temp)){ans=min(ans,t);  break;}
            for(int j=0;j<temp-1;j++)
            {
                if(char(i+'a')==x[j+1])x[j]=char(i+'a');
            }
            temp--; t++;
            }
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
from random import randint

def getrand():
    n = randint(1,3)
    m = randint(0,5)
    s = []
    for i in range(m):
        s.append([randint(1,n),randint(0,9)])
    s.sort()
    print([n,m])
    print(s)
    return n,m,s

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    return n,m,s

def getrand():
    n = randint(1,3)
    m = randint(0,5)
    s = []
    for i in range(m):
        s.append([randint(1,n),randint(0,9)])
    s.sort()
    print([n,m])
    print(s)
    return n,m,s

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    return n,m,s

def main(n,m,s):
    #Initiate
    temp = [-1 for i in range(n)]
    ans = ""
    flag = True
    #Exceptions: contains dup or ([1,0] and n>1)
    if [1,0] in s and n>1:
        flag = False
    for i in s:
        if not temp[i[0]-1] in [-1,i[1]]:
            flag = False
            break
        temp[i[0]-1] = i[1]
    if flag:
        if n==1:
            if m==0:
                ans = "0"
            else:
                ans = str(temp[0])
        else:
            if temp[0]==-1:
                temp[0] = 1
            for i in range(0,n):
                if temp[i]==-1:
                    temp[i] = 0
            for i in temp:
                ans += str(i)
    else:
        ans = "-1"
    print(ans)
        

if __name__=="__main__":
    #n,m,s = getrand()
    n,m,s = getval()
    main(n,m,s)
    #for i in range(10):
      #n,m,s = getrand()
      #main(n,m,s)

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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

int main(){
  using mint = modint<(int)1e9+7>;
  long long L, R;
  cin >> L >> R;
  mint dp[2][2][2];
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j)
      for(int k = 0; k < 2; ++k)
        dp[i][j][k] = 0;
  dp[1][1][0] = 1;

  for(int i = 60; i >= 0; --i){
    mint dp_[2][2][2];

    for(int j = 0; j < 2; ++j)
      for(int k = 0; k < 2; ++k)
        for(int l = 0; l < 2; ++l)
          dp_[j][k][l] = 0;

    for(int j = 0; j < 2; ++j){
      for(int k = 0; k < 2; ++k){
        for(int l = 0; l < 2; ++l){
          // y : 0, x : 0
          if((!j) or !((L>>i)&1)){
            int k_ = k&(!((R>>i)&1));
            dp_[j][k_][l] += dp[j][k][l];
          }
          // y : 1, x : 0
          if(l and ((!k) or ((R>>i)&1)) and ((!j) or !((L>>i)&1))){
            dp_[j][k][l] += dp[j][k][l];
          }
          // y : 1, x : 1
          if((!k) or (R>>i)&1){
            int j_ = j&((L>>i)&1);
            dp_[j_][k][1] += dp[j][k][l];
          }
        }
      }
    }

    swap(dp,dp_);
  }
  mint ans = 0;
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j)
      for(int k = 0; k < 2; ++k)
        ans += dp[i][j][k];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;

int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<int> v1(n),v2(m);
    for(int i=0;i<n;i++){
        cin>>v1[i];
    }
    for(int i=0;i<m;i++){
        cin>>v2[i];
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    int max_v1=max(x,v1[n-1]),max_v2=min(y,v2[0]);
    if(max_v1<max_v2){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    return 0;
}
    

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

int main(){
	int n;
	int top, front, right, sub, res;
	string order;
	
	while(true){
		cin >> n;
		if(n == 0) return 0;
		
		top = 1; front = 2; right = 3;
		res = 1;
		
		for(int i = 0; i < n; i++){
			cin >> order;
			if(order == "North"){
				sub = 7 - top;
				top = front;
				front = sub;
			}
			else if(order == "South"){
				sub = 7 - front;
				front = top;
				top = sub;
			}
			else if(order == "East"){
				sub = 7 - right;
				right = top;
				top = sub;
			}
			else if(order == "West"){
				sub = 7 - top;
				top = right;
				right = sub;
			}
			else if(order == "Right"){
				sub = 7 - front;
				front = right;
				right = sub;
			}
			else if(order == "Left"){
				sub = 7 - right;
				right = front;
				front = sub;
			}
			
			res += top;
		}
		
		cout << res << endl;
	}
}

Measured memory_bytes: 1208
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template<int Modulo = MOD>
struct Mint {

	lint val;
	constexpr Mint(lint v = 0) noexcept : val(v% Modulo) { if (val < 0) val += Modulo; }

	constexpr Mint& operator+=(const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator-=(const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator*=(const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator/=(const Mint& r) noexcept {
		lint a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			lint t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}

	constexpr Mint operator+(const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator-(const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator*(const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator/(const Mint& r) const noexcept { return Mint(*this) /= r; }

	constexpr Mint operator-() const noexcept { return val ? Modulo - val : 0; }

	constexpr bool operator==(const Mint& r) const noexcept { return val == r.val; }
	constexpr bool operator!=(const Mint& r) const noexcept { return !((*this) == r); }
	constexpr bool operator< (const Mint& r) const noexcept { return val < r.val; }

	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept { return os << x.val; }
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		lint tmp; is >> tmp;
		x = Mint(tmp);
		return is;
	}

	constexpr Mint pow(lint n) const noexcept {
		Mint res = 1, tmp = val;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;


struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N;
	cin >> N;


	vector<mint> memo(N + 1);
	memo[N] = 1;

	auto dfs = [&](auto &&f, int cut) -> mint {

		if (memo[cut] != 0) return memo[cut];

		mint sum = 0;
		for (int i = cut + 3; i <= N; i++) {
			sum += f(f, i);
		}

		return memo[cut] = sum;
	};

	dfs(dfs, 0);

	DMP(memo);
	cout << memo[0] << "\n";

	return 0;
}


Measured memory_bytes: 3664
#include <stdio.h>

void CookieExchange(int *a,int *b,int *c){
    int tmp1,tmp2;
    tmp1 = *a;
    tmp2 = *b;
    *a = (*b+*c)/2;
    *b = (tmp1+*c)/2;
    *c = (tmp1+tmp2)/2;

}



int main(void){
    int A,B,C;
    int i=0;
    scanf("%d %d %d",&A,&B,&C);
    int a = A,b = B,c = C;
    while(A%2 == 0 && B%2 == 0 && C%2 == 0){
        CookieExchange(&A,&B,&C);
        i++;
        if(A==a&&B==b&&C==c){
            printf("-1\n");
            return 0;
        }
    }
    printf("%d\n",i);
    return 0;
}


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

a, b = [0], [0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 47492
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <set>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=1005;
int w,h,n,X1[N],Y1[N],X2[N],Y2[N];
int grid[2*N][2*N],id[2*N][2*N];
int dsu[4*N*N];
int dir[2][2]={{1,0},{0,1}};

int fi(int x) {
    return dsu[x]==x?x:(dsu[x]=fi(dsu[x]));
}

int solve() {
    vector<int> lsh1,lsh2;
    lsh1.pb(0);lsh1.pb(w);
    for (int i=1;i<=n;i++) lsh1.pb(X1[i]),lsh1.pb(X2[i]);
    lsh2.pb(0);lsh2.pb(h);
    for (int i=1;i<=n;i++) lsh2.pb(Y1[i]),lsh2.pb(Y2[i]);
    sort(lsh1.begin(),lsh1.end());
    sort(lsh2.begin(),lsh2.end());
    lsh1.assign(lsh1.begin(),unique(lsh1.begin(),lsh1.end()));
    lsh2.assign(lsh2.begin(),unique(lsh2.begin(),lsh2.end()));
    int mm=lsh1.size()-1;
    int nn=lsh2.size()-1;

    memset(grid,0,sizeof(grid));
    int tot=0;
    for (int i=1;i<=nn;i++) {
        for (int j=1;j<=mm;j++) {
            id[i][j]=++tot;
        }
    }
    for (int i=1;i<=tot;i++) dsu[i]=i;

    for (int i=1;i<=n;i++) {
        int lx=lower_bound(lsh1.begin(),lsh1.end(),X1[i])-lsh1.begin();
        int rx=lower_bound(lsh1.begin(),lsh1.end(),X2[i])-lsh1.begin();
        int ly=lower_bound(lsh2.begin(),lsh2.end(),Y1[i])-lsh2.begin();
        int ry=lower_bound(lsh2.begin(),lsh2.end(),Y2[i])-lsh2.begin();
        for (int j=ly+1;j<=ry;j++) {
            for (int k=lx+1;k<=rx;k++) {
                grid[j][k]=1;
            }
        }
    }

    for (int i=1;i<=nn;i++) {
        for (int j=1;j<=mm;j++) {
            if (grid[i][j]==0) {
                for (int k=0;k<2;k++) {
                    int ii=i+dir[k][0];
                    int jj=j+dir[k][1];
                    if (ii<=nn&&jj<=mm&&grid[ii][jj]==0) {
                        int r1=fi(id[i][j]);
                        int r2=fi(id[ii][jj]);
                        dsu[r2]=r1;
                    }
                }
            }
        }
    }

    set<int> s;
    for (int i=1;i<=nn;i++) {
        for (int j=1;j<=mm;j++) {
            if (grid[i][j]==0) {
                s.insert(fi(id[i][j]));
            }
        }
    }

    return s.size();
}

int main()
{
    while (true) {
        scanf("%d%d",&w,&h);
        if (w==0&&h==0) break;
        scanf("%d",&n);
        for (int i=1;i<=n;i++) {
            scanf("%d%d%d%d",X1+i,Y1+i,X2+i,Y2+i);
        }
        printf("%d\n",solve());
    }
}


Measured memory_bytes: 23640
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n,a[55],A;
ll dp[2*51*51][55];
ll rec(ll i,ll s)
{
	if(i>n)
		return s==2500;
	if(dp[s][i]!=-1)
		return dp[s][i];
	ll an=0;
	an=rec(i+1,s)+rec(i+1,s+a[i]-A);
	return dp[s][i]=an;
}
int main()
{
	memset(dp,-1,sizeof dp);
	SPEED;
	cin>>n>>A;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	cout<<rec(1,2500)-1<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io
    
    ll n;
    cin>>n;
    ll a[n];
    rep(i,n) cin>>a[i];
    sort(a, a+n);
    ll ans=0;
    ll cnt=1;
   rep(i,n){
       if(a[i]==a[i+1]){
           cnt++;
       }else{
           if(cnt%2){
               ans++;
           }
           cnt=1;
       }
   }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
}

use std::iter;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input!{
        source = src,
        s: String,
    }

    return iter::repeat("x").take(s.len()).collect();
}


Measured memory_bytes: 4352
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        int HP;
        int amount;

        HP = sc.nextInt();
        amount = sc.nextInt();

        List<Integer> attack = new ArrayList<>();

        for (int i = 0; i < amount; i++) {
            attack.add(sc.nextInt());
        }
        int sum = 0;
        for (int i = 0; i < attack.size(); i++) {
            sum += attack.get(i);
        }
        if (sum >= HP) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    if(s != t.substr(0, n)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }


    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
//const int mod = 1e9 + 7;
const int mod = 998244353;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int r;
  cin >> r;
  cout << r*r << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

long long mod = 1e9+7;

long long modpow(long long x, long long n) {
    x = x%mod;
    if(n == 0){
        return 1;
    }
    else if(n%2 == 1){
        return(x*modpow(x, n-1))%mod;
    }
    else{
        return modpow((x*x)%mod, n/2)%mod;
    }
}

long long comb(long long n, long long k){
    long long x = 1;

    for(long long i = n-k+1; i <= n; i++){
        x = x*(i%mod);
        x = x%mod;
    }
    long long y = 1;
    for(long long i = 1; i <= k; i++){
        y = y*(i%mod);
        y = y%mod;
    }

    y = modpow(y, mod-2);

    return x*y%mod;
}

int main(){
    long long x, y;
    cin >> x >> y;

    if((x+y) % 3 != 0){
        printf("0\n");
        return 0;
    }

    long long n = (x+y)/3;
    long long k = (abs(x-2*n) + abs(y-n))/2;

    if(n <= x and x <= 2*n and n <= y and y <= 2*n){
        cout << comb(n, k) << endl;
    }
    else{
        printf("0\n");
    }

    
    return 0;
}

Measured memory_bytes: 3648
import math

N,K = map(int,input().split())

table = [0]*(N+1)
for i in range(1,N+1):
    if i >= K:
        table[i] = 1/N
    else:
        table[i] = math.ceil(math.log2(K/i))
        if table[i] != 0:
            table[i] = 0.5**table[i] / N

print(sum(table))


Measured memory_bytes: 6132
N=gets.to_i
x = 3500
1.upto(x) do |i|
    i.upto(x) do |j|
        # r = Rational(4,N) - Rational(1,i) - Rational(1,j)
        r = Rational(4*i*j-N*j-N*i,N*i*j)
        if r.numerator == 1
            puts [i,j,r.denominator].join(' ')
            exit
        end
    end
end



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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;


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

  int N;
  cin >> N;
  vector<set<int>> G(N);
  REP(i,N-1){
	int u, v;
	cin >> u >> v;
	--u;
	--v;
	G[u].insert(v);
	G[v].insert(u);
  }

  queue<int> q;
  REP(i,N)
	if(SZ(G[i]) == 1){
	  q.push(i);
	}

  bool win = false;
  while(!q.empty()){
	int u = q.front();
	q.pop();
	if(G[u].empty()){
	  win = true;
	  break;
	}

	int to = *begin(G[u]);
	for(int t: G[to]){
	  G[t].erase(to);
	  if(t != u && SZ(G[t]) <= 1)
		q.push(t);
	}
  }

  cout << (win?"First": "Second") << endl;

  return 0;
}


Measured memory_bytes: 14592
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    int n;
    cin >> n;
    vector<int> num_yaku(1010, 0);
    vector<int> prime;
    ll mod = 1e9+7;
    for(int i=2;i<1001;i++) {
        bool flag = true;
        for(int j=2;j<i;j++) {
            if(i%j==0) {
                flag = false;
                break;
            }
        }
        if(flag)
            prime.push_back(i);
    }

    for(int i=n;i>0;i--) {
        int temp = i;
        for(int j=2;j<=i;j++) {
            if(temp%j==0) {
                temp /= j;
                num_yaku[j] = (num_yaku[j]+1)%mod;
                j--;
                if(temp == 1)
                    break;
            }
        }
    }
    ll ans = 1;
    for(int i=2;i<num_yaku.size();i++) {
        if(num_yaku[i] != 0)
            ans = (ans *(num_yaku[i]+1)) % mod;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a=new int[n];
		Map<Integer,Long> group=new HashMap<>();
		for(int i=0;i<n;i++){
			a[i]= sc.nextInt();
			Long x=group.get(a[i]);
			if(x==null){
				group.put(a[i],(long)1);
			}else{
				group.put(a[i],x+1);
			}
		}
      	long all=0;
      	for(Integer key:group.keySet()){
          long v=group.get(key);
          all+=v*(v-1)/2;
        }  
		for(int i=0;i<n;i++){
			System.out.println(all-group.get(a[i])+1);
		}
		
	}
}


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

#define MAX 100000
#define BLACK 1
#define WHITE 0

int n,e;
vector<int> G[MAX];
int color[MAX];
int prenum[MAX],parent[MAX], lowest[MAX],timer;

void dfs(int current, int prev){
    prenum[current]=lowest[current]=timer;
    timer++;

    color[current]=BLACK;

    int next;

    for(int i=0;i<G[current].size();i++){
        next=G[current][i];
        if(color[next]==WHITE){
            parent[next]=current;

            dfs(next, current);

            lowest[current]=min(lowest[current],lowest[next]);
        }
        else if(next!=prev){
            lowest[current] = min(lowest[current],prenum[next]);
        }
    }
}
    void art_points(){
        for(int i=0;i<n;i++) color[i]=WHITE;
        timer=1;
        dfs(0,-1);

        set<int> ap;
        int np=0;
        for(int i=1;i<n;i++){
            int p= parent[i];
            if(p==0) np++;
            else if(prenum[p]<=lowest[i])ap.insert(p);
        } 
        if(np>=2)ap.insert(0);
        for(set<int>::iterator it = ap.begin(); it!=ap.end();it++) cout<< *it <<endl;
    }

    int main(){
        int s,t;
        cin>>n>>e;
        for(int i=0;i<e;i++){
            cin>>s>>t;
            G[s].push_back(t);
            G[t].push_back(s);
        }
        art_points();
        return 0;
    }




Measured memory_bytes: 6964
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

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

ll add(ll a, ll b) {
    return (a+b) % MODBASE;
}

ll mul(ll a, ll b) {
    return (a*b) % MODBASE;
}

ll sub(ll a, ll b) {
    return (a-b+MODBASE) % MODBASE;
}

ll f[MAXN], inv[MAXN], c[MAXN];
int n;

ll C(int N, int K) {
    if (K > N || K < 0) return 0;
    return mul(f[N], mul(inv[N-K], inv[K]));
}

void init() {
    f[0] = 1;
    inv[0] = binPowMod(f[0], MODBASE-2);
    FOR(i,1,200000) {
        f[i] = mul(f[i-1], i);
        inv[i] = binPowMod(f[i], MODBASE-2);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    init();
    
    cin >> n;
    
    FOR(i,1,n) cin >> c[i];
    sort(c+1, c+n+1);
    ll res = 0;
    FOR(i,1,n) {
        ll sum = add(binPowMod(2, n-i) ,mul(n-i, binPowMod(2, n-i-1)));
        // FOR(j,0,n-i) sum = add(sum, mul(j+1, C(n-i, j)));
        res = add(res, mul(mul(binPowMod(2, n-i+1), binPowMod(4, i-1)), mul(c[i], sum)));
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 4992