akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    VI a(n+1);
    REP(i,n+1) a[i] = i;
    ll ans = 1;
    FOR(i,2,n){
        int x = 0;
        FOR(j,1,n){
            while (a[j] % i == 0){
                x++;
                a[j] /= i;
            }
        }
        ans = (ans * (x+1)) % MOD;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	string s;
	cin >> s;
	vector<int>a(s.length());
	vector<int>c(26,0);
	for (int i = 0; i < s.length(); i++) {
		a.at(i) = s.at(i) - 'a';
		c.at(a.at(i))++;
	}
	if (s.length() <= 25) {
		ll ans;
		for (int i = 0; i < 26; i++) {
			if (c.at(i) == 0) {
				ans = i;
				break;
			}
		}
		char c = 'a' + ans;
		cout << s << c << endl;
	}
	else {
		set<int>b;
		b.insert(a.at(s.length() - 1));
		a.at(s.length() - 1) = -1;
		for (int i = 1; i < 26; i++) {
			int d = a.at(s.length() - 1 - i);
			for (auto e : b) {
				if (e > d) {
					char f = 'a' + e;
					cout << s.substr(0,26-i-1) << f << endl;
					return 0;
				}
			}
			b.insert(d);
			a.at(s.length() - 1 - i) = -1;
		}
		cout << -1 << endl;
	}
}

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

#define F first
#define S second
#define pb push_back

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}



int dp[333][333];

int a[333][333];

bool used[333][333];

int main() {
	
    int n = readInt();
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= n; j++) {
    		cin >> a[i][j];
    		dp[i][j] = a[i][j];
    		if (i == j) {
    			dp[i][j] = MOD;
    		}
    		sum += a[i][j];
    	}
    }
    for (int k = 1; k <= n; k++) {
    	for (int i = 1; i <= n; i++) {
    		for (int j = 1; j <= n; j++) {
    		    if (i == j) continue;
    		    if (i == k) continue;
    		    if (k == j) continue;
    			dp[i][j] = min(dp[i][k] + dp[k][j], dp[i][j]);
    		} 
    	}
    }
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= n; j++) {
    		if (i == j) continue;
    		if (a[i][j] != dp[i][j]) {
    			cout << -1;
    			return 0;
    		}
    	}
    }

    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
            	if (i == j) continue;
                if (j == k) continue;
                if (i == k) continue;
    			if (!used[i][j] && a[i][j] == a[i][k] + a[k][j]) {
    				sum -= a[i][j];
    				used[i][j] = 1;
    			}
    		}
    	} 
    }
    cout << (sum>>1);
	return 0;
}

Measured memory_bytes: 1152
<?php
$stdin = explode(" ",fgets(STDIN));

$a = (int)$stdin[0];
$b = (int)$stdin[1];

$result = array();
$result[0] = $a + $b;
$result[1] = $a - $b;
$result[2] = $a * $b;
echo max($result);
?>


Measured memory_bytes: 4728
a,b,c = map(int, input().split())
original = [a,b,c]
flag = 0
i = 0
while a%2 == b%2 == c%2 == 0:
    a_ = (b+c)//2
    b_ = (c+a)//2
    c_ = (a+b)//2
    a = a_
    b = b_
    c = c_
    if [a,b,c] == original:
        flag = 1
        break
    i += 1
if flag:
    print(-1)
else:
    print(i)


Measured memory_bytes: 38256
S = input()
if len(set(S)) == 1:
  print(0)
  exit()

ans = float('inf')
for s in set(S):  
  ini_idx = S.find(s)
  tmp_ans = ini_idx
  prv_idx = ini_idx
  while 1:
    tmp_idx = S[prv_idx+1:].find(s)
    if tmp_idx == -1:
      break
    else:
      tmp_idx += prv_idx + 1
      tmp_ans = max(tmp_ans, tmp_idx - prv_idx - 1)
      prv_idx = tmp_idx
    
  tmp_ans = max(tmp_ans, len(S) - prv_idx - 1)
  ans = min(ans,tmp_ans)
print(ans)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<vector<pair<ll, ll>>> a(n);
    rep(i, n) {
        ll tmp;
        cin >> tmp;
        rep(j, tmp) {
            ll x, y;
            cin >> x >> y;
            x--;
            a[i].push_back(make_pair(x, y));
        }
    }
    ll ans = 0;
    rep(bit, 1 << n) {
        bool f = true;
        ll tmp = 0;
        rep(i, n) {
            if ((bit & (1 << i)) != 0) {
                rep(j, sz(a[i])) {
                    if (a[i][j].second == 1) {
                        if ((bit & (1 << a[i][j].first)) == 0) {
                            f = false;
                            break;
                        }
                    }
                    else {
                        if ((bit & (1 << a[i][j].first)) != 0) {
                            f = false;
                            break;
                        }
                    }
                }
                tmp++;
            }
        }
        if (!f) continue;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

template<class Istr>
vector<int> separated_str(Istr& istr, char delim){
    std::string str;
    vector<int> res;
    while(std::getline(istr, str, delim)){
        res.push_back(stoi(str));
    }
    return res;
}

signed main() {
    int M;
    while(cin >> M, M) {
        vector<int> ids, scores, ord;
        string s;
        cin.ignore();
        for(int i=0; i<M; i++) {
            getline(cin, s);
            stringstream ss(s);
            auto v = separated_str(ss, ' ');

            int id = v[0];
            int score = 0, pre1 = 0, pre2 = 0, t = 1, p = 0, f = 1;
            for(size_t k=1; k<v.size(); k++) {
                score += v[k];
                score += (pre1 + pre2) * v[k];

                pre1 = pre2;
                pre2 = 0;
                int pf = f, pt = t;
                if(t == 1 and v[k] == 10) {
                    if(f < 10) pre2++;
                    t = 1;
                    f++;
                }
                else if(t == 2 and p + v[k] == 10) {
                    if(f < 10) pre1++;
                    t = 1;
                    f++;
                }
                else {
                    t++;
                    if(f < 10 and t == 3) f++, t = 1;
                }
                p = v[k];
                // fprintf(stderr, "# f = %lld, t = %lld, %lld\n", pf, pt, score);
            }
            ids.push_back(id);
            scores.push_back(score);
            ord.push_back(i);
        }
        sort(ord.begin(), ord.end(), [&](int x, int y) {
                if(scores[x] != scores[y]) return scores[x] > scores[y];
                return ids[x] < ids[y];
            });

        for(int i=0; i<M; i++) {
            cout << ids[ ord[i] ] << " " << scores[ ord[i] ] << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3152
n,m=map(int,input().split())
link=[[] for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  link[a-1].append(b-1)
  link[b-1].append(a-1)
q=[0]
visited=[0]*n
visited[0]=1
while q:
  x=q.pop(0)
  for i in link[x]:
    if visited[i]==0:
      visited[i]=x+1
      q.append(i)
print('Yes')
print(*visited[1:],sep='\n')

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int func(long long n, std::vector<long long> a) {
    vll left(n + 1), right(n + 1);
    rep(i, n) {
        left[i + 1]  = gcd(a[i], left[i]);
        right[i + 1] = gcd(a[n - 1 - i], right[i]);
    }

    ll ans = 0;
    rep(i, n) { ans = max(ans, gcd(left[i], right[n - 1 - i])); }
    cout << ans << endl;

    return 0;
}

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

    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    func(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
parseInt(x) = parse(Int, x)

function main()
	n = readline() |> parseInt
	a = map(parseInt, split(readline()))
	ga = Array{Int}(n+1)
	ga[1] = 0
	la = Array{Int}(n+1)
	la[1] = 0
	for i in 1:n
		ga[i+1] = ga[i]+a[i]
		la[i+1] = la[i]+a[n-i+1]
	end
	sa = Array{Int}(n-1)
	for i in 1:n-1
		sa[i] = abs(ga[i+1]-la[n-i+1])
	end
	print(minimum(sa))
end

main()

Measured memory_bytes: 166052
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << "a > b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)

typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };

int dp[31][1 << 16];
int bitCount(int i) {
	i = i - ((i >> 1) & 0x55555555);
	i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
	i = (i + (i >> 4)) & 0x0f0f0f0f;
	i = i + (i >> 8);
	i = i + (i >> 16);
	return i & 0x3f;
}

int main(void)
{
	ios::sync_with_stdio(false);
	int n, c;
	while(cin >> n >> c && n)
	{
		memset(dp, -1, sizeof(dp));
		Array beats(n);
		Array pushes(c);
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < 16; j++)
			{
				beats[i] = (beats[i] << 1) | getInt();
			}
		}
		for (int i = 0; i < c; i++)
		{
			for (int j = 0; j < 16; j++)
			{
				pushes[i] = (pushes[i] << 1) | getInt();
			}
		}

		dp[0][0] = 0;
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < 1 << 16; j++)
			{
				if(dp[i][j] == -1) continue;

				int cb = j | beats[i];
				for (int k = 0; k < c; k++)
				{
					int num = bitCount(cb & pushes[k]);
					int nb = cb & ~pushes[k];
					dp[i + 1][nb] = max(dp[i + 1][nb], dp[i][j] + num);
					ans = max(dp[i + 1][nb], ans);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int sum_w = 0, sum_b = 0;
    rep(i,n) {
        if (s[i] == '#') sum_b++;
        else sum_w++;
    }
    int ct_w = 0, ct_b = 0;
    int ans = min(sum_w,sum_b);
    rep(i,n-1) {
        if (s[i] == '.') {ct_w++; sum_w--;}
        if (s[i] == '#') {ct_b++; sum_b--;}
        if (s[i] == '.' && s[i+1] == '#') {
            ans = min(ans,ct_b+sum_w);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3732
import math
a,b,x = map(int,input().split())
#a,b,x = 3,1,8
mass = (a**2) * b
space = float((a**2)*b - x)
if x >= (mass/2):
     tan_n = (2*space)/a**3
else:
     tan_n = (a*(b**2)) / (2 *x)

atan1 = float(math.degrees(math.atan(tan_n)))
print(atan1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int n,p,q,i,j,r,a,b=1,c=1,d=1,f[8]={};
int main(){
    scanf("%d",&n);
    for(i=n;i>0;i--)b*=i;
    for(i=0;i<n;i++){
        scanf("%d",&p);
        for(a=j=0;j<p;j++)a+=abs(f[j]-1);
        b/=n-i;
        c+=(a-1)*b;
        f[p-1]=1;
    }
    for(i=n;i>0;i--)b*=i;
    for(i=0;i<8;i++)f[i]=0;
    for(i=0;i<n;i++){
        scanf("%d",&p);
        for(a=j=0;j<p;j++)a+=abs(f[j]-1);
        b/=n-i;
        d+=(a-1)*b;
        f[p-1]=1;
    }
    printf("%d\n",abs(c-d));
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  __int128 t = A[0];
  for(int i = 1; i < N; ++i){
    if((__int128)1e18 < t*A[i]){
      cout << -1 << endl;
      return 0;
    }
    t *= A[i];
  }
  long long ans = t;
  cout << ans << endl;
}


Measured memory_bytes: 4048
n = gets.to_i
a = gets.split.map &:to_i
c1 = a.count{|i|i%2!=0 && i%4!=0}
c2 = a.any?{|i|i%2==0 && i%4!=0}
c4 = a.count{|i|i%4==0}
# p [c1,c2,c4]
if c2
	if c1 <= c4
		puts "Yes"
	else
		puts "No"
	end
else
	if c1 <= c4 + 1
		puts "Yes"
	else
		puts "No"
	end
end

Measured memory_bytes: 8452
def main():
    n, d = map(int, input().split())
    d *= d
    ans = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x ** 2 + y ** 2 <= d:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
template<class T>bool is_prime(T IN){
    if(IN<=1)return false;
    for(long long i=2;i*i<=IN;i++){
        if(IN%i==0){
            return false;
        }
    }
    return true;
}
bool check(ll t,ll i){
    if(i==1)return false;
    while(t%i==0)t/=i;
    return (t%i==1);
}
unordered_map<ll,ll> mp;
long long INF = 1LL<<60;
int main( ){
    ll x; cin>>x;
    ll res=0;
    for(ll i=1;i*i<=(x-1);i++){
        if((x-1)%i==0){
            ll a=(x-1)/i; ll b=i;
            if(a!=1&&!mp.count(a)){
                res++; mp[a]++;
            }
            if(a!=b&&b!=1&&!mp.count(b)){
                res++;mp[b]++;
            }
        }
    }
    for(ll i=1;i*i<=x;i++){
        //iともう一方のj以外の素因数を持たないこと.つまり，x==pow(i,n)*j
        if(!(x%i)){
        ll a=i,b=x/i;
        if(check(x,a)&&!mp.count(a)){res++;mp[a]++;}
        if(a!=b&&check(x,b)&&!mp.count(b)){res++;mp[b]++;}
        }
    }
    cout<<res<<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 per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int ans[110000];

struct Unionfind {
  vector<int> d;

  Unionfind(int n) : d(n,-1) {}

  int root(int x) {
    if(d[x] < 0) return x;
    return d[x] = root(d[x]);
  }

  bool unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if(rx==ry) return false;
    if(d[rx] < d[ry]) swap(rx,ry);
    d[rx] += d[ry];
    d[ry] = rx;
    return true;
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -d[root(x)];
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  Unionfind tree(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.unite(a,b);
    ans[a]--; ans[b]--;
  }
  rep(i,k) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    if(tree.root(c)==tree.root(d)) {
      ans[c]--; ans[d]--;
    }
  }
  rep(i,n) {
    int r = tree.root(i);
    ans[i] += (tree.size(r) - 1);
  }
  rep(i,n) {
    cout << ans[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
  }
  return 0;
}

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

int main()
{
    int a[3];
    while(cin >> a[0] >> a[1] >> a[2])
    {
        sort(a,a + 3);
        if(a[0] + a[1] == a[2])
        cout << "Yes" << endl;
        else
        cout << "No" << endl;
    }
    return 0;
}


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

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0) v += MOD; }

  Mint operator-() { return Mint(-v); };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0) return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

const int SIZE = 11234567;
mint fact(int n) {
  static vector<mint> factorial = []() {
    vector<mint> _f(SIZE, 1);
    for(int i=1; i<SIZE; i++) _f[i] = _f[i-1] * i;
    return _f;
  }();
  return factorial[n];
}
mint perm(int n, int k) { return n<k ? 0 : fact(n) / fact(n-k); }
mint comb(int n, int k) { return n<k ? 0 : perm(n, k) / fact(k); }

int main() {
  lint N, K;
  cin >> N >> K;
  vector<lint> A(N);
  for(auto& elem : A) cin >> elem;
  sort(A.begin(), A.end());

  mint ans = 0;
  for(lint i=0; i<N; i++) {
    ans += comb(i,K-1) * A[i];
    ans -= comb(N-i-1,K-1) * A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 91696
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>
using namespace std;

int main() {
    long long MOD = 1000000007;
    long long H, W, K;
    long long num[101][10];
    long long hor_f[10];

    scanf("%lld %lld %lld", &H, &W, &K);

    hor_f[0] = 1; hor_f[1] = 1;
    for(int i=2;i<10;i++){
        hor_f[i] = hor_f[i-1] + hor_f[i-2];
    }

    num[0][1] = 1;
    for(int i=2;i<W+1;i++){
        num[0][i] = 0;
    }

    for(int h=1;h<=H;h++){
        num[h][1] = (hor_f[W-1] * num[h-1][1] + hor_f[W-2] * num[h-1][2]) % MOD;
        num[h][W] = (hor_f[W-2] * num[h-1][W-1] + hor_f[W-1] * num[h-1][W]) % MOD;
        for(int a=2;a<W; a++){
            num[h][a] = (hor_f[a-2] * hor_f[W-a] * num[h-1][a-1] + hor_f[a-1] * hor_f[W-a] * num[h-1][a] + hor_f[a-1] * hor_f[W-a-1] * num[h-1][a+1]) % MOD;
        }
    }

    printf("%lld\n", num[H][K]);

}


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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;

int N, W;
int v[110], w[110];
int dp[110][10010];
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> N >> W;
	rep(i, N) {
		cin >> v[i] >> w[i];
	}
	rep(i, N) {
		rep(j, W + 1) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			if (j - w[i] >= 0) {
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 7104
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
bool comp(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int a, b;
	cin >> a >> b;
	if ( ((2 * b) - 1) <= a) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

//#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<"\n";//cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const ld pi=acos(-1);
//const int inf=1e18,M=1e9+7;
//const int N=1;

int n;
set<string> ans;

void func(string str,char x)
{
    if(str.length()==n)
    {
        ans.ins(str);
        return;
    }

    char tmp,mx;

    for(int j=0;j<=x+1-'a';++j)
    {
        tmp=j+'a';
        if('a'<=tmp && tmp<='z')
        {
            mx=max(x,tmp);
            func(str+tmp,mx);
        }
    }
}

void solve()
{
    cin>>n;

    func("a",'a');

    show(ans);
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 12416
from bisect import bisect_right

N = int(input())
S = input()

d = [[0] * N for _ in range(3)]
for i in range(3):
    for j in range(N):
        d[i][j] = int(S[j] == "RGB"[i])
        
cumsum = [[0] * (N + 1) for _ in range(3)]
for i in range(3):
    for j in range(N):
        cumsum[i][j + 1] = cumsum[i][j] + d[i][j]

cnt = [len(v) for v in d]
ans = 0
for i in range(1, N - 1):
    for j in range(i + 1, N):
        
        if S[i - 1] == S[j - 1]:
            continue

        # Find `k` string and index
        s = (set("RGB") - set([S[i - 1], S[j - 1]])).pop()
        idx = "RGB".find(s)
        ans += cumsum[idx][-1] - cumsum[idx][j]
        
        k = 2 * j - i
        if k <= N and d[idx][k - 1]:
            ans -= 1
        
print(ans)


Measured memory_bytes: 69080
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U;typedef long long ll;typedef pair<int,int > P;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int ttt;scanf("%d",&ttt);for(int i=1;i<=ttt;i++)
	inp();
	return 0;
}
const int N = 1e5 + 100;
P P1[N],P2[N];
#define A first
#define B second
bool getI( P &a, P &b, P &ans){
	int x, y;
	x = max(a.A, b.A);
	y = min(a.B, b.B);
	if( x < y ){
		ans.A = x,ans.B = y;
		return true;
	}
	return false;
}
void pP( P * arr, int n ){
	printf("vvv\n");
	for(int i =0;i<n;i++){
		printf("%d %d\n", arr[i].A, arr[i].B);
	}
	printf("^^^\n");
}
void inp(){
	int n,m; scanf("%d%d",&n,&m);
	int bkm = m;
	P * p1 = P1, *p2 = P2;
	for(int i =0 ;i<m;i++){
		scanf("%d%d",&p1[i].A, &p1[i].B);
	}
	int next_m = 0;
	P ans;
	int flag = true;
	//while(flag){
		flag = false;
		sort(p1, p1+m);
		P cur = p1[0];
		next_m = 0;
		for(int i = 1;i<m;i++){
			if( getI(cur, p1[i], ans ) ){
				cur = ans;
				flag = true;
			}
			else {
				p2[next_m++] = cur;
				cur = p1[i];
			}
		}
		p2[next_m++] = cur;
		swap(next_m, m);
		swap(p1, p2);
		//pP(p1, m);
	//}
	printf("%d",  m );
}
//d.cc by xsthunder at Wed Jul 25 23:18:28 2018

//AC at Wed Jul 25 23:35:41 2018
 

Measured memory_bytes: 1664
/*
======================
[     ___T_          ]
[    | 6=6 | =>HI :-)] 
[    |__o__|         ]
[ >===]__o[===<      ]
[     [o__]          ]
[      .".           ]
[      |_|           ]
[                    ]
======================
 */

#include<bits/stdc++.h>
using namespace std;
using lli = int64_t;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int T = 1;
	for(int t = 1; t <= T; t++){
		int n;
		string s;
		cin >> n >> s;
		int red = 0,white = 0;
		for(int i = 0;i < n; i++){
			red += (s[i] == 'R');
		}
		for(int i = 0; i < red; i++){
			white += (s[i] == 'W');
		}
		cout << white << "\n";
	}
}



Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
from collections import deque

def bfs(u):
    dist = [-1 for _ in range(n)]
    dist[u] = 0
    que = deque([])
    que.append(u)
    
    while que:
        v = que.popleft()
        for nv in G[v]:
            if dist[nv] != -1:
                continue
            dist[nv] = dist[v] + 1
            que.append(nv)

    for d in dist:
        if d == 0:
            continue
        ans[d-1] += 1
    return ans


n, x, y = map(int,input().split())
G = [[] for _ in range(n)]
for i in range(n-1):
    G[i].append(i+1)
    G[i+1].append(i)
G[x-1].append(y-1)
G[y-1].append(x-1)

ans = [0]*(n-1)
for i in range(n):
    bfs(i)

for i in ans:
    print(i//2)

Measured memory_bytes: 47964
def main():
    S = input()
    y, m, d = list(map(int, S.split('/')))
    if y < 2019:
        print('Heisei')
        return 0
    elif y == 2019:
        if m <= 4:
            print('Heisei')
        else:
            print('TBD')
    else:
        print('TBD')

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define pi 3.141592653589793238

ll find(vector<ll> &v, ll a, ll b, ll c){
    if(b < a+c) return 1;
    else return 0;
}

void solve(){
    ll n, k, m = 1e9+7;;
    cin >> n >> k;
    ll sum = 0;
    for(ll i = k;i <= n+1;i++){//cout << i << ";\n";
        ll mini = 0, maxi = 0;
        mini = (i*(2*0 + (i-1)))/2;
        maxi = (i*(2*n - (i-1)))/2;
        ll d = (maxi - mini + 1)%m;////cout << d <<endl;
        sum = (sum+d)%m;////cout << sum << endl;
    }
    cout << sum << endl;
}


int main() {
    //int t; cin >> t; while(t--)
    solve();
    
	return 0;
}


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

using namespace std;
typedef long long ll;


int main()
{
    string s;
    cin >> s;
    int K;
    cin >> K;
    int n = int(s.length());
    
    rep(i,n){
        int aa = s[i]-'a';
        
        if(26-aa <= K && s[i]!='a'){
            s[i] = 'a';
            K-=(26-aa);
        }
        if(K == 0) break;
        if(i == n-1){
            K %= 26;
            s[i] = char(s[i]+K);
            K = 0;
        }
    }
    
    cout << s << endl;
    
    
    
    return 0;
}



Measured memory_bytes: 512
import heapq

n = int(input())
alist = list(map(int, input().split()))

ad = {}
for i, a in enumerate(alist):
  ad[a] = i

h = []
right = [n-1] * n

for i in range(n):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    right[ad[v]] = i - 1
  heapq.heappush(h, -alist[i])

h = []
left = [0] * n

for i in reversed(range(n)):
  while h and -h[0] > alist[i]:
    v = -heapq.heappop(h)
    left[ad[v]] = i + 1
  heapq.heappush(h, -alist[i])

ans = 0
for i in range(n):
  ans += alist[i] * (i - left[i] + 1) * (right[i] - i + 1)

print(ans)


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

int main() {
	int n, k; cin >> n >> k;
	vector<int>x(n); for (auto&& i : x)cin >> i;

	vector<int>cnt;
	for (int i = 0; i <= n - k; i++) {
		int xl = x[i];
		int xr = x[i + k - 1];
		int time1 = abs(xl) + abs(xr - xl);
		int time2 = abs(xr) + abs(xr - xl);
		cnt.push_back(min(time1, time2));
	}
	sort(cnt.begin(), cnt.end());
	cout << cnt[0] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;

int main() {
	double a,b,c,pi=3.1415926535897932;
	cin>>a>>b>>c;
	cout<<fixed<<setprecision(5)<<a*b*sin(c*pi/180.0)/2<<endl<<a+b+sqrt(a*a+b*b-2.0*a*b*cos(c*pi/180.0))<<endl<<b*sin(c*pi/180.0)<<endl;
	return 0;
}

Measured memory_bytes: 3476
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main() {
	double a,b,c,d;
    bool t=false;
    scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
    if(c==a/2&&d==b/2){
    	t=true;
	}
    double s;
    s=a*b/2;
    if(t){
    	printf("%.6f 1",s);
	}else{
		printf("%.6f 0",s);
	}
	return 0;
}

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

__asm__ (
	"asm_my_gcd2_in:"
	"movl $0, %edx;"
	"divl %ecx;"
	"cmpl $0, %edx;"
	"jz asm_my_gcd2_in2;"
	"asm_my_gcd2_in1:"
	"movl %ecx, %eax;"
	"movl %edx, %ecx;"
	"movl $0, %edx;"
	"divl %ecx;"
	"cmpl $0, %edx;"
	"jnz asm_my_gcd2_in1;"
	"asm_my_gcd2_in2:"
	"ret;"
);

inline int gcd(uint32_t a, uint32_t b){
	if(a==0 || b==0) return a==0?b:a;
	uint32_t ans;
	__asm__ (
	"movl %1, %%ecx;"
	"movl %2, %%eax;"
	"call asm_my_gcd2_in;"
	"movl %%ecx, %0;"
		:"=r"(ans)
		:"r"(a),"r"(b)
		:"%eax", "%ecx", "%edx", "cc"
		);
	return ans;
}

uint32_t nextpint(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
int a[100001];
int l[100002], r[100002];
int main(void){
	int n=nextpint();
	for(int i=1; i<=n; i++){
		a[i]=nextpint();
	}
	l[0]=0;
	for(int i=1; i<=n; i++){
		l[i] = gcd(l[i-1], a[i]);
	}
	r[n+1]=0;
	for(int i=n; i>0; i--){
		r[i] = gcd(r[i+1], a[i]);
	}
	int max=0;
	for(int i=1; i<=n; i++){
		int now=gcd(l[i-1], r[i+1]);
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    set<int>s;
    int y;
    for (int i=0;i<x;i++){
        cin>>y;
        s.insert(y);
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<i64>();
    let (a, b) = (line[0], line[1]);

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,k=0;
    cin>>a>>b;
    int c[a],d[b][2],e[a];
    for(int i=0;i<a;i++)cin>>c[i],e[i]=1;
    for(int i=0;i<b;i++){
        cin>>d[i][0]>>d[i][1];
        if(c[d[i][0]-1]<c[d[i][1]-1]){
            e[d[i][0]-1]=0;
        }
        else if(c[d[i][0]-1]>c[d[i][1]-1]){
            e[d[i][1]-1]=0;
        }
        else if(c[d[i][0]-1]==c[d[i][1]-1]){
            e[d[i][0]-1]=0;
            e[d[i][1]-1]=0;
        }
    }
    for(int i=0;i<a;i++){
        if(e[i]==1){
            k++;
        }
    }
    cout<<k;
}


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

int64_t f(int64_t A, int64_t B) {
    return A * A * A * A + A * A * A * B + A * A * B * B + A * B * B * B + B * B * B * B;
}

pair<bool, int64_t> ok(int64_t i, int64_t t) {
    //A = B + iのとき、A^4 + ... + B^4がtになるようなBが存在するかどうか判定
    for (int64_t B = -1000; B <= 1000; B++) {
        int64_t v = f(B + i, B);
        if (v == t) {
            return { true, B };
        }
    }

    return { false, -1 };
}

int main() {
    int64_t X;
    cin >> X;
    for (int64_t i = 1; i * i <= X; i++) {
        if (X % i != 0) {
            continue;
        }

        //A = B + iの場合
        auto result1 = ok(i, X / i);
        if (result1.first) {
            cout << result1.second + i << " " << result1.second << endl;
            return 0;
        }

        //A = B + X / iの場合
        auto result2 = ok(X / i, i);
        if (result2.first) {
            cout << result2.second + X / i << " " << result2.second << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

typedef long long ll;
const int maxn = 200200;

void solve()
{
    string s,t,u;
    int a,b;
    cin >> s;
    for (char x : s) cout << 'x';
    cout << endl;
}


int main()
{
    int t;
    solve();
    return (0);
}





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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll k;
  cin >> k;

  queue<ll> q;
  for (ll i = 1; i < 10; ++i) {
    q.push(i);
  }

  ll i = 0;
  while (!q.empty()) {
    auto v = q.front();
    q.pop();
    
    i++;
    if (i == k) {
      cout << v << endl;
      return 0;
    }

    auto next = v % 10;
    for (ll j = next-1; j <= next+1; ++j) {
      if (j < 0 || j >= 10) continue;
      q.push(v*10 + j);
    }
  }

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include<bitset>

using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
long long INF = 1e10;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007

int main() {
	int n; cin >> n;
	vector<string> S,T;
	for (int i = 0; i < n; i++)
	{
		string c; cin >> c;
		S.push_back(c);
		T.push_back(c);
	}
	sort(all(S));
	for (int i = 0; i < n-1; i++)
	{
		if (S[i] == S[i + 1]) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = 0; i < n-1; i++)
	{
		if (T[i].back() != T[i + 1].front()) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 
const vi ny={0,1,0,-1};
const vi nx={1,0,-1,0};

signed main(){
	int n,m; cin>>n>>m;
	vector<vector<char>> vec(n,vector<char>(m));
	int cnt=0;
	rep(i,0,n){
		rep(j,0,m){
			char c; cin>>c;
			if(c=='#') cnt++;
			vec[i][j]=c;
		}
	}
	queue<pi> q;
	q.push(pi(0,0));
	vvi bfs(n,vi(m));
	vector<vector<bool>> seen(n,vector<bool>(m));
	seen[0][0]=true;
	bfs[0][0]=1;
	while(!q.empty()){
		pi p=q.front(); q.pop();
		int a=p.first;
		int b=p.second;
		rep(i,0,4){
			int y=a+ny[i];
			int x=b+nx[i];
			if(y<0 || y>=n) continue;
			if(x<0 || x>=m) continue;
			if(vec[y][x]=='#') continue;
			if(seen[y][x]) continue;
			seen[y][x]=true;
			bfs[y][x]=bfs[a][b]+1;
			q.push(pi(y,x));
		}
	}
	if(!seen[n-1][m-1]){
		cout<<-1;
		return 0;
	}
	int ans=(n*m)-cnt-bfs[n-1][m-1];
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()
#define endll "\n"

#define fin             freopen("input.txt","r",stdin);
#define fout            freopen("output.txt","w",stdout);


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n,x,t;
    cin >> n >> x >> t;
    cout << (ll)ceil((double)n/x)*t << endl;

    return 0;
}



Measured memory_bytes: 3756
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <cmath>
# include <functional>
# include <utility>
# define MOD 1000000000+7
# define INF 2000000000
#define rep(i,rept)	for(int i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
int main() {
	//new
	int x, y;
	string str;
	cin >> x>>str;
	if (x % 2 == 1) {
		cout << "No" << endl;
}
	else {
		if (str.substr(0, x / 2) == str.substr(x / 2, x / 2)) {
			cout<<"Yes"<<endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}



Measured memory_bytes: 256
#include <iostream>
#define endl '\n'
using namespace std;

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

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

    return 0;
}



Measured memory_bytes: 3636
n,l=map(int,input().split())
if l>0 and (l+n-1)>0:
    print(((l+1)+(l+n-1))*(n-1)//2)
elif l>0 and (l+n-1)<=0:
    print(((l+l+n-1)*(n))//2)
elif l<=0 and l+n-1>0:
    print(((l+l+n-1)*(n))//2)
else:
    print(((l)+(l+n-2))*(n-1)//2)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];
ll S[101010];
ll mo=1000000007;

const int NUM_=400001;
ll fact[NUM_+1],inv[NUM_+1];
ll invsum[NUM_+1];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	inv[1]=fact[0]=invsum[1]=1;
	for (int i=2;i<=NUM_;++i) {
		inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		(invsum[i] = invsum[i-1] + inv[i])%=mo;
	}
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo;
	
	cin>>N;
	ll ret=0;
	FOR(i,N) {
		cin>>A[i];
		(ret+=(invsum[i+1]+invsum[N-i]-1)*A[i])%=mo;
	}
	
	cout<<ret*fact[N]%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10880
N, M = map(int, input().split())

graph = [[] for _ in range(N+1)]
for i in range(M):
  X, Y, Z = map(int, input().split())
  graph[X].append(Y)
  graph[Y].append(X)

answer = 0
stack = []
seen = [0] * (N+1)

for i in range(1, N+1):
  if seen[i] == 0:
    answer += 1
    seen[i] = 1
    if len(graph[i]):
      stack.append(i)
      while stack:
        s = stack.pop()
        for g in graph[s]:
          if seen[g] == 0:
            stack.append(g)
            seen[g] = 1
print(answer)

Measured memory_bytes: 69536
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
 
using namespace std;
 
struct Node {
    int key;
    Node *right, *left, *parent;
};
 
Node *root, *NIL;
 
Node * find(Node *u, int k) {
    while(u != NIL && k != u->key) {
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}
 
void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
     
    z = (Node *)malloc(sizeof(Node));
    z->key   = k;
    z->left  = NIL;
    z->right = NIL;
     
    while(x != NIL) {
        y = x;
        if(z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
     
    z->parent = y;
    if(y == NIL) {
        root = z;
    } else {
        if( z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}
 
void inorder(Node *u) {
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u) {
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
     
int main(void) {
    int n, i, x;
    string com;
    scanf("%d",&n);
     
    for(i=0;i<n;i++) {
        cin >> com;
        if(com[0] == 'f') {
            scanf("%d",&x);
            Node *t = find(root,x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        } else if(com == "insert") {
            scanf("%d",&x);
            insert(x);
        } else if(com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
 
    return 0;
}


Measured memory_bytes: 22016
N,M=map(int,input().split())
ab=[list(map(lambda x:int(x)-1,input().split())) for i in range(M)]
x=[0]*(N-1)
for i in range(M):
    if x[ab[i][0]]>ab[i][1] or x[ab[i][0]]==0:
        x[ab[i][0]]=ab[i][1]
flag=0
a=N
cnt=0

for i in range(N-1):
    if flag==0 and x[i]==0:
        continue
    elif flag==0 and x[i]>0:
        flag=1
        a=x[i]
        cnt+=1
    elif i<a:
        if x[i]<a and x[i]!=0:
            a=x[i]
    else:
        if x[i]>0:
            a=x[i]
            cnt+=1
        else:
            flag=0
            a=N
print(cnt)

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    while(N > 0){
        N /= K;
        ans++;
    }

    cout << ans << endl;

}



Measured memory_bytes: 256