akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int A[N];
    rep(i,N){
        cin>>A[i];
    }

    int dp[N+1][3]{};
    dp[0][0]=1000;
    dp[0][1]=0;
    dp[0][2]=0;
    rep(i,N){
        dp[i+1][0]=max(dp[i][0],dp[i][2]*A[i]+dp[i][1]);
        if(dp[i][0]/A[i]==dp[i][2]) {
            dp[i+1][1]=max(dp[i][0]%A[i],dp[i][1]);
            dp[i+1][2]=dp[i][2];
        }
        else if(dp[i][0]/A[i]>dp[i][2]){
            dp[i+1][1]=dp[i][0]%A[i];
            dp[i+1][2]=dp[i][0]/A[i];
        }else{
            dp[i+1][1]=dp[i][1];
            dp[i+1][2]=dp[i][2];
        }
    }

    cout << dp[N][0]<<endl;

    



}


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

using namespace std;

const int Nmax = 1e5 + 5;

int t[Nmax], w[Nmax];
pair<int,int> edge[Nmax];
vector<int> v[Nmax];
int n, m;
bool used[Nmax];


void dfs(int node)
{
    for(auto it : v[node])
        if(!t[it])
        {
            t[it] = node;
            dfs(it);
        }
}

void dfs2(int node)
{
    used[node] = 1;
    for(auto it : v[node])
        if(!used[it])
        {
            dfs2(it);
            w[node] ^= w[it] ^ 1;
        }
}

void print(int x, int y)
{
    cout << x << ' ' << y << '\n';
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    int i, x, y;

    cin >> n >> m;

    if(m % 2)
    {
        cout << "-1\n";
        return 0;
    }

    for(i=1; i<=m; ++i)
    {
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);

        edge[i] = {x, y};
    }

    t[1] = -1;
    dfs(1);

    for(i=1; i<=m; ++i)
    {
        tie(x, y) = edge[i];
        if(t[x] != y && t[y] != x) w[x] ^= 1, print(x, y);
    }

    dfs2(1);

    for(i=1; i<=m; ++i)
    {
        tie(x, y) = edge[i];
        if(t[x] == y) swap(x, y);

        if(t[y] == x)
        {
            if(w[y]) print(y, x);
                else print(x, y);
        }
    }

    return 0;
}


Measured memory_bytes: 13184
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) v.erase(unique(ALL(v)), v.end())
#define bit(i) (1LL<<i)
#define sz(v) ((LLI)(v).size())

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

class Doubling{
public:
  int n;
  int m;
  vector<vector<int>> table;
  
  // 常に、next[i] >= i を満たすようにする。
  Doubling(const vector<int> &next): n(next.size()), m(ceil(log2(n))+1), table(m, vector<int>(n)){
    REP(i,n) table[0][i] = next[i];
    FOR(i,1,m){
      REP(j,n){
	table[i][j] = table[i-1][table[i-1][j]];
      }
    }
  }

  int distance(int a, int b){ // aからbに移動する(超える)最小回数 (a<=b)
    int ret = 0;
    int cur = a;

    while(1){
      if(table[0][cur] >= b){
	++ret;
	break;
      }

      if(table[0][cur] == cur) return -1;

      FOR(i,1,20){
	if(table[i][cur] >= b){
	  ret += (1<<(i-1));

	  cur = table[i-1][cur];
	  break;
	}
      }
    
    }
    
    return ret;
  }

};

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

  int N;
  while(cin >> N){
    vector<int> x(N); cin >> x;
    int L; cin >> L;

    vector<int> next(N);

    REP(i,N){
      next[i] = upper_bound(ALL(x), x[i]+L) - x.begin() - 1;
    }

    Doubling doubling(next);

    int Q; cin >> Q;
    REP(i,Q){
      int a,b; cin >> a >> b;
      --a, --b;
      if(a>b) swap(a,b);

      int ans = doubling.distance(a,b);
      
      cout << ans << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 8696
N = int(input())
p = list(map(int,input().split()))
q = list(p)
ans = 'NO'
# i<j piとpjを入れ替える

if p == sorted(q):
  ans = 'YES'
else:
  for i in range(N-1):
    for j in range(i+1,N):
      p[i],p[j] = p[j],p[i]
      if p == sorted(q):
        ans = 'YES'
        break
      else:
        p[i],p[j] = p[j],p[i]
print(ans)

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

int main() {
	int A,B,C ; cin >>A>>B>>C;
	int minA,minB,minAB; minA = min(A,2*C);minB = min(B,2*C);
	minAB = min(A+B,2*C);
	int X,Y; cin >>X>>Y;
	if(X > Y)
	cout << min(X,Y)*minAB + (X-Y)*minA << endl;
	if(X <= Y)
	cout << min(X,Y)*minAB + (Y-X)*minB << endl;
}

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

using namespace std;

int n, m, cnt;
int a[55][55];
int b[55];

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 0; i < m; i++)
    {
        int t1, t2;
        scanf("%d%d", &t1, &t2);
        a[t1][t2] = 1;
        a[t2][t1] = 1;
        b[t1]++;
        b[t2]++;
    }
    for(int i = 1; i <= n; i++)
    {
        bool flag = true;
        for(int j = 1; j <= n; j++)
        {
            if(b[j] == 1)
            {
                flag = false;
                cnt++;
                b[j] = 0;
                for(int k = 1; k <= n; k++)
                {
                    if(a[k][j] == 1)
                    {
                        a[k][j] = 0;
                        b[k]--;
                    }
                }
            }
        }
        if(flag) break;
    }
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 256
using System;

class Sample
{
  public static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    int a = N % 10;
    switch(a)
    {
      case 0:
        Console.WriteLine("pon");
        break;
      case 1:
        Console.WriteLine("pon");
        break;
      case 2:
        Console.WriteLine("hon");
        break;
      case 3:
        Console.WriteLine("bon");
        break;
      case 4:
        Console.WriteLine("hon");
        break;
      case 5:
        Console.WriteLine("hon");
        break;
      case 6:
        Console.WriteLine("pon");
        break;
      case 7:
        Console.WriteLine("hon");
        break;
      case 8:
        Console.WriteLine("pon");
        break;
      default :
        Console.WriteLine("hon");
        break;
    }
  }
}

Measured memory_bytes: 17632
#include <iostream>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main() {
    int n, k, x, y, total;
    cin >> n >> k >> x >> y;
    if (k <= n) {
        total = k*x + (n-k)*y;
    }
    else {
        total = n*x;
    }
    cout << total << endl;
}

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

int main() {
  int N,A,B;
  int sum = 0;
  cin >> N;
  
  for(int i=0;i<N;i++){
    cin >> A >> B;
    sum += B-A+1;
    }

  cout << sum << endl;  
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

constexpr static int MOD = 1000000000 + 7;
constexpr static int inf = INT_MAX / 2;
constexpr static llong INF = 1LL << 31;
constexpr static int dx[] = {1, 0, -1, 0};
constexpr static int dy[] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    vector<vector<int> > sw(n);
    vector<int> p(m);
    rep(i, n) {
        rep(j, m) sw[i].push_back(0);
    }

    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            sw[s - 1][i] = 1;
        }
    }

    rep(i, m) cin >> p[i];
    int ans = 0;
    vector<int> cnt(m, 0);
    for (int bit = 0; bit < (1 << n); ++bit) {
        rep(i, n) {
            if (bit & (1 << i)) {
                rep(j, m) {
                    if (sw[i][j]) ++cnt[j];
                }
            }
        }

        int tmp = 0;
        rep(i, m) {
            if (cnt[i] % 2 == p[i]) ++tmp;
        }

        if (tmp == m) ++ans;

        rep(i, m) {
            cnt[i] = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) return euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	int n;
	cin >> n;
	int ans = 0;
	vector<int> a;
	FOR(i, 1, n + 1) {
		FOR(j, 1, n + 1) {
			a.push_back(euclidean_gcd(i, j));
		}
	}

	rep(i, a.size()) {
		FOR(j, 1, n + 1) {
			ans += euclidean_gcd(a[i], j);
		}
	}

	cout << ans << endl;
}




Measured memory_bytes: 3788
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int N = 3e5+10;
inline int read()
{
	register int x = 0 , f = 0; register char c = getchar();
	while(c < '0' || c > '9') f |= c == '-' , c = getchar();
	while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0' , c = getchar();
	return f ? -x : x;
}
int n;
int s[N] , p[N] , mx[N];
vector<int> v;
int main()
{
	n = read();
	for(int i = 1 ; i <= n ; ++i) s[i] = read();
	for(int i = 1 ; i <= n ; ++i) p[i] = s[i] == i;
	for(int i = 2 ; i <  n ; ++i) if(!p[i-1] && !p[i] && !p[i+1]) return puts("No") , 0; // 有连续3个都是不能交换的。 
	for(int i = 1 , j = 1; i <= n ; i = j + 1)
	{
		j = i;
		while(j < n && p[j] != p[j+1]) ++j;
		v.clear(); v.push_back(0);
		for(int k = i ; k <= j ; ++k) 
		{
			if(s[k] < i || s[k] > j) return puts("No") , 0; // 不在值域范围内。 
			if(!p[k]) v.push_back(s[k]);
		}
		mx[1] = v[1];
		for(int k = 2 ; k < (int)v.size() ; ++k) mx[k] = max(mx[k-1] , v[k]);
		int mi = 2e9;
		for(int k = (int)v.size() - 1 ; k >= 3 ; --k)
		{
			mi = min(mi , v[k]);
			if(mx[k-2] > v[k-1] && v[k-1] > mi) return puts("No") , 0; // 出现了 a > b > c 的情况 
		}
	}
	puts("Yes"); // 没有不合法的情况， 
	return 0;
}
/*
7
3 2 1 6 5 4 7
*/

/*
还有一片题解，写的是
先判总的逆序对数是不是3的倍数。
然后看奇数位上是不是都是奇数，偶数位上是不是都是偶数，
最后判奇数位上的逆序对+偶数位上的逆序对是不是总的的1/3 
*/

Measured memory_bytes: 3828
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}


int main() {
	ll N;
	cin >> N;
	ll ans = N*N*N;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
void main()
{
    long n = rdElem;
    long[] v = rdRow;
    long[] c = rdRow;

    v[] -= c[];
    v.sort!"a > b";
    long result;
    foreach (x; v)
    {
        if (x > 0) result += x;
        else break;
    }

    result.writeln;
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s,t;
int main()
{
	cin>>n>>s>>t;
	for (int i=n;i;i--)
	{
		bool f=true;
		for (int j=0;j<i;j++)
		{
			if (t[j]!=s[n-i+j])
			{
				f=false;
				break;
			}
		}
		if (f)
		{
			cout<<n+n-i<<endl;
			return 0;
		}
	}
	cout<<n+n<<endl;
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<pair<ll,ll>> zahyo(n);
	rep(i,n) {
		ll x, y;
		cin >> x >> y;
		zahyo[i] = make_pair(x,y);
	}
	
	int ans = 0;
	
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if(i == j) continue;
			ll p = zahyo[i].first - zahyo[j].first;
			ll q = zahyo[i].second - zahyo[j].second;
			int count = 0;
			for (int k = 0; k < n; ++k) {
				for (int l = 0; l < n; ++l) {
					if(k == l) continue;
					ll dx = zahyo[k].first - zahyo[l].first;
					ll dy = zahyo[k].second - zahyo[l].second;
					if(dx == p && dy == q){
						count++;
					}
				}
			}
			ans = max(ans, count);
		}
	}
	
	cout << n - ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll n; cin >> n;
    vector<ll> a(n), b(n);
    ll a_sum = 0, b_sum = 0;

    rep(i, n){
        cin >> a[i];
        a_sum += a[i];
    }
    rep(i, n){
        cin >> b[i];
        b_sum += b[i];
    }
    if(a_sum > b_sum){
        cout << "No" << endl;
        return 0;
    }
    ll sum_ab = 0, sum_ba = 0; // sum_ab : count a < b, sum_ba : b < a  
    rep(i, n){
        if(b[i] < a[i]){
            sum_ba += (a[i] - b[i] + 1) / 2;
        }else{
            sum_ab += (b[i] - a[i] + 1) / 2;
        }
    }
    if(sum_ba > b_sum - a_sum or sum_ab > b_sum - a_sum){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int tap = 1, A, B;
	cin >> A >> B;
	for (size_t i = 0; true; i++)
	{
		if (tap >= B) { cout << i; return 0; }
		tap += A - 1;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll ans = 0;
  ans = (b / x) - (a / x);
  if (a % x == 0) ans++;
  P(ans);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> cnt(n + 2);
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        cnt[a]++;
    }
    std::sort(cnt.rbegin(), cnt.rend());
    std::vector<int> overw(n + 2), acc(n + 2);
    for (int i = n; i > 0; i--) {
        overw[i] = overw[i + 1];
        while (cnt[overw[i]] >= i) overw[i]++;
    }
    for (int i = n - 1; i >= 0; i--) {
        acc[i] = cnt[i] + acc[i + 1];
    }
    for (int h = 1; h <= n; h++) {
        int lo = 0, hi = n / h + 1;
        while (hi - lo > 1) {
            int mid = lo + (hi - lo) / 2;
            if (overw[mid] + acc[overw[mid]] / mid >= h) lo = mid;
            else hi = mid;
        }
        std::cout << lo << std::endl;
    }
    return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, m;
	int64_t q = pow(10, 9) + 7, ans = 1;

	cin >> n >> m;
	if (abs(n - m) > 1)
	{
		cout << 0 << endl;
		return (0);
	}
	for (int i = 1; i <= n; i++)
		ans = (ans * i) % q;
	for (int i = 1; i <= m; i++)
		ans = (ans * i) % q;
	if (n == m)
		ans = (ans * 2) % q;
	cout << ans << endl;
	
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define MAX 3001
using namespace std;
long long N,MOD;
long long Dp[MAX][MAX];
long long Combination[MAX][MAX]; 
inline long long Quick_Power(long long A,long long P,long long MOD)
{
	register long long Return;
	Return=1;
	while(P)
	{
		if(P&1)
		{
			Return=Return*A%MOD;
		}
		A=A*A%MOD;
		P>>=1;
	}
	return Return;
}
int main(void)
{
	register long long i,j;
	cin>>N>>MOD;
	for(i=0;i<=N;i++)
	{
		Dp[i][0]=1;
		for(j=1;j<=i;j++)
		{
			Dp[i][j]=(Dp[i-1][j-1]+(j+1)*Dp[i-1][j]%MOD)%MOD;
		}
	}
	for(i=0;i<=N;i++)
	{
		Combination[i][0]=1;
		for(j=1;j<=i;j++)
		{
			Combination[i][j]=(Combination[i-1][j-1]+Combination[i-1][j])%MOD;
		}
	}
	register long long Ans;
	Ans=0;
	for(i=0;i<=N;i++)
	{
		register long long Can;
		Can=Quick_Power(2,Quick_Power(2,N-i,MOD-1),MOD);
		register long long Num;
		Num=Quick_Power(2,N-i,MOD);
		register long long Sum;
		Sum=0;
		register long long Coefficient;
		Coefficient=1;
		for(j=0;j<=i;j++)
		{
			Sum=(Sum+Dp[i][j]*Coefficient)%MOD;
			Coefficient=Coefficient*Num%MOD;
		}
		Ans=(Ans+Sum*(Can*(i&1?MOD-Combination[N][i]:Combination[N][i])%MOD)%MOD)%MOD;
	}
	cout<<Ans<<endl; 
	return 0;
}

Measured memory_bytes: 95836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u)a--;
    if(t == u)b--;
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
require 'set'

n, m = gets.chomp!.split(" ").map!(&:to_i)
a_n = gets.chomp!.split(" ").map!(&:to_i).sort_by!{|x| x }

x = SortedSet.new(a_n)
bc_m = {}

a_n.each do |a|
    bc_m[a] = (bc_m[a] || 0) + 1 
    x << a
end

m.times do |i|
    b, c = gets.chomp!.split(" ").map!(&:to_i)
    bc_m[c] = (bc_m[c] || 0) + b
    x << c
end

sum = 0
count = 0
x.reverse_each do |i|
    if count + bc_m[i] >= n
        sum += ((n - count) * i)
        break
    else
        sum += bc_m[i] * i
        count += bc_m[i]
    end
end

puts sum


Measured memory_bytes: 41448
if __name__ == "__main__":
    num_a = int(input())
    a = list(map(lambda x: int(x), input().split()))
    num_query = int(input())

    for _ in range(num_query):
        begin, end = map(lambda x: int(x), input().split())
        if (0 == begin):
            a[begin: end] = a[end - 1:: -1]
        else:
            a[begin: end] = a[end - 1: begin - 1: -1]

    print(" ".join([str(elem) for elem in a]))



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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    for (ll i = K; i <= N + 1; ++i) {
        ll b = i * (i - 1) / 2;
        ll n = (N - i);
        ll t = N * (N + 1) / 2 - n * (n + 1) / 2;

        ans = (ans + t - b + 1) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n, a, b, x, y;
  cin >> n >> a >> b;
  x = n * a;
  y = b;

  if (x <= y) {
    cout << x << endl;
  }
  else {
    cout << y << endl;
  }
}

Measured memory_bytes: 3552
n=int(input())
m=[list(map(str,input().split())) for i in range(n)]

cnt=0

for i in range(n):
  m[i][0]=float(m[i][0])
  if m[i][1]=='BTC':
    m[i][0]*=380000.0
  cnt+=m[i][0]

print(cnt)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
 
const double eps = 1e-8;
const double inf = 1e10;
 
bool equals(double a, double b) {
  return abs(a-b) < eps;
}
 
struct P {
  double x, y, z;
  P() : x(0), y(0), z(0) {}
  P(double x, double y, double z) : x(x), y(y), z(z) {}
};
 
P operator + (const P &a, const P &b) {
  return P(a.x+b.x, a.y+b.y, a.z+b.z);
}
P operator - (const P &a, const P &b) {
  return P(a.x-b.x, a.y-b.y, a.z-b.z);
}
P operator * (const P &p, const double &a) {
  return P(p.x*a, p.y*a, p.z*a);
}
P operator / (const P &p, const double &a) {
  return P(p.x/a, p.y/a, p.z/a);
}
 
double dot(P a, P b) {
  return a.x*b.x + a.y*b.y + a.z*b.z;
}
 
double norm(P a) {
  return dot(a,a);
}
 
double abs(P a) {
  return sqrt(norm(a));
}
 
P project(P s1, P s2, P p) {
  P base = s2 - s1;
  double t = dot(p - s1, base)/norm(base);
  return s1 + base*t;
}
 
P reflect(P s1, P s2, P p) {
  return p + (project(s1, s2, p) - p)*2.0;
}
 
double getDistanceLP(P s1, P s2, P p) {
  return abs(project(s1, s2, p) - p);
}
 
P getQ(P s1, P s2, P p, double r) {
  P m = project(s1, s2, p);
  P base = s2 - s1;
  double x = r*r - norm(m-p);
  if(equals(x, 0.0)) x = 0.0;
  else if(x < 0) return P(inf,inf,inf);
  return m - base * sqrt(x) / abs(base);
}
 
int main() {
  int N;
  P v;
  vector<P> p;
  vector<double> r;
  while(cin >> N && N) {
    p.resize(N);
    r.resize(N);
    cin >> v.x >> v.y >> v.z;
    for(int i = 0; i < N; ++i) {
      cin >> p[i].x >> p[i].y >> p[i].z >> r[i];
    }
     
    P s, t;
    t = v;
    while(1) {
      double mini = inf;
      int k = -1;
      for(int i = 0; i < N; ++i) {
        P q = getQ(s, t, p[i], r[i]);
        if(q.x == inf) continue;
        if(dot(t-s, q-s) < eps) continue;
        double dist = abs(q - s);
        if(mini > dist) {
          mini = dist;
          k = i;
        }
      }
      if(k == -1) break;
      P q = getQ(s, t, p[k], r[k]);
      t = reflect(p[k], q, s);
      s = q;
    }
    printf("%.4f %.4f %.4f\n", s.x, s.y, s.z);
  }
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#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 sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<vector<int>> a(n,vector<int>(n-1));
    rep(i,n)rep(j,n-1){
        cin>>a[i][j];
        a[i][j]--;
    }
    int f=0;
    vector<int> t(n,0);
    queue<int> que;
    rep(i,n)que.push(i);
    ll res=0;
    while(true){
        res++;
        queue<int> que2;
        bool used=false;
        vector<bool> ft(n,false);
        while(que.size()){
            int x=que.front();que.pop();
            if(ft[x])continue;
            int op=a[x][t[x]];
            if(ft[op])continue;
            if(a[op][t[op]]==x){
                used=true;
                ft[x]=ft[op]=true;
                t[x]++;t[op]++;
                if(t[x]==n-1)f++;
                else que2.push(x);
                if(t[op]==n-1)f++;
                else que2.push(op);
            }
        }
        if(!used){
            cout<<-1<<endl;
            return 0;
        }
        if(f==n){
            cout<<res<<endl;
            return 0;
        }
        swap(que,que2);
    }
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
	
	public static void push(int x, int y, boolean[][] p_array, boolean[][] e_array){
		p_array[y][x] = !p_array[y][x];
		e_array[y][x] = !e_array[y][x];
		
		if(x != 0){
			e_array[y][x-1] = !e_array[y][x-1];
		}
		
		if(x != SIZE-1){
			e_array[y][x+1] = !e_array[y][x+1];
		}
		
		if(y != 0){
			e_array[y-1][x] = !e_array[y-1][x];
		}
		
		if(y != SIZE-1){
			e_array[y+1][x] = !e_array[y+1][x];
		}
	}
	
	public static void set(int x, int y, boolean sw, boolean[][] p_array, boolean[][] e_array){
		if(sw){
			push(x,y,p_array,e_array);
		}
	}
	
	public static final int SIZE = 10;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		boolean[][] array = new boolean[SIZE][SIZE];
		boolean[][] effect_array = new boolean[SIZE][SIZE];
		boolean[][] put_array = new boolean[SIZE][SIZE];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < SIZE; j++){
				for(int k = 0; k < SIZE; k++){
					array[j][k] = sc.nextInt() == 0 ? false : true;
				}
			}
			
			for(int cur = 0; cur < (1 << SIZE); cur++){
				
				for(int j = 0; j < SIZE; j++){
					for(int k = 0; k < SIZE; k++){
						put_array[j][k] = effect_array[j][k] = false; 
					}
				}
				
				set(9 , 0 , (((cur >> (SIZE - 10)) % 2) == 0) ? false : true , put_array , effect_array);
				set(8 , 0 , (((cur >> (SIZE -  9)) % 2) == 0) ? false : true , put_array , effect_array);
				set(7 , 0 , (((cur >> (SIZE -  8)) % 2) == 0) ? false : true , put_array , effect_array);
				set(6 , 0 , (((cur >> (SIZE -  7)) % 2) == 0) ? false : true , put_array , effect_array);
				set(5 , 0 , (((cur >> (SIZE -  6)) % 2) == 0) ? false : true , put_array , effect_array);
				set(4 , 0 , (((cur >> (SIZE -  5)) % 2) == 0) ? false : true , put_array , effect_array);
				set(3 , 0 , (((cur >> (SIZE -  4)) % 2) == 0) ? false : true , put_array , effect_array);
				set(2 , 0 , (((cur >> (SIZE -  3)) % 2) == 0) ? false : true , put_array , effect_array);
				set(1 , 0 , (((cur >> (SIZE -  2)) % 2) == 0) ? false : true , put_array , effect_array);
				set(0 , 0 , (((cur >> (SIZE -  1)) % 2) == 0) ? false : true , put_array , effect_array);
				
				for(int j = 1; j < SIZE; j++){
					for(int k = 0; k < SIZE; k++){
						if(array[j-1][k] != effect_array[j-1][k]){
							push(k, j, put_array, effect_array);
						}
					}
				}
				
				boolean is_correct = true;
				
				for(int j = 0; j < SIZE; j++){
					if(array[9][j] != effect_array[9][j]){
						is_correct = false;
						break;
					}
				}
				
				if(!is_correct){
					continue;
				}else{
					for(int j = 0; j < SIZE; j++){
						boolean is_first = true;
						for(int k = 0; k < SIZE; k++){
							if(!is_first){
								System.out.print(" ");
							}
							System.out.print(put_array[j][k] ? 1 : 0);
							if(is_first == true){
								is_first = false;
							}
						}
						System.out.println();
					}
					break;
				}
				
			}
			
		}
		
	}
	
}

Measured memory_bytes: 12000
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>

int main()
{
    std::cout << std::setprecision(16);
    int N;
    std::cin >> N;
    std::vector<int> x(N);
    std::vector<int> y(N);
    for (int i=0; i<N; ++i) {
        std::cin >> x[i] >> y[i];
    }
    long long count = 0L;
    double sum = 0.0;
    for (int i=0; i<N-1; ++i) {
        for (int j=i+1; j<N; ++j) {
            double dx = x[i] - x[j];
            double dy = y[i] - y[j];
            double dist = std::sqrt(dx*dx+dy*dy);
            count += 1;
            sum += dist;
        }
    }
    double mean = sum / count;
    double total = mean * (N - 1);
    std::cout << total << std::endl;

    return 0;
}

Measured memory_bytes: 256
#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;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

 
 
const ll N = 100005;
const ll mod = 1000000007;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   




void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);




int main(){
    
     
   ll a,b;
   cin>>a>>b;
   string s,t;
   rep(i,a) s.push_back(b+'0');
   rep(i,b) t.push_back(a+'0');
   if(s<t) cout<<s<<endl;
   else cout<<t<<endl;






   

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

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

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(int i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

const int M=22;
const ll INF=1e15;
const int MOD=1e9+7;

int n;
bool p[M][M];
ll dp[M][1<<M];

ll DP(int m,int c){
	ll &y=dp[m][c];
	if (m == n) return 1;
	if (y != -1) return y;
	y = 0;
	fp(i,0,n)
		if (p[m][i] && (c>>i)&1) y = (y + DP(m+1 , c & ( ~(1<<i) ))) % MOD;
	return y;
}

int main(){

	fastio;
	cin >> n;
	fp(i,0,n)
		fp(j,0,n) cin >> p[i][j];
	fp(i,0,n)
		fp(j,0,(1<<n)) dp[i][j] = -1;
	cout << DP(0,(1<<n)-1) << "\n";

	return 0;
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int ans = 0;
	rep (i, n) {
		if (i < k) ans += x;
		else ans += y;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String N = sc.next();
        char[]n = N.toCharArray();
        
        int num = 0;
        for(int i=0; i<3; i++){
            if(n[i]=='7'){
                num++;
            }
        }
            if(num>0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }         
	}
}

Measured memory_bytes: 35576
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>

using namespace std;

char change(char c)
{
	if ( isupper(c) ) {
		return tolower(c);
	} else if ( islower(c) ) {
		return toupper(c);
	} else {
		return c;
	}
}


int main() {

	string s;

	getline(cin, s);
	transform(s.begin(), s.end(), s.begin(), change);
	cout << s << endl;

	return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 8;
const ll MOD = 1e9 + 7;
const ll LLINF = 1e18;
#define Pint pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rnr(i,a,b) for(int i=int(a);i>=int(b);i--)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

bool isOk(vector<int> result, vector<int> material) {
    sort(all(result));
    sort(all(material));
    int j = 0;
    rep(i, material.size()) {
        if(material[i] == result[j]) {
            ++j;
        }
        if(j == result.size()) break;
    }
    return (j == result.size());
}

int main() {
    int n; cin >> n;
    vector<int> D(n);
    rep(i, n) cin >> D[i];
    int m; cin >> m;
    vector<int> T(m);
    rep(i, m) cin >> T[i];
    if(isOk(T, D)) {
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

int main() 
{
    FAST;
    string s;
    cin>>s;
    ll n=s.length();
    for(int i=0;i<n;i++)
        if(s[i]=='?')
            s[i]='D';
    cout<<s;
    subt;
    return 0;
}

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

int main(){
  string s; cin >> s;
  int cnt=0;
  for(int i=0; i<s.size()-1; i++){
    if(s[i]==s[i+1]) continue;
    cnt += 1;
  }
  cout << cnt << endl;

}


Measured memory_bytes: 512
from math import sqrt


def f(b, n, s):
    cnt = 0
    while n > 0:
        cnt += n % b
        n //= b
    return cnt == s


N = int(input())
S = int(input())
if S > N:
    print(-1)
    exit()
if S == N:
    print(N + 1)
    exit()

for b in range(2, int(sqrt(N)) + 1):
    if f(b, N, S):
        print(b)
        exit()

for p in range(int(sqrt(N)), 0, -1):
    if (N - S) % p == 0:
        b = (N - S) // p + 1
        q = N - p * b
        if b > p >= 0 and b > q >= 0 and p + q == S:
            print(b)
            exit()

print(-1)


Measured memory_bytes: 3064
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, h, w, ans = 3, now;
  scanf("%lld%lld", &h, &w);
  char s[h][w + 10];
  ll cnt[4][h][w];
  for(i = 0; i < h; ++i) scanf("%s", s[i]);
  for(i = 0; i < h; ++i) for(j = 0; j < w; ++j) {
    cnt[0][i][j] = cnt[1][i][j] = 1;
    if(s[i][j] == '#')  cnt[0][i][j] = cnt[1][i][j] = 0;
    else {
      if(i) cnt[0][i][j] = cnt[0][i - 1][j] + 1;
      if(j) cnt[1][i][j] = cnt[1][i][j - 1] + 1;
    }
  }
  for(i = h - 1; i >= 0; --i) for(j = w - 1; j >= 0; --j) {
    cnt[2][i][j] = cnt[3][i][j] = 1;
    if(s[i][j] == '#')  cnt[2][i][j] = cnt[3][i][j] = 0;
    else {
      if(i != h - 1) cnt[2][i][j] = cnt[2][i + 1][j] + 1;
      if(j != w - 1) cnt[3][i][j] = cnt[3][i][j + 1] + 1;
    }
  }
  for(i = 0; i < h; ++i) for(j = 0; j < w; ++j) {
    now = 0;
    for(k = 0; k < 4; ++k) now += cnt[k][i][j];
    if(ans < now) ans = now;
  }
  printf("%lld", ans - 3);
  return 0;
}

Measured memory_bytes: 129152
#include<bits/stdc++.h>
using namespace std;
int main(){
    char number;
    char kako='a';
    string ans="Good";
    for(int i=0; i<4; i++){
        cin >> number;
        if(number==kako) ans = "Bad";
        kako = number;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
N = gets_i

total = 0
max = 0
1.upto(N) do |n|
  total += n
  if total >= N
    max = n
    break
  end
end

diff = total - N
((1..max).to_a - [diff]).each do |i|
  puts i
end

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

int main() {
    int w, h;
    char c;
    cin >> w >> h >> c;
    
    rep(i, h) rep(j, w) {
        if (i == 0 || i == h-1) {
            if (j == 0) cout << '+';
            else if (j == w-1) cout << '+' << endl;
            else cout << '-';
        } else if (i == (h-1)/2) {
            if (j == 0) cout << '|';
            else if (j == w-1) cout << '|' << endl;
            else if (j == (w-1)/2) cout << c;
            else cout << '.';
        } else {
            if (j == 0) cout << '|';
            else if (j == w-1) cout << '|' << endl;
            else cout << '.';
        }
    }

    return 0;
}


Measured memory_bytes: 3116
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    l = I()
    l = list(map(int,bin(l)[2:]))
    n = len(l)
    ans = []
    for i in range(n-1):
        ans.append((i+1,i+2,0))
        ans.append((i+1,i+2,1<<i))
    w = (1<<(n-1))
    for i in range(1,n):
        if l[i]:
            x = n-i
            ans.append((x,n,w))
            w += (1<<(x-1))
    print(n,len(ans))
    for x,y,w in ans:
        print(x,y,w)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 39024
white = 0
HW = parse.(split(readline()))
H,W = HW[1], HW[2]
C = []
for i in 1:H
  s = chomp(readline())
  white += count(c -> c == '.', s)
  push!(C,s)
end 
start = [1,1]
goal = [H ,W]

dx = [1,-1,0,0]
dy = [0,0,1,-1]

que = []
push!(que,start)
dist = [[-1 for i in 1:W] for j in 1:H]
dist[start[1]][start[2]] = 0
while isempty(que) == false
  x,y = shift!(que)
  if [x,y] == goal
    break
  else
    for i in 1:4
      if 0 <x+dx[i] <=H && 0 <y+dy[i] <=W
        if C[x+dx[i]][y+dy[i]] != '#' && dist[x+dx[i]][y+dy[i]] == -1
          push!(que,[x+dx[i],y+dy[i]])
          dist[x+dx[i]][y+dy[i]] = dist[x][y]+1
        end
      end
    end
  end
end
ans =  dist[goal[1]][goal[2]]

if ans == -1
  print(-1)
else
  print(white - ans - 1)
end

Measured memory_bytes: 126916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A.at(i);
  vector<bool> num(pow(10, 9));
  rep(i, N){
    if(num.at(A.at(i))){
      cout << "NO" << endl;
      break;
    } else {
      num.at(A.at(i)) = true;
      if(i == N-1) cout << "YES" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 123136
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
a = list(map(int, input().split()))
b = []
multiple = [[i] for i in range(1,N+1)]
balls = [0] * N

for i in range(N,0,-1):
    if balls[i-1] % 2 != a[i-1]:
        for x in make_divisors(i):
            balls[x-1] += 1
        b.append(i)
print(len(b))
print(*b)

Measured memory_bytes: 87772
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[100005], b[100005];
int main(){
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    ll x=0;

    for(int i=1; i<=n; i++)
        a[i]+=a[i-1];
    for(int i=1; i<=n; i++)
        b[i] = a[i];
    ll ans=0, res=1e16;
    //pos
    for(int i=1; i<=n; i++){
        a[i]+=x;
        //cout<<x<<" ";
        if(i%2 && a[i]<=0){
            ans+=abs(a[i])+1;
            x+=abs(a[i])+1;
            a[i]=1;
        }
        else if(i%2==0 && a[i]>=0){
            ans+=a[i]+1;
            x-=(a[i]+1);
            a[i]=-1;
        }
    }
    res=ans;
    ans=0, x=0;
    for(int i=1; i<=n; i++){
        b[i]+=x;
        //cout<<x<<" ";
        if(i%2==0 && b[i]<=0){
            ans+=abs(b[i])+1;
            x+=abs(b[i])+1;
            b[i]=1;
        }
        else if(i%2 && b[i]>=0){
            ans+=b[i]+1;
            x-=(b[i]+1);
            b[i]=-1;
        }
    }
    res=min(res, ans);
    cout<<res;
    return 0;
}


Measured memory_bytes: 1792
sub f{
	for($i=0;++$i<@s;){
		$_[$i+1]=$_[$i-1]^$_[$i]^$s[$i]
	}
	if($_[0]==$_[-1]&&($_[-2]^$_[0]^$s[0])==$_[1]){
		pop;
		print+(map{$_?W:S}@_),$/
	}
}
<>;
@s=<>=~y/ox/01/r=~/./g;
f(0,0)||f(0,1)||f(1,0)||f(1,1)||print-1,$/


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

def main():
    H,W,h,w = map(int,input().split())
    if H*W-(H//h)*(W//w)*w*h == 0:
        print("No")
    else:
        if W%w != 0:
            ans = [0 for _ in range(W)]
            co = [0 for _ in range(W+1)]
            for i in range(1,w):
                co[i] = (W-i)//w+1
            for i in range(w,W+1):
                co[i] = co[i-w]-1
            for i in range(W):
               ans[i] = co[i+1]-co[i]
            print("Yes")
            for i in range(H):
                print(*ans)
        else:
            ans = [0 for _ in range(H)]
            co = [0 for _ in range(H+1)]
            for i in range(1,h):
                co[i] = (H-i)//h+1
            for i in range(h,H+1):
                co[i] = co[i-h]-1
            for i in range(H):
               ans[i] = co[i+1]-co[i]
            print("Yes")
            for i in range(H):
                print(*list(ans[i] for _ in range(W)))

if __name__ == "__main__":
    main()

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

int main() {
  string A,B,C;
  cin >> A >> B >> C;;
  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int x, t;

    cin >> x >> t;

    if (x - t >= 0) {
        cout << x - t;
    } else {
        cout << "0";
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a,b,k;
  cin >> a >> b >> k;
  bool t = true;
  for(int i=0;i<k;i++){
    if(t){
      if(a%2==1)
        a--;
      a /= 2;
      b += a;
      t = false;
    } else {
      if(b%2==1)
        b--;
      b /= 2;
      a += b;
      t = true;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256