akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using ll = long long;
using std::cout;
using std::cin;
using std::endl;
int main(){
    int a;
    cin >> a;
    a %= 10;
    if(a==3){
        cout << "bon" << endl;
    }else if(a==0 || a==1 || a==6 || a==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}

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

vector<long long> divi(long long n)
{
    vector<long long> ret;
    for(long long i = 1; i*i <= n; i++)
    {
        if(n % i == 0)
        {
            ret.push_back(i);
            if(i*i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main()
{
    long long N;
    cin >> N;
    vector<long long> v = divi(N);
    long long minv = 10e13;
    long long t1 = 0;
    long long t2 = 0;
    for(long long i = 0; i < v.size(); i++)
    {
        if(N % v[i] == 0)
        {
            long long a = N / v[i];
            if(minv > abs(v[i]-a))
            {
                minv = abs(v[i]-a);
                t1 = a;
                t2 = v[i];
            }
        }
    }
    //
    long long ans = (t1-1) + (t2-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

constexpr cat mod = 1000000007;

constexpr int MX = 700000;
cat fac[MX], inv[MX];

cat pw(cat a, cat e) {
	if(e <= 0) return 1;
	cat x = pw(a, e/2);
	return e&1 ? (x * x % mod * a) % mod : (x * x % mod);
}

cat C(int N, int K) {
	if(K < 0 || N < 0 || K > N) return 0;
	return fac[N] * inv[K] % mod * inv[N-K] % mod;
}

cat solve(int N, int M, int R) {
	cat cnt_total = C(R+N, N);
	cat cnt = 0;
	for(int K = 0; K <= N-M; K++) {
		cat sum = 0;
		for(int X = 1; X <= R/(M+K)+1; X++)
			sum += C(R-M*X-K*X+N, N) - C(R-M*X-K*(X-1)+N, N);
		cnt = (cnt + sum % mod * (K&1 ? -1 : 1) * C(N-M, K)) % mod;
	}
	return (cnt_total - cnt * C(N, M)) % mod;
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	fac[0] = inv[0] = 1;
	for(int i = 1; i < MX; i++) fac[i] = i * fac[i-1] % mod;
	for(int i = 1; i < MX; i++) inv[i] = pw(i, mod-2) * inv[i-1] % mod;
	int N, M, L, R;
	cin >> N >> M >> L >> R;
	cat ans = solve(N, M, R) - solve(N, M, L-1);
	ans %= mod;
	if(ans < 0) ans += mod;
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


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

typedef long long ll;
const ll MOD = 1e9+7;
const int N =2e5+5;

int dp[N][3],n;
string s;

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

    n=s.length();
    s="#"+s;

    dp[1][1]=1;
    for(int i=2;i<=n;i++){
        dp[i][1]=dp[i-1][2]+1;
        if(s[i]!=s[i-1])dp[i][1]=max(dp[i][1],dp[i-1][1]+1);

        dp[i][2]=dp[i-2][1]+1;
        if(i>=4&&s[i]!=s[i-2]||s[i-1]!=s[i-3])dp[i][2]=max(dp[i][2],dp[i-2][2]+1);
    }

    cout<<max(dp[n][1],dp[n][2]);
    return 0;
}


Measured memory_bytes: 2896
n=int(input())
s=input()
inf=float("inf")
A=[[inf]*10 for _ in range(n+1)]
for i in reversed(range(n)):
  ss=s[i]
  for j in range(10):
    if j==int(ss):
      A[i][j]=i
    else:
      A[i][j]=A[i+1][j]
ans=0
for x in range(1000):
  x=str(x).zfill(3)
  cur=0
  for xx in x:
    xx=int(xx)
    cur=A[cur][xx]+1
    if cur==inf:
      break
  if cur!=inf:
    ans+=1
print(ans)




Measured memory_bytes: 52444
#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() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), last(n);
	
	// 貪欲
	ll ans = 0;
	rep(i, d) {
		ll mx = -1001001001;
		int now = 0;
		
		rep(j, n) {
			ll tmp = ans;
			tmp += s[i][j];
			rep(k, n) {
				if(j == k) continue;
				tmp -= c[k] * (i+1-last[k]);
			}
			if(mx < tmp) {
				mx = tmp;
				now = j;
			}
		}
		ans = mx;
		last[now] = i+1;
		t[i] = now+1;
	}
	int cnt = 0;
	while(1) {
		// 局所探索法
		cnt++;
		if(cnt > 200000) break;
		vector<int> old = t;
		const int CH = 30; // 10箇所変える
		rep(i, CH) {
			int nd = rand()%d;
			int nq = rand()%n + 1;
			t[nd] = nq;	
		}
		
		// 点数のシミュレーション
		vector<int> nlast(n);
		ll now = 0;
		rep(i, d) {
			now += s[i][t[i]];
			nlast[t[i]-1] = i+1;
			rep(j, n) {
				now -= c[j] * (i+1-nlast[j-1]);
			}
		}
		
		// 良くなれば更新
		if(now > ans) {
			ans = now;
		} else {
			t = old;
		}
	}
	
	rep(i, d) printf("%d\n", t[i]);
	return 0;
}

Measured memory_bytes: 3776
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;

/// Info.
///****************************************************************************************************************************************///
/// author                : BAHAA El-DEEN OSAMA .
/// Problem name          : I - Tsundoku
/// Method                : brute force
/// Online judge          : vjudge(Contest)
/// Date                  : 8/6/2020
///****************************************************************************************************************************************///
#define ll   long long


int main()
{

    ll m,n,k;
	cin >> n >> m >> k;
	vector<ll> a(n);
	vector<ll> b(m);
	for(int i = 0; i<n; i++){
		cin >> a[i];
	}
	for(int i = 0; i<m; i++){
		cin >> b[i];
	}
	vector<ll> sumA(n+1);
	vector<ll> sumB(m+1);
	for(int i = 0; i<n; i++){
		sumA[i+1] = sumA[i] + a[i];
	}
	for(int i = 0; i<m; i++){
		sumB[i+1] = sumB[i] + b[i];
	}
	int total = 0;
	for(int i = 0; i<= n;i++){
		ll other = k-sumA[i];
		if(other < 0){
			continue;
		}
		int l = lower_bound(sumB.begin(), sumB.end(), other)-sumB.begin();
		if(l>m||sumB[l]>other){
			--l;
		}
		total = max(total, i+l);
	}
	cout << total;

 return 0;
}


Measured memory_bytes: 9556
#include <bits/stdc++.h>
using namespace std;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vb   = vector<bool>;
using vvb  = vector<vb>;
using pii  = pair<int,int>;
using vpii = vector<pii>;

int main() {
    int D, T, S; cin >> D >> T >> S;
    if (D > T*S) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3668
package main

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

func main() {
	scanner := NewScanner()
	x := scanner.NextInt64()
	max := 10 * 10 * 10
	m := make(map[int64]int64)
	for i := 0; i <= max; i++ {
		j := int64(i)
		k := j * j * j * j * j
		m[k] = j
	}
	for k, a := range m {
		d := k - x
		if d >= 0 {
			b, ok := m[d]
			if ok {
				fmt.Printf("%v %v\n", a, b)
				return
			}
		} else {
			b, ok := m[-d]
			if ok {
				fmt.Printf("%v %v\n", a, -b)
				return
			}
		}
	}
}

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &Scanner{s}
}

func (s *Scanner) NextWord() string {
	if !s.scanner.Scan() {
		log.Fatal("failed to find the next word")
	}
	return s.scanner.Text()
}

func (s *Scanner) NextInt() int {
	str := s.NextWord()
	i, err := strconv.Atoi(str)
	if err != nil {
		log.Fatalf("failed to parse %s to int", str)
	}
	return i
}

func (s *Scanner) NextInt64() int64 {
	str := s.NextWord()
	i, err := strconv.ParseInt(str, 10, 64)
	if err != nil {
		log.Fatalf("failed to parse %s to int64", str)
	}
	return i
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
const ll MOD = 1e9+7;

#define pll pair<ll,ll>

int U[2000][2000];
int D[2000][2000];
int L[2000][2000];
int R[2000][2000];

int main(){
    int H,W; cin>>H>>W;
    string board[H]; CINA(board,H);
    
    REP(i,H){
        REP(j,W){
            if(board[i][j]=='.'){
                if(j-1>=0){ L[i][j] = L[i][j-1]+1;}
                else{ L[i][j] = 1;}
            }else{
                L[i][j] = 0;
            }
        }
    }
    REP(i,H){
        REPR(j,W-1){
            if(board[i][j]=='.'){
                if(j+1<W){ R[i][j] = R[i][j+1]+1;}
                else{ R[i][j] = 1;}
            }else{
                R[i][j] = 0;
            }
        }
    }

    REP(j,W){
        REP(i,H){
            if(board[i][j]=='.'){
                if(i-1>=0){ U[i][j] = U[i-1][j]+1;}
                else{ U[i][j] = 1;}
            }else{
                U[i][j] = 0;
            }
        }
    }
    
    REP(j,W){
        REPR(i,H-1){
            if(board[i][j]=='.'){
                if(i<H-1){ D[i][j] = D[i+1][j]+1;}
                else{ D[i][j] = 1;}
            }else{
                D[i][j] = 0;
            }
        }
    }
    
    int ans = 0;
    int MAX = H+W-1;
    REP(i,H){
        REP(j,W){
            chmax(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3);
            if(ans==MAX){ break;}
        }
        if(ans==MAX){ break;}
    }
    

    cout << ans << "\n";
}


Measured memory_bytes: 66816
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, m, w, ans = 0, count = 0;
  string s, t;
  cin >> n >> m;
  vector<vlli> d(n);
  rep(i, 0, n)
  {
    cin >> k;
    // cout << "k:" << k << endl;
    repe(j, 1, k)
    {
      cin >> a;
      d[i].pb(a);
      // cout << "a:" << a << endl;
    }
  }
  repe(j, 1, m)
  {
    rep(i, 0, n)
    {
      auto found_itr = find(d[i].begin(), d[i].end(), j);
      bool found = (found_itr != d[i].end());
      if (found)
      {
        count++;
      }
      // cout << "count: " << count << endl;
    }
    if (count == n)
    {
      ans++;
    }
    count = 0;
  }
  cout << ans << endl;
  // cout << d << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<unordered_set>
using namespace std;
const int MAX = 3300;


int main() {
	int A, B, C, D, E, F;
	bool table[MAX][MAX] = { false };
	
	int sugar = 0;
	int water = 0;
	double max = -1;

	cin >> A >> B >> C >> D >> E >> F;

	table[0][0] = true;
	for (int i = 0; i * 100 < F; i++) {
		for (int j = 0; j < F; j++) {
			if (table[i][j]) {
				table[i + A][j] = true;
				table[i + B][j] = true;
				table[i][j + C] = true;
				table[i][j + D] = true;

				if (i * 100 + j > F)continue;
				if (j > i * E)continue;
				if (i == 0 && j == 0)continue;

				double n = 100 * j / double(i * 100 + j);
				if (n > max) {
					max = n;
					water = i * 100;
					sugar = j;
				}
			}
		}
	}

	cout << water + sugar << " " << sugar << endl;

	return 0;
}

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

#define lint long long

const int N = 2000 + 2 ;
int a[N] ;
const int MOD = 1e9 + 7 ;



int main()
{
    lint n, k ; cin >> n >> k ;
    for(int i = 0; i < n; i++) cin>> a[i];
    lint cnt = 0 ;
    lint sub = (k*(k-1))/2 ; sub %= MOD ;
    for(int i = 0; i < n; i++)
    {

        lint after = 0 ;
        for(int j = i+1 ; j < n; j++) if (a[i] > a[j]) after++ ;
        lint total = 0 ;
        for(int j = 0; j < i; j++) if(a[i] > a[j]) total++ ;
        total += after ;

        lint now = total * sub ; now %= MOD ;
        lint now2 = after * k ; now2 %= MOD ;
        cnt += (now % MOD + now2 % MOD) % MOD ; cnt %= MOD ;
        /*
        for(int l = k-1; l >= 0; l--)
        {
            lint now = after + ( ( total * l ) % MOD ) ; now %= MOD ;
            cnt += now ; cnt %= MOD ;
        }
        */
    }
    cout << cnt ;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int ans=0;
  for(int i=0;i<4;i++){
  	char c;cin>>c;
    if(c=='2')ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val line = readLine()!!.split(" ")
        val (a, b) = listOf(line[0], line[2]).map { it.toInt() }
        val op = line[1]

        if (op == "?") break

        println(
                when (op) {
                    "+" -> {
                        a + b
                    }
                    "-" -> {
                        a - b
                    }
                    "*" -> {
                        a * b
                    }
                    "/" -> {
                        a / b
                    }
                    else -> {
                    }
                }
        )
    }

}


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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define XOR(x, y) (((x) && (y)) || ((!(x)) && (!(y))))

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRESICE_COUT std::cout << std::setprecision(15) << std::fixed

int ask_distance(int a, int b) {
  cout << "? " << a << " " << b << endl;
  int x;
  cin >> x;
  return x;
}

void guess(deque<int> &que) {
  cout << "! ";
  for (auto x : que) {
    cout << x << (x != que.back() ? " " : "");
  }
  cout << endl;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  // main procedure

  // dist: 0 base, order: 1 base
  vector<vector<int>> imagawa_on_distance(N - 1, vector<int>());
  for (size_t i = 2; i <= N; i++) {
    int d = ask_distance(1, i);
    imagawa_on_distance[d - 1].push_back(i);
  }

  // order: 1 base
  deque<int> imagawa_row;
  imagawa_row.push_back(1);

  // for (auto v : imagawa_on_distance) {
  //     for (auto x : v) {
  //       cout << x << " ";
  //     }
  //     cout << endl;
  // }

  for (size_t i = 0; i < N - 1; i++) {
    if (imagawa_on_distance[i].size() == 0) {
      break;
    } else if (imagawa_on_distance[i].size() == 1) {
      int distance_from_back =
          ask_distance(imagawa_on_distance[i][0], imagawa_row.back());

      if (distance_from_back == 1) {
        imagawa_row.push_back(imagawa_on_distance[i][0]);
      } else {
        imagawa_row.push_front(imagawa_on_distance[i][0]);
      }
    } else {
      // ###DEBUG###
      //   cout << "distance(0 base) = " << i << endl;
      //   for (auto x : imagawa_row) {
      //     cout << x << (x == imagawa_row.back() ? " " : "");
      //   }
      //   cout << endl;
      // ##########

      int distance_from_back =
          ask_distance(imagawa_on_distance[i][0], imagawa_row.back());

      if (distance_from_back == 1) {
        imagawa_row.push_back(imagawa_on_distance[i][0]);
        imagawa_row.push_front(imagawa_on_distance[i][1]);
      } else {
        imagawa_row.push_front(imagawa_on_distance[i][0]);
        imagawa_row.push_back(imagawa_on_distance[i][1]);
      }
    }
  }

  // output
  guess(imagawa_row);

  return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
ans = [True] * n
for _ in range(k):
    d = int(input())
    a = [int(item) for item in input().split()]
    for item in a:
        ans[item - 1] = False

print(sum(ans))

Measured memory_bytes: 9188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int N;

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

        System.out.println(solve());
    }

    static String solve() {
        StringBuilder ans = new StringBuilder();
        while(N != 0) {
            // 1が立ってるかどうかを判定
            if( Math.abs(N % 2) == 1 ) {
                ans.append("1");
                N -= 1;
            } else {
                ans.append("0");
            }
            // bitをshiftさせる
            N /= -2;
        }
        if( ans.length() == 0 ) {
            return "0";
        } else {
            return ans.reverse().toString();
        }
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int MAX_N = 3000 + 2, INF = 987654321;
int board[MAX_N][MAX_N];
ll cache[MAX_N][MAX_N][4];
int N, M, K;

ll f(int y, int x, int toPick)
{
	//cout << y << " " << x << endl;
	if (y == N&&x == M)return (toPick ? board[y][x] : 0);

	ll&ret = cache[y][x][toPick];
	if (ret != -1)return ret;
	ret = 0;

	if (y == N )return ret = (toPick > 0 ? max(f(y, x + 1, toPick - 1) + board[y][x], f(y, x + 1, toPick)) : f(y, x + 1, toPick));
	if (x == M )return ret = (toPick > 0 ? f(y + 1, x, 3) + board[y][x] : f(y + 1, x, 3));

	if (toPick) {
		ret = max(f(y + 1, x, 3) + board[y][x], f(y, x + 1, toPick - 1) + board[y][x]);
	}
	ret = max(ret, max(f(y + 1, x, 3), f(y, x + 1, toPick)));
	
	return ret;


}

int main()
{
	memset(cache, -1, sizeof(cache));
	memset(board, 0, sizeof(board));
	cin >> N >> M >> K;
	while (K--)
	{
		int r, c, v;
		cin >> r >> c >> v;
		board[r][c] = v;
	}
	cout << f(1, 1, 3);

}

Measured memory_bytes: 321056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

ll gcd(ll a,ll b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}

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

int main(){
  int N; cin >> N;
  vector<ll> v(N);
  rep(i,N){
    cin >> v.at(i);
  }
  ll ans=1;
  rep(i,N){
    ans=lcm(ans,v.at(i));
  }
  cout << ans << endl;  
  
  
}

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

int main(){
  int n;
  cin >>n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  cout << d.at(n/2) - d.at(n/2-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;
struct rest
{
    string s;
    int z;
    int p;
    bool operator <(const rest &oth) const
    {
        if(s==oth.s)
            return z>oth.z;
        return s<oth.s;
    }
}v[101];

int main()
{
    int i,n,p;
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cin>>v[i].s>>v[i].z;
        v[i].p=i;
    }
    sort(v+1,v+1+n);
    for(i=1; i<=n; i++)
    {
        printf("%d\n",v[i].p);
    }

    return 0;
}


Measured memory_bytes: 256
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

public class Main{
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		  
		  int N;
		  int M;
		  N = s.nextInt();
		  M = s.nextInt();
		  int code[][] = new int[M][4];
		  for(int i=0;i<M;i++) {
			  code[i][0]=i; 
			  code[i][1]=s.nextInt();
			  code[i][2]=s.nextInt();
			  code[i][3]=0;
		  }

Arrays.sort(code,0,M,new Comparator<int[]>() {
 public int compare(int[] x, int[] y) {
 if(x[1] < y[1]){
 return -1;
 } else if(x[1] > y[1]){
 return 1;
 } else { 
	if(x[2] < y[2]) 
		return -1; 
	else if(x[2] > y[2])
  		return 1; 
	else
  		return 0; 
}
 } 
		}); 		
int pchange=0,ychange=0;
  		for(int i=0;i<M;i++) 		{
  			int p= code[i][1]; 			if(pchange!=p) 			{ 
				pchange=p; 	
			ychange=1; 
			} 			else 			{
			ychange++; 			
} 
			code[i][3]=ychange; 		
} 	
	Arrays.sort(code,0,M,new Comparator<int[]>() { 
public int compare(int[] x, int[] y) {
 if(x[0] < y[0]){ 
return -1;
 } else if(x[0] > y[0]){ 
return 1; 
} else {
 return 0;
 } 
} 
		});





		  
		  double resurt;
		  double tt;
	
			NumberFormat nf = NumberFormat.getInstance();
			nf.setGroupingUsed(false);
			nf.setMaximumIntegerDigits(12);	
			nf.setMinimumIntegerDigits(12);
				
		  for(int p=0;p<M;p++) {
			 
			  tt=(int)code[p][1];
			  
			  resurt = tt*1000000 + (int)code[p][3];
		
			  System.out.println(nf.format(resurt));
		  }
		
			  s.close();
		  
	}
}

Measured memory_bytes: 103184
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();

        int tmp = 0;

        tmp = X;
        X = Y;
        Y = tmp;

        tmp = X;
        X = Z;
        Z = tmp;

        System.out.println(X + " " + Y + " " + Z);
    }
}

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

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

  int ans;
  if (n >= 10) {
    ans = r;
  } else {
    ans = 100 * (10 - n) + r;
  }

  cout << ans << endl;
}


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

using i64 = int64_t;

constexpr int INF = 1e9;

int main(){
    int h, n;
    cin >> h >> n;
    vector<pair<int, int>> v;
    for(int i=0;i<n;++i){
        int a, b;
        cin >> a >> b;
        v.emplace_back(a, b);
    }

    vector<vector<int>> dp(n, vector<int>(h+1, INF));
    dp[0][0] = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<=h;++j){
            if(i+1 < n)dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            int d = j + v[i].first;
            dp[i][min(h, d)] = min(dp[i][min(h, d)], dp[i][j] + v[i].second);
            //cerr << dp[i][j] << " ";
        }
        //cerr << endl;
    }

    int ans = INF;
    for(int i=0;i<n;++i)ans = min(ans, dp[i][h]);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39424
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,t,x,y;
	cin>>N;
	int flag=0;
	for(int i=1;i<=N;i++)
	{
	   cin>>t>>x>>y;
	   int tmp=x+y;
	   if(tmp>t) flag=1;
	   else
	   	   if((t-tmp)%2==1) flag=1;
	}
	if(flag==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i > 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t int64;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using namespace std;


class B {
	int tap, target;
public:
	B()
	{
		cin >> tap >> target;
	}
	void solve()
	{
		int ans;
		target--;
		tap--;
		if (target % tap == 0)
		{
			ans = target / tap;
		}
		else
			ans = 1 + target / tap;

		cout << ans << endl;

	}
};


int main()
{
	B solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
C = [list(map(int, input().split())) for _ in range(M)]

for n in range(N):
    d_lst = []
    for m in range(M):
        dis = abs(A[n][0] - C[m][0]) + abs(A[n][1] - C[m][1])
        d_lst.append(dis)
    print(d_lst.index(min(d_lst)) + 1)

Measured memory_bytes: 9104
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] length = new int[n];
        for(int i=0;i<n;i++){
            length[i] = Integer.parseInt(sc.next());
        }
        sort(length, 0, n-1);
        int sum=0;
        for(int i=0;i<k;i++){
            sum += length[i];
        }
        System.out.println(sum);
    }

    public static void sort(int[] d, int left, int right){
        if(left>=right){return;}
        int p = d[(left + right)/2];
        int l=left, r=right;
        int tmp;
        while(l<r){
            while(d[l]>p){l++;}
            while(d[r]<p){r--;}
            if(l<=r){
                tmp=d[l];
                d[l]=d[r];
                d[r]=tmp;
                l++;r--;
            }
        }
        sort(d, left, r);
        sort(d, l, right);
    }
}

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

using ll = long long;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

const ll INF = (ll)1e11;

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int a[5];
    for (int i = 0; i < 5; ++i) cin >> a[i];

    sort(a, a+5);

    int ans = 1e9;
    do {
        int t = 0;
        for (int i = 0; i < 5; ++i) {
            int r = t % 10;
            if (r > 0) {
                t += 10 - r;
            }
            t += a[i];
        }
        ans = min(ans, t);
    } while (next_permutation(a, a+5));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

using namespace std;
const int MX = 1e6;
const int inf = 1e9;
//const int mod = 1e9+7;



using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
 }
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
vector<mint> fac(MX);
vector<mint> ifac(MX);
mint comp(ll a, ll b) {
    return fac[a]/fac[b]/fac[a-b];
}


signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,k) {
        vector<int> wa(n+1,0);
        rep(i,n) {
            int start = i - a[i];
            int end = i + a[i] + 1;
            wa[max(0,start)]++;
            wa[min(n,end)]--;
        }
        rep(i, n) wa[i+1] += wa[i];
        wa.pop_back(); 
        if(a==wa) break;
        a = wa;
    }
    rep(i, n) cout << a[i] << " " << flush;
    cout << "" << endl;

    return 0;
}


Measured memory_bytes: 20360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
const int inf = 2000000000; 
#define rep(i,n) for(int i=0; i<(n);++i)

int main(){
    int N;cin>>N;
    vector<ll> h(N),dp(N);
    rep(i,N)dp[i]=INF;
    dp[0]=0LL;
    rep(i,N)cin>>h[i];
    rep(i,N){
        if(i+1<N)dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i+2<N)dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


int main() {
    int n,m;
    cin >> n >> m;
    int s[n];
    rep(i,n)cin >> s[i];
    int t[m];
    rep(i,m)cin >> t[i];
    ll dp[n+1][m+1];
    ll MOD = 1000000007;

    rep(i,n+1){
        rep(j,m+1){
            if(i==0||j==0){
                dp[i][j] = 1;
            }else if(s[i-1]==t[j-1]){
                dp[i][j] = dp[i-1][j] + dp[i][j-1];
            }else{
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + MOD;
            }
            dp[i][j] %= MOD;
        }
    }

    

    cout << dp[n][m] << endl;
    return 0;
}
 
 




Measured memory_bytes: 31488
import scala.io.StdIn
object Main extends App {
  def breakNumber(number: Int): Int = {
    var count = 0
    var n = number
    while (n > 1) {
      n /= 2
      count += 1
    }
    count
  }
  val N = StdIn.readLine().toInt
  var maxCount = Int.MinValue
  var answer = 0
  for (i <- 1 to N) {
    val count = breakNumber(i)
    if (count > maxCount) {
      maxCount = count
      answer = i
    }
  }
  println(answer)
}


Measured memory_bytes: 27340
#define ll long long int
#define pb push_back
#include<bits/stdc++.h>
using namespace std;
void lcs(string X,string Y,int m,int n)
{
	  int L[m+1][n+1]; 
	 for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
	int index = L[m][n]; 
	char lcs[index +1];
	lcs[index]='\0';
	int i =  m,j =n;
	while(i>0 && j>0)
	{
		if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
	 else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
   cout << lcs; 
} 
int main()
{
	int n,m;
	string s,t;
	cin>>s>>t;
	n = s.length();
	m = t.length();
	lcs(s,t,n,m);
	return 0;
}

Measured memory_bytes: 35456
#include<iostream>
using namespace std;
int n,d,x;
int a[100];
int main(){
  cin >> n >> d >> x;
  for(int i=0;i<n;i++) cin >> a[i];
  int cnt=0;
  for(int i=0;i<n;i++){
    int day=1;
    while(day<=d){
      day+=a[i];
      cnt++;
    }
  }
  cout << cnt+x << "\n";
  return 0;
}


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

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    string s, t; cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] != t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3796
[A,B] = map(int,input().split())
max_ab = max(A,B)
min_ab = min(A,B)

r = max_ab
s = min_ab

while s != 0:
  r,s = s,r % s
  if s == 0:
    break
print(int(r*(A/r)*(B/r)))

Measured memory_bytes: 3060
#include<stdio.h>

struct dice{
           int a[6];
       };
struct dice dice1;
struct dice dice2;

void tate(){
            int cmp=dice2.a[0];
            dice2.a[0]=dice2.a[4];
            dice2.a[4]=dice2.a[5];
            dice2.a[5]=dice2.a[1];
            dice2.a[1]=cmp;
             }
void yoko(){
            int cmp=dice2.a[1];
            dice2.a[1]=dice2.a[2];
            dice2.a[2]=dice2.a[4];
            dice2.a[4]=dice2.a[3];
            dice2.a[3]=cmp;
             }


int main(){
    int i,j;
    for(i=0;i<6;i++){
           scanf("%d",&dice1.a[i]);
                     }
for(i=0;i<6;i++){
           scanf("%d",&dice2.a[i]);
                     }

for(i=0;i<5;i++){

              for(j=0;j<5;j++){
                              if(dice1.a[0]==dice2.a[0])break;
                               tate();
                               }
              for(j=0;j<5;j++){
                                if(dice1.a[1]==dice2.a[1])break;
                                yoko();
                                }
                  }

if(dice1.a[0]==dice2.a[0]&&dice1.a[1]==dice2.a[1]&&dice1.a[2]==dice2.a[2])printf("Yes\n");
else printf("No\n");
 
return 0;
}








Measured memory_bytes: 2108
n,k=map(int,input().split())
x=list(map(int,input().split()))

xmin=(x[n-1]-x[0])*2

for i in range(n-k+1):
    x1=abs(x[i])+abs(x[i+k-1]-x[i])
    x2=abs(x[i+k-1])+abs(x[i+k-1]-x[i])
    xmin=min(xmin,x1,x2)

print(xmin)


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

typedef long long ll;

ll n;
ll pw[15];

void dfs(ll x,int d){
    if(d<0)return;
    if(x>=pw[d])cout<<char(x/pw[d]%27+'a'-1);
    dfs(x,d-1);
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    pw[0]=1;
    for(int i=1;i<=12;i++){
        pw[i]=pw[i-1]*26;
    }
    cin>>n;
    for(int i=1;;i++)if(pw[i]>=n){
        n--;
        for(int j=1;j<=i;j++){
            cout<<char(n/pw[i-j]%26+'a');
        }
        break;
    }else n-=pw[i];

    return 0;
}

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

int main(){
	int c1,c5,c10,c50,c100,c500;
	int m;
	cin>>c1>>c5>>c10>>c50>>c100>>c500;
	m=(c1*1)+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500);
	if(m>=1000){
		cout<<"1"<<endl;
	}else{
		cout<<"0"<<endl;
	}
return 0;
}

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


int main() {

  int sx;
  int sy;
  int gx;
  int gy;
  int INF = 999999;

  vector<vector<int>> count(21, vector<int>(21));
  vector<vector<int>> count_(21, vector<int>(21));

  deque<pair<int,int>> que;

  vector<int> dx = {0, 1, 0, -1};
  vector<int> dy = {1, 0, -1, 0};

  int H, W;
  cin >> H >> W;

  vector<string> S;
  S.resize(H);
  
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      count_[i][j] = INF;
    }
  }

  count = count_;

  int answer = 0;

  for (int j = 0; j < H; j++) {
    for (int k = 0; k < W; k++) {

      if (S[j][k] == '.') {

        sx = k;
        sy = j;

        for (int j2 = 0; j2 < H; j2++) {
          for (int k2 = 0; k2 < W; k2++) {

            if (S[j2][k2] == '.' && (sx != k2 || sy != j2)) {

              gx = k2;
              gy = j2;

              count = count_;
              
              que.clear();

              que.push_back(make_pair(sy, sx));

              count[sy][sx] = 0;

              while (!que.empty()) {
                
                pair<int,int> p = que.front();
                que.pop_front();

                if (p.second == gx && p.first == gy) {
                  break;
                }

                for (int i = 0; i < 4; i++) {

                  int dx_ = p.second + dx[i];
                  int dy_ = p.first + dy[i];

                  if (0 <= dy_ && dy_ < H && 0 <= dx_ && dx_ < W && count[dy_][dx_] == INF && S[dy_][dx_] == '.'){
                    count[dy_][dx_] = count[p.first][p.second] + 1;
                    que.push_back(make_pair(dy_, dx_));
                  }

                }

              }

              answer = max(answer, count[gy][gx]);

            }
          }
        }
      }
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
import bisect

def main():
    s = input()
    k = int(input())
    n = len(s)
    dp = []
    for l in range(n):
        for r in range(l + 1, min(n + 1, l + 6)):
            t = s[l:r]
            i = bisect.bisect_right(dp, t)
            if i > 0:
                if t == dp[i - 1]: continue
            if len(dp) < k:
                bisect.insort(dp, t)
            elif t < dp[-1]:
                dp.pop()
                bisect.insort(dp, t)
    print(dp[-1])

main()


Measured memory_bytes: 3188
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-04-04 22:48:48
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

template<class T> std::vector<T> divisor(T n) {
  std::vector<T> res;
  for (T i = 1; i * i <= n; ++i) {
    if (n % i == 0){
      res.push_back(i);
      if (i * i != n){
        res.push_back(n / i);
      }
    }
  }
  std::sort(res.begin(), res.end());

  return res;
}

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

  int64 n; cin >> n;

  vector<int64> v1 = divisor(n);
  vector<int64> v2 = divisor(n - 1);

  debug(v1, v2, v1.size(), v2.size());

  int ans = v2.size() - 1;

  auto check = [&](int64 x) -> bool {
    int64 t = n;
    while (t >= x) {
      if (t % x == 0) {
        t /= x;
      } else {
        t %= x;
      }
      debug(t);
    }
    return t == 1;
  };

  int m = v1.size();

  for (int i = 0; i < m; ++i) {
    if (v1[i] == 1) continue;
    ans += check(v1[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
import itertools
N,M = map(int,input().split())
sw = [[] for _ in range(M)]
for i in range(M):
  sw[i] = list(map(int, input().split()[1:]))
p = list(map(int, input().split()))

ans = 0
for tpl in itertools.product([0,1],repeat=N):
  bl = True
  for i in range(M):
    s = sum([tpl[s-1] for s in sw[i]])
    if (s-p[i])%2 != 0:
      bl = False
      break
  if bl:
    ans += 1
print(ans)      
    

Measured memory_bytes: 3064
#include <iostream>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
typedef long long ll;
int a[200000],b[200000],c[200000];
int tmp(const void *p,const void *q){
  int n = a[*(int *)p]-a[*(int *)q];
  if(n != 0) return n;
  else return b[*(int *)q]-b[*(int *)p];
}
int main(){
  ll i,n,m,cnt=0;
  ll result=0;
  cin >> n >> m;
  for(i=0;i<n;i++){
    cin >> a[i] >> b[i];
    c[i] = i;
  }
  qsort(c,n,sizeof(int),tmp);
  for(i=0;i<n;i++){
    if(cnt+b[c[i]]>=m){
      result += (ll)a[c[i]]*(m-cnt);
      cnt = m;
      break;
    }else{
      cnt += (ll)b[c[i]];
      result += (ll)a[c[i]]*(ll)b[c[i]];
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4856
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
    n=int(input())
    S=input()
    S,T=S[:n],S[2*n-1:n-1:-1]
    C=defaultdict(int)

    for V in range(1<<n):
        s=''.join([s if((V>>i)&1) else '' for i,s in enumerate(S)])
        t=''.join([s if(not (V>>i)&1) else '' for i,s in enumerate(S)])
        C[(s,t)]+=1

    ans=0
    for V in range(1<<n):
        s=''.join([t if((V>>i)&1) else '' for i,t in enumerate(T)])
        t=''.join([t if(not (V>>i)&1) else '' for i,t in enumerate(T)])
        ans+=C[(s,t)]

    print(ans)
resolve()

Measured memory_bytes: 167160
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b=sc.nextInt();
        int res = 1;
        int now = a;
        while(now < b){
            now += (a-1);
            res++;
        }
        if(b==1)res=0;
        System.out.println(res);
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

map<string,int> table;
map<string,vector<string>> recipe;
map<string,int> opt;
map<string,int> state;

int dfs(string& name){
    state[name]=1;
    int& res=opt[name];
    res=table[name];
    if(recipe[name].empty()) return res;

    int tmp=0;
    for(auto &next:recipe[name]){
        if(state[next]==1) tmp+=table[next];
        else if(state[next]==2) tmp+=opt[next];
        else tmp+=dfs(next);
    }
    res=min(res,tmp);

    state[name]=2;
    return res;
}

void solve(){
    int n;
    while(true){
        cin >> n;
        if(!n) break;

        table.clear();
        recipe.clear();
        opt.clear();
        state.clear();

        rep(i,0,n){
            string name;
            int cost;
            cin >> name >> cost;
            table[name]=opt[name]=cost;
        }

        int m;
        cin >> m;
        rep(i,0,m){
            string name1;
            int k;
            cin >> name1 >> k;
            rep(j,0,k){
                string name2;
                cin >> name2;
                recipe[name1].push_back(name2);
            }
        }

        string str;
        cin >> str;
        cout << dfs(str) << endl;
    }
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 10000007

typedef  long long ll;

using namespace std;

ll gcd(ll a,ll b){
    if (b==0)return a;
    return gcd(b,a%b);
}

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  
  return i;
}
bool judge(string s){
  bool ret = false;
  string t = s;
  reverse(t.begin(), t.end());
  if(s == t){
    ret = true;
  }
  return ret;
}

void solve(){
  string s;
  cin >> s;
  string a,b;
  int n = s.size();
  for(int i = 0;i < (n-1)/2;i++){

    a.push_back(s[i]);
  }

  for(int i = (n+1)/2;i < n;i++){ 
    b.push_back(s[i]);  
  }
  
  if(judge(s) && judge(a) && judge(b)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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


Measured memory_bytes: 256