akhauriyash/Code-Regression huggingface dataset:
n, k = map(int,input().split())
MOD = 10**9+7
ans = 0
N = 5 * 10 ** 5
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
p = MOD
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
if k >= n-1:
    print(cmb(2*n-1, n, p))
else:
    for i in range(k+1):
        ans += cmb(n, i, p)*cmb(n-1, i, p) %MOD
    print(ans%MOD)
        

Measured memory_bytes: 62708
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  int n,k;
  while(cin>>n>>k,n+k){
    vector<bool> in(n+1,0);
    vector<bool> used;
    rep(i,k){
      int num;
      cin>>num;
      in[num]=true;
    }
    
    vector<int> dp(n);
    vector<int> box;
    int maxv = 0;
    loop(i,1,n+1){
      dp[i] = dp[i-1] + in[i];
      maxv = max(maxv,dp[i]);
      if(in[i]==0){
	dp[i] = 0;
	if(in[i-1] && in[i+1])box.push_back(i);
      }
    }
    if(in[0]){      
      for(int i = n-1 ; i > 0 ; i --){
	if(in[i])
	  dp[i] = max(dp[i],dp[i+1]);
      }
      rep(i,box.size()){
	maxv = max(maxv,dp[box[i]-1]+dp[box[i]+1]+1);
      }
    
    }
    cout<<maxv<<endl;
  }  
}

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

int main(){
    int bingo[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin>>bingo[i][j];
        }
    }

    int N;
    set<int> dat;
    bool flag = false;
    cin>>N;
    
    for(int i=0; i<N; i++){
        int b; cin>>b;
        dat.insert(b);
    }

    int cnt = 0;

    for(int i=0; i<3; i++){
        cnt = 0;
        for(int j=0; j<3; j++){
            if(dat.count(bingo[i][j])) cnt++;
        }
        if(cnt == 3) flag = true;
    }

    for(int i=0; i<3; i++){
        cnt = 0;
        for(int j=0; j<3; j++){
            if(dat.count(bingo[j][i])) cnt++;
        }
        if(cnt == 3) flag = true;
    }

    if(dat.count(bingo[0][0]) && dat.count(bingo[1][1]) 
     && dat.count(bingo[2][2])) flag = true;

    if(dat.count(bingo[0][2]) && dat.count(bingo[1][1]) 
     && dat.count(bingo[2][0])) flag = true;

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;

}

Measured memory_bytes: 256
N = int(input())
for i in range(N):
    if 10 **i <= N < 10 ** (i+1):
        keta_10 = i+1
        break
total = 0
if keta_10 % 2 == 0 :
    for k in range(1, keta_10 + 1):
        if k % 2 == 1:
            total = total + 9 * (10**(k-1))
else:
    for k in range(1, keta_10 + 1 - 2):
        if k % 2 ==1:
            total = total + 9 * (10**(k-1))
    total = total + N - 10 ** i + 1

print(total)

    

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = (ull)1e9 + 7;

int main(void)
{
	ll n;
	cin >> n;
	vector<P> vs(n);
	rep(i, n) {
		ll x, l;
		cin >> x >> l;
		vs[i] = make_pair(x - l, x + l);
	}
	sort(vs.begin(), vs.end());
	ll r0 = vs[0].second;
	ll count = 0;
	rep(i, n - 1) {
		ll rr = vs[i + 1].first;
		if (rr < r0) {
			count++;
			if (vs[i + 1].second < r0) {
				r0 = vs[i + 1].second;
			}
		}
		else {
			r0 = vs[i + 1].second;
		}
	}
	cout << (n-count) << endl;
	return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vi v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];
    sort(v.begin(),v.end());
    int counta=0,countb=0;
    for(int i=1;i<=n;i++){
        if((i&1)==1){
            counta+=v[n-i];
        }
        else{
            countb+=v[n-i];
        }
    }
    cout<<counta-countb<<endl;
    return 0;
}


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

int main(){
  int a,i,n,m,max=1000000,min=0;
  cin>>n>>m;
  for(i=0;i<m;i++){
    cin>>a;
    if(a>min){min=a;}
    cin>>a;
    if(a<max){max=a;}
  }
  if(max-min<0){cout<<0;}
  else{cout<<max-min+1;}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef vector<string> data;
int h, w, n;

void print(const data &d){ REP(i,h) cout << d[i] << endl; cout << endl;}

void drop(data &f){
  for(int i = h - 1; i > 0; i--){
    REP(j,w) if(f[i][j] == '.'){
      for(int y = i - 1; y >= 0; y--){
        if(f[y][j] != '.'){
          swap(f[i][j], f[y][j]);
          break;
        }
      }
    }
  }
}

bool solve(data &f){
  bool flag = true;
  while(flag){
    flag = false;
    vector<vector<int> > cnth(h, vector<int>(w, 1));
    vector<vector<int> > cntw(h, vector<int>(w, 1));
    int cnt = 0;
    REP(i,h) REP(j,w) if(f[i][j] != '.') cnt++;
    if(cnt == 0) return true;

    REP(i,h) REP(j,w) if(f[i][j] != '.'){
      if(i + 1 < h && f[i][j] == f[i+1][j])
        cnth[i+1][j] += cnth[i][j];
      if(j + 1 < w && f[i][j] == f[i][j+1])
        cntw[i][j+1] += cntw[i][j];
    }

    for(int i = h - 1; i >= 0; i--)
      for(int j = w - 1; j >= 0; j--)
        {
          if(cntw[i][j] >= n){ flag = true; REP(k,cntw[i][j]) f[i][j-k] = '.'; }
          if(cnth[i][j] >= n){ flag = true; REP(k,cnth[i][j]) f[i-k][j] = '.'; }
        }

    if(flag) drop(f);
  }
  return false;
}

int main(){
  cin >> h >> w >> n;
  data f(h);
  REP(i,h) cin >> f[i];

  REP(i,h) REP(j,w-1){
    data g = f;
    swap(g[i][j], g[i][j+1]); drop(g);
    if(solve(g)){
      puts("YES");
      return 0;
    }
  }

  puts("NO");
  return 0;
}

Measured memory_bytes: 904
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}
string s;


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}


int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);
   string a=RS() , b=RS() ,s=a+b ;
   stringstream v( s );
   int n=0;
   v >> n ;
   int y=sqrt(n) ;
   if(y*y == n)
    cout << "Yes";
   else
    cout << "No";

}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
 int n,k,x,i,j,a[10006];
bool check(int p)
{
    while(p>0)
    {
        if(a[p%10])
            return false;
        p=p/10;

    }
    return true;
}
int main()
{

    while(cin>>n>>k)
    {
        memset(a,0,sizeof(a));
        for(i=0;i<k;i++)
        {
            cin>>x;
            a[x]++;
        }
        for(i=n;;i++)
        {
            if(check(i)){
                    cout<<i<<endl;
            return 0;


            }
        }
    }
    return 0;
}


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

int main(){

  int n;
  cin>>n;
  
  int k;
  cin>>k;
  
  int arr[n];
  
  for(int i=0;i<n;i++){
  	cin>>arr[i];
  }

  std::sort(arr, arr+n);
   int initial_sum  = 0;  
    cout<<accumulate(arr, arr+k, initial_sum);
  
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;
  rep(i,1,n+1) {
    if (i % 2 == 1) {
      if (s.substr(i-1,1) == "L") {
        ok = false;
      }
    } else {
      if (s.substr(i-1,1) == "R") {
        ok = false;
      }
    }
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
    int n, x, sum;
    for (;;){
        int count=0;
        cin >> n >> x;
        if ( n==0 && x==0 ) break;
        for (int i=1; i<n+1; i++){
            for (int j=1; j<n+1; j++){
                for (int k=1; k<n+1; k++){
                    sum = i + j + k;
                    if (sum == x && i!=j && j!=k && k!=i) count += 1;   // 重複を許さない=3つの文字がそれぞれ異なる
                }
            }
        }
        count = count / 6;  // 組み合わせなので3の階乗で割る
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
def b (n) :
    def find_sum(y) :
        return ((y+1)*y)//2

    total = find_sum(n)
    total -= find_sum(n//3)*3
    total -= find_sum(n//5)*5
    total += find_sum(n//15)*15

    return total

if __name__ == "__main__" :
    n = int(input())
    print(b(n))


Measured memory_bytes: 9128
// Problem : D - I hate Factorization
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 1e4+500;
bool sieve[N+5];

void help()
{
    
    for(int i=2;i*i<=N;++i)
    {
        if(!sieve[i])
        {
            for(int j = i*i;j<=N;j+=i)
            {
                sieve[j] = true;
            }
        }
    }
}
int give(int x)
{
	int ans = 1;
	for(int i=1;i<=5;++i)
	ans*=x;
	return ans;
}

signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
    	int n;
    	cin>>n;
		for(int i=0;i<N;++i)
		{
			for(int j=0;j<=i;++j)
			{
				if(give(i)-give(j)==n)
				{
					cout<<i<<" "<<j;
					return 0;
				}
			}
		}
		for(int i=0;i<N;++i)
		{
			for(int j=0;j<=i;++j)
			{
				if(give(i)-give(-j)==n)
				{
					cout<<i<<" "<<-j;
					return 0;
				}
			}
		}
		
		    	
    }
    return 0;
}



Measured memory_bytes: 3568
#include <stdio.h>

  

int main(void){

  char str[1010];

  int i,sum;

  

  scanf("%s",str);

  while(str[0]!='0'){

    i=0;  sum=0;

    while(str[i]){

      sum+=str[i]-'0';  i++;

    }

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

    scanf("%s",str);

  }

  

  return 0;

}

Measured memory_bytes: 536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		solve(s, s.length());
	}

	private static void solve(String s, int len) {
		// TODO Auto-generated method stub
		long sum = 0;
		for(int i = 0; i < len; i++) {
			sum += s.charAt(i) - '0';
		}
		if (sum % 9 == 0) 
			System.out.println("Yes");
		else 
			System.out.println("No");
	}

}


Measured memory_bytes: 31028
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    int N;
    cin >> N;
    
    vector<int> L(N);
    for (int i = 0; i < N; i++) {
        int l;
        cin >> l;
        L[i] = l;
    }
    std::sort(L.begin(), L.end());
    
    ll cnt = 0;
    
    int a, b, c;
    for (int i = 0; i < N; i++) {
        c = L[i];
        for (int j = 0; j < i; j++) {
            b = L[j];
            for (int k = 0; k < j; k++) {
                a = L[k];
                //cerr << a << ", " << b << ", " << c << endl;
                if (c < a+b) {
                    cnt += 1;
                }
            }
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  set<string> items;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (!items.count(S)) {
      ans++;
      items.insert(S);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 19184
#include <bits/stdc++.h>
//#define inf 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inv(x) Power(x, mod - 2)
#define fi first
#define se second
#define MP make_pair
#define PB push_back

using namespace std;
typedef pair<int,int> Pair;
typedef long double ld;
typedef long long ll;

const int mod = 998244353, MAX = 1e5, N = 50005;
//template{{{
const long double Pi = 3.14159265358979323846l;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; };
inline void inc(int &x, int y) { x += y; x -= (x >= mod ? mod : 0); }
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int Power(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		x = mul(x, x), y >>= 1;
	} return ans;
}

/*char buf[1<<23],obuf[1<<23],*p1=buf,*p2=buf, *O = obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
void print(int x) {
    if(x > 9) print(x / 10);
    *O++=x%10+'0';
} */

template <class T> inline T	input() {
	T x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}

template <class T> inline bool chkmin(T &x, T y) { x = x < y ? x : y; return x == y; }
template <class T> inline bool chkmax(T &x, T y) { x = x > y ? x : y; return x == y; }
template <class T> inline T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
template <class T> inline T sqrm(T x) { return (ll) x * x % mod; }
template <class T> inline T sqr(T x) { return x * x; }

struct {
	inline operator int () { return input<int>(); }
	inline operator long long () { return input<long long>(); }
	template <class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read; //}}}

int n, m, Q;
int A[N], a[N], b[N], c[N], d[N];
long long ans = 0;

void dfs(int p) {
	if (p > n) {
		long long res = 0;
		for (int i = 1; i <= Q; ++i)
			if (A[b[i]] - A[a[i]] == c[i])
				res += d[i];
		chkmax(ans, res);
		return void();
	}

	for (int i = A[p - 1]; i <= m; ++i)
		A[p] = i, dfs(p + 1);
}

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	freopen("log", "w", stderr);
#endif

	read(n, m, Q);
	for (int i = 1; i <= Q; ++i) read(a[i], b[i], c[i], d[i]);

	A[0] = 1;
	dfs(1);

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


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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || abs(a - b) <= d && abs(b - c) <= d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

money = 1000
stock = 0
for day in range(N):
    if day == N - 1:
        money += stock * A[day]
        stock = 0
    elif A[day] == A[day+1]:
        continue
    elif A[day] < A[day+1]:
        stock += money // A[day]
        money = money % A[day]
    elif A[day] > A[day+1]:
        money += stock * A[day]
        stock = 0

print(money)


Measured memory_bytes: 61952
n = str(input())
x = list(n[i] for i in range(4))
if x[0] == x[1] == x[2] or x[1] == x[2] == x[3]:
  print('Yes')
elif x[0] == x[1] == x[2] == x[3]:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	
	int a, b;
	cin >> a >> b;
	

	
	cout <<(a+b)%24<< endl;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    int n,k; cin >> n >> k;
    string s; cin >> s;
    rep(i,n){
        if(i+1 == k)printf("%c",(s[i] + 32));
        else printf("%c",s[i]);
    }
    printf("\n");
}

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

void swap(int a, int b) {
    int t;
    if (a > b) {
        t = a; a = b; b = t;
    }
    cout << a << ' ' << b << '\n';
}

int main() {
    int a, b;

    for (int i = 0; i < 3000; i++) {
        cin >> a >> b;
        if (a == 0 && b == 0) break;
        swap(a,b);
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int N,M;cin>>N>>M;
	vi A(N); vin(A);
	int su = 0; rep(i,N) su += A[i];
	int cnt = 0;
	rep(i,N) {
		if(4*M*A[i] >= su) cnt++; 
	}
	if(cnt >= M) Yes
	else No
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        x: usize,
    }   

    let mut i = 0;
    let mut sum = 0;
    loop {
        if x<=sum {
            break;
        }
        i += 1;
        sum += i;
    }

    // if x==sum {
    //     println!("{}", i);
    // } else {
    //     println!("{}", i-1);
    // }

    println!("{}", i);

}


Measured memory_bytes: 2180
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;
using vi = vector<int>;

typedef long long llint;

const int MAXN = 2010;

int n, a[MAXN], adj[MAXN][MAXN];
vector<int> e[MAXN];
bool bio[MAXN];

void dfs(int x) {
  bio[x] = true;
  REP(y, n) {
    if (!adj[x][y]) continue;
    if (bio[y]) continue;
    e[x].push_back(y);
    dfs(y);
  }
}

vi solve(int x) {
  vector<vi> v;
  for (int y : e[x]) {
    auto tmp = solve(y);
    reverse(tmp.begin(), tmp.end());
    v.push_back(tmp);
  }

  vector<int> ret;
  if (x != n)
    ret.push_back(x);
  
  while (true) {
    int i = -1;
    REP(j, (int)v.size()) {
      if (v[j].empty()) continue;
      if (i == -1 || v[j].back() > v[i].back())
	i = j;
    }
    if (i == -1) break;
    ret.push_back(v[i].back());
    v[i].pop_back();
  }

  return ret;
}

int main(void) {
  scanf("%d",&n);
  REP(i, n) scanf("%d",&a[i]);
  sort(a, a + n);

  REP(i, n) REP(j, i) 
    adj[i][j] = adj[j][i] = (__gcd(a[i], a[j]) > 1) ? 1 : 0;

  REP(i, n)
    if (!bio[i]) {
      e[n].push_back(i);
      dfs(i);
    }

  auto sol = solve(n);
  for (int x : sol)
    printf("%d ",a[x]);
  printf("\n");
    
  return 0;
}


Measured memory_bytes: 16512
n,a,b = map(int,input().split())
mod = 10**9+7

def modInverse(a,p):
    # Fermat's little theorem, a**(p-1) = 1 mod p
    return pow(a,p-2,p)

def nCr(n,r,p=mod):
    num = 1
    den = 1
    for i in range(r):
        num = (num*(n-i)) % p
        den = (den*(i+1)) % p
    return num*modInverse(den,p)% p

ans = pow(2,n,mod)-1
print((ans-nCr(n,a)-nCr(n,b))%mod)

Measured memory_bytes: 3064
// 迷図と命ず
// 所要時間 分
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()

int main() {

    int w, h;
    while(true){
        cin >> w >> h;
        if(w == 0 && h == 0){
            break;
        }
        vector<vector<int> > graph(h, vector<int>(w));
        vector<vector<int> > tate(h, vector<int>(w-1));
        vector<vector<int> > yoko(h-1, vector<int>(w));
        rep(i, w-1){
            cin >> tate[0][i];
        }
        rep(k, h-1){
            rep(i, w){
                cin >> yoko[k][i];
            }
            rep(i, w-1){
                cin >> tate[k+1][i];
            }
        }

        queue<pair<int, int> > q;
        vector<vector<int> > dis(h, vector<int>(w, -1));
        q.push({0, 0});
        dis[0][0] = 1;
        const int dy[] = {0, 1, 0, -1};
        const int dx[] = {1, 0, -1, 0};
        while(!q.empty()){
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            rep(i, 4){
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(ny < 0 || nx < 0 || ny >= h || nx >= w){
                    continue;
                }
                if(abs(ny - y) == 1 && yoko[min(y, ny)][nx] == 1){
                    continue;
                }
                if(abs(nx - x) == 1 && tate[ny][min(x, nx)] == 1){
                    continue;
                }
                if(dis[ny][nx] == -1){
                    dis[ny][nx] = dis[y][x] + 1;
                    q.push({ny, nx});
                }
            }
        }        
        if(dis[h-1][w-1] != -1){
            cout << dis[h-1][w-1] << endl;
        }
        else{
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3024
#include<stdio.h>
int main() {
	int x, a, b;
	int m, n;
	scanf("%d %d %d", &x, &a, &b);
	m = x - a;
	n = x - b;
	if (m < 0) {
		m = 0 - m;
	}
	if (n < 0) {
		n = 0 - n;
	}
	if (m < n) {
		printf("A");
	}
	else {
		printf("B");
	}
	return 0;
}

Measured memory_bytes: 128
/**
     **author : _KMS_
     **created : 07-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6,MOD=2e9;
typedef long long ll;
bool prime[M+100];
int dp[M];
void precal()
{
      prime[0]=prime[1]=1;
      for(int i=2;i*i<M;i++)
      {
            if(!prime[i])
            {
                  for(int j=i*i;j<M;j+=i)
                  {
                        prime[j]=1;
                  }
            }
      }
      int cnt=0;
      for(int i=3;i<=100000;i++)
      {
            if(!prime[i]&&!prime[(i+1)/2])cnt++;
            dp[i]=cnt;
      }
}
int main() {
      
   ios::sync_with_stdio(false);
   cin.tie(0);
   precal();
   int q;
   cin>>q;
   while(q--)
   {
         int l,r;
         cin>>l>>r;
         cout<<dp[r]-dp[l-1]<<"\n";
   }
  
   return 0;
}

Measured memory_bytes: 3840
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int red[200005], whi[200005];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll ok = 1e9, ng = 0;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        ll cnt = 0;
        rep(i,n){
            cnt += (a[i] + mid - 1) / mid - 1;
        }
        if(cnt <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 4752
#include <iostream>
#include <algorithm>
#include <vector>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

int main()
{
    int Nums[3];
    cin >> Nums[0] >> Nums[1] >> Nums[2];

    sort(Nums, Nums + 3);

    if ((Nums[0] == Nums[1] && Nums[1] != Nums[2]) || (Nums[1] == Nums[2] && Nums[1] != Nums[0])) cout << "Yes";
    else cout << "No";
    
    return 0;
}

Measured memory_bytes: 256
n  = int(input())
#a = list(map(int,input().split()))
s = input()
alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ans=""
for i in range(len(s)):
    idx=0
    idx = alp.find(s[i])
    idx = (idx + n)%26
    ans = ans+alp[idx]
print(ans)
    


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int n;
int memo[45];

int fib(int n) {
  if (n == 0 || n == 1) {
    memo[n] = 1;
    return memo[n];
  } else if (memo[n] >= 0) {
    return memo[n];
  } else {
    memo[n] = fib(n - 1) + fib(n - 2);
    return memo[n];
  }

}

int main(void) {
  for (int i = 0; i < 45; i++) { memo[i] = -1; }
  cin >> n;
  cout << fib(n) << endl;
}



Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  string a,b,c;
  cin >> a;
  cin >>b;
  cin >>c;
  
  cout << a[0]<<b[1]<<c[2]<<endl;
  
  
   return 0;
}


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

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	string s;
	llint n;
	cin >> n;
	cin >> s;
	llint x=0;
	llint ans=x;
	for(char c:s){
		if(c=='I'){
			x++;
			ans=max(x,ans);
		}
		else x--;
	}
	cout << ans << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	long long int n,x,a1,a2,r=0;
	scanf("%lld %lld",&n,&x);
	scanf("%lld",&a1);
	if(a1>x){
		r=a1-x;
		a1=x;
	}
	while(--n){
		scanf("%lld",&a2);
		if(a1+a2>x){
			r+=a1+a2-x;
			a2=x-a1;
		}
		a1=a2;
	}
	printf("%lld\n",r);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
int n;
double x[1005], y[1005], X, Y, d, e;
double dist(double a, double b) {
    return a*a + b*b;
}
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lf%lf", &x[i], &y[i]);
        X += x[i]; Y += y[i];
    }
    X /= n; Y /= n;
    double P = 0.1;
    for (int i = 0; i < 30000; i++) {
        int f = 0;
        d = dist(X - x[0], Y - y[0]);
        for (int j = 1; j < n; j++) {
            e = dist(X - x[j], Y - y[j]);
            if (d < e) { d = e; f = j; }
        }
        X += (x[f] - X)*P;
        Y += (y[f] - Y)*P;
        P *= 0.999;
    }
    printf("%.10lf", sqrt(d));
}

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

char grid[2020][2020];
vector<int> bh[2020],bw[2020];

bool isOK(int index, int i, vector<int> &vec){
  if(vec[index]<i) return 1;
  else return 0;
}

int nibutan(int i, vector<int> &vec){
  int left = 0, right = vec.size()-1;
  while(right-left>1){
    int middle=(left+right)/2;
    if(isOK(middle,i,vec)) left = middle;
    else right = middle; 
  }
  return vec[right]-vec[left]-1;
}

int main(){
  int h,w;
  cin>>h>>w;
  rep(i,h)rep(j,w) cin>>grid[i][j];
  rep(i,h){
    bh[i].push_back(-1);
    rep(j,w){
      if(grid[i][j]=='#') bh[i].push_back(j);
    }
    bh[i].push_back(w);
  }
  rep(j,w){
    bw[j].push_back(-1);
    rep(i,h){
      if(grid[i][j]=='#') bw[j].push_back(i);
    }
    bw[j].push_back(h);
  }

  int ans=0;
  rep(hi,h)rep(wi,w){
    if(grid[hi][wi]=='#') continue;
    int H = nibutan(wi,bh[hi]), W = nibutan(hi,bw[wi]);
    ans=max(ans,H+W-1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 39376
#include <bits/stdc++.h>
using namespace std;
int n, ans;
struct node {
	int val, st;
}a[100005];
bool cmp(node t, node b) {
	return t.val < b.val;
}
int main() {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &a[i].val);
		a[i].st = i;
	}
	sort (a + 1, a + n + 1, cmp);
	for (int i = 1; i <= n; i++) {
		if ((a[i].st - i) % 2)
			ans++;
	}
	printf ("%d", ans/2);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 1000000007;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

ll n, k;
vvi adj;

ll dfs(int node, int par, int one, int two){
    ll ways = k-one-two;
    int c = 0;
    for(int x : adj[node]){
        if(x == par) continue;
        ways = (ways * dfs(x, node, 1, one+c)) % mod;
        c++;
    }
    return ways;
}

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

    cin >> n >> k;
    adj = vvi(n);
    for(int i = 0; i < n-1; i++){
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cout << dfs(0, -1, 0, 0) << endl;
}

Measured memory_bytes: 9600
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    string S;
    cin>>S;
    ll N=S.length();
    ll ans=0;
    vector<ll> rem(2019,0);
    FORI(i,0,N)
    {
        vector<ll> rem2(2019,0);
        ll x=(ll)S[i]-(ll)'0';
        FORI(j,0,2019)
        {
            rem2[(j*10+x)%2019]+=rem[j];
        }
        rem2[x]++;
        ans+=rem2[0];
        rem=rem2;
    }
    cout<<ans<<endl;

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


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3972
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
)

func f(x int) int {
	if x == 0 {
		return 0
	}
	return f(x%bits.OnesCount32(uint32(x))) + 1
}

func main() {
	var n int
	fmt.Scan(&n)
	s := ""
	fmt.Scan(&s)
	x := make([]int, n)
	for i, c := range s {
		x[i] = int(c - '0')
	}
	pc0 := 0
	for _, v := range x {
		pc0 += v
	}
	ans := make([]int, n)
	for b := 0; b < 2; b++ {
		pc := pc0
		if b == 0 {
			pc++
		} else {
			pc--
		}
		if pc <= 0 {
			continue
		}

		r0 := 0
		for _, v := range x {
			r0 *= 2
			r0 %= pc
			r0 += v
		}

		k := 1
		for i := n - 1; i >= 0; i-- {
			if x[i] == b {
				r := r0
				if b == 0 {
					r = (r + k) % pc
				} else {
					r = (r - k + pc) % pc
				}
				ans[i] = f(r) + 1
			}
			k = (2 * k) % pc
		}
	}
	w := bufio.NewWriter(os.Stdout)
	for _, v := range ans {
		fmt.Fprintln(w, v)
	}
	w.Flush()
}


Measured memory_bytes: 7024
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	int x,a,b;
	int d;

	cin>>x;
	cin>>a;
	cin>>b;

	d=x-a;

	cout<<d%b<<endl;


	return 0;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string n;
    cin >> n;
    rep(i,0,3){
        if(n[i] == '1'){
            cout << '9';
        }else{
            cout << '1';
        }
    }
    cout << endl;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int x, y;
    cin >> x >> y;
    while(y != 0){
        int a = (x>y)? x : y;
        int b = (x>y)? y : x;
        x = b;
        y = a%b;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3108
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

######
# URL: https://atcoder.jp/contests/abc122/tasks/abc122_b
######

def main():
    S = input()
    ans = 0
    for begin in range(len(S)):
        for end in range(begin, len(S)):
            if sum([ "ACGT".count(s) for s in S[begin:end+1]]) == len(S[begin:end+1]):
                ans = max(ans, len(S[begin:end+1]))
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct edge{ll from, to, weight;};

int main(){
  ll L;
  cin >> L;
  ll hoge = L;
  ll cnt = 0;
  while(hoge!=0){
    hoge = hoge/2;
    cnt++;
  }
  ll N = cnt;
  vector<edge> E;
  for(ll i = 1; i <= N-1; i++){
    edge e;
    e.from = i, e.to = i+1, e.weight = 1<<(i-1);
    E.push_back(e);
    e.weight = 0;
    E.push_back(e);
  }
  ll max = (1<<(N-1)) - 1;
  while(max!=L-1){
    edge e;
    e.from = floor(log2(L-max-1))+1, e.to = N; e.weight = max+1;
    E.push_back(e);
    max += 1<<(e.from-1);
  }
  cout << N << " " << E.size() << endl;
  for(auto e: E){
    cout << e.from << " " << e.to << " " << e.weight << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int w;
	cin>>w;
	string ans;
	int now=0;
	while(now<s.size()){
		ans+=s[now];
		now+=w;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
left = 0
right = 4472
while right - left > 1:
    mid = (left + right) // 2
    if mid * (mid + 1) // 2 < N:
        left = mid
    else:
        right = mid
ans = {i for i in range(1, right + 1)}
ans -= {right * (right - 1) // 2 - N + right}
print('\n'.join(map(str, ans)))


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int N;
int main(void){
	cin >> N;
	int ans=0;
	for(int i=0;i<N;i++){
		char h;
			cin >> h;
		if(h=='R')
			ans++;
	}
	if(ans>N/2)
		cout << "Yes"<<endl;
	else
		cout <<"No" << endl;
	return 0;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n; 
    while (cin >> n) {
        map<string,int> cnt;
        FOR(i,1,n+1) {
            const string s = to_string(i);
            const string p = string() + s[0] + s.back();
            cnt[p]++;
        }
        int ans = 0;
        FOR_ALL(i,cnt) {
            const string p = i->first;
            const int    c = i->second;
            if (p[0] == p[1])
                ans += c * (c-1) + c;
            else {
                const string pp = string() + p[1] + p[0];
                const int    cc = cnt[pp];
                ans += c * cc;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;

const int mod = 1e9 + 7;


int main(int argc, char *argv[]) {
	long long int n, k;
	cin >> n >> k;
	long long int res = 0;

	for (long long int i = k; i <= n + 1; i++) {
		// 0 -> i - 1
		// n - i + 1 -> n
		res += (n + n - i + 1) * i / 2 - (i - 1) * i / 2 + 1;
		res %= mod;
	}
	cout << res << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  ll n;
  vector<ll> a(5);
  cin >> n;
  REP(i, 5) cin >> a[i];
  ll m = *min_element(ALL(a));
  cout << (n+m-1)/m + 4 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  string s;
  cin >> s;
  int c = 0;
  rep(i, 3) if (s[i] == 'R') c++;
  int ans = 0;
  if (c == 3) ans = 3;
  else if (c == 2) {
    if (s[1] == 'S') ans = 1;
    else ans = 2;
  } else if (c == 1) {
    ans = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main(){
	double r,s,c;
	scanf("%lf",&r);
        s = r*r*M_PI;
        c = r*2*M_PI;
	printf("%lf %lf\n",s,c);
	return 0;
}

Measured memory_bytes: 3200