akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    from math import factorial
    n,k=map(int,input().split())
    def modfact(n):
        fact=[1]*(n+1)
        invfact=[1]*(n+1)
        for i in range(1,n+1):
            fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1):
            invfact[i]=invfact[i+1]*(i+1)%MOD
        return fact,invfact
    fact,invfact=modfact(n)

    for i in range(1,k+1):
        if(n-k-i+1<0):
            print(0)
            continue
        ans=fact[k-1]*invfact[i-1]*invfact[k-i]
        print(ans*fact[n-k+1]*invfact[i]*invfact[n-k-i+1]%MOD)
resolve()

Measured memory_bytes: 41840
#include <bits/stdc++.h>
//#include <iostream>
//#include <cstdio>

#define repl(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repl(i, 0, n)
#define MOD 1000000007
#define INF 2000000000

typedef long long ll;
typedef unsigned long long ull;
//typedef Pair<int,int> P;

using namespace std;

int main(void){
	char c;
	cin>>c;
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
		cout<<"vowel"<<endl;
	}else{
		cout<<"consonant"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int m = sc.nextInt();
    if(s.equals("+")){
      System.out.println(n + m);
    }else{
      System.out.println(n - m);
    }
  }
}

Measured memory_bytes: 23120
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
#include<queue>
#include<map>
using namespace std;

int gcd_2(int A, int B) {
	int a = A;
	int b = B;
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int gcd_3(int A, int B, int C) {
	int a = A;
	int b = B;
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	a = b;
	b = C;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {
	int K;
	cin >> K;
	int ans = 0;
	for (int a = 1; a <= K; a++) {
		for (int b = 1; b <= K; b++) {
			for (int c = 1; c <= K; c++) {
				ans += gcd_3(a, b, c);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3224
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{   
    ll n;
    cin>>n;
    pair<ll,ll> arr[n];
    REP(i,0,n){
        cin>>arr[i].first>>arr[i].second;
    }
    REP(i,2,n){
        if(arr[i].first == arr[i].second && arr[i-1].first == arr[i-1].second && arr[i-2].first == arr[i-2].second){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}   
    

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define TR(it,c) for( typeof(c.begin()) it = c.begin(); it != c.end(); ++it )
#define TRR(it,c) for( typeof(c.rbegin()) it = c.rbegin(); it != c.rend(); ++it
#define REP(i,a) for (int i = 0; i < (a); i++)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)

#define DRI(a) int a; scanf("%d", &a);
#define DRII(a, b) int a, b; scanf("%d %d", &a, &b);
#define DRIII(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c);
#define RI(a) scanf("%d", &a);
#define RII(a, b) scanf("%d %d", &a, &b);
#define RIII(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define MM(arr, num) memset((arr), (num), sizeof((arr)))
#define DEB(x) cerr << ">>> " << (#x) << " -> " << (x) << endl;
#define DEBA(x,n) cerr << (#x) << " "; deba((x),(n));
void deba(int * a, int n){ cerr << "| "; REP(i,n) cerr << a[i] << " "; cerr << "|" << endl;}


inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

const int INF = 1<<30;
typedef long long ll;
typedef unsigned long long ull;
/*******************************************************/
int a[15];

bool ok( int n, int k ){
  while(n){
      int num = n%10;
      n/=10;
      REP(i,k){
        if(a[i] == num)return false;
      }
  }
  return true;
}

int main() {

  DRII(n,k);
  REP(i,k)RI(a[i]);
  while(1){
    if( ok(n,k) ){cout << n << endl; return 0;}
    n++;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a1, a2, a3; cin >> a1 >> a2 >> a3;
    int sum = a1 + a2 + a3;
    cout << (sum > 21 ? "bust" : "win") << endl;
    return 0;
}

Measured memory_bytes: 256
x = []
y = []
while True:
  try:
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
  except:
    break

for i in range(3):
  a=x[i]
  b=y[i]
  
  if len(set([x[(i+1)%3], y[(i+1)%3], y[(i+2)%3], x[(i+2)%3]]))!=4:
    continue

  if not (set([x[(i+1)%3], y[(i+1)%3]]) - set([a,b])):
    continue
  elif not (set([x[(i+2)%3], y[(i+2)%3]]) - set([a,b])):
    continue
  else:
    print('YES')
    exit()

print('NO')
  

Measured memory_bytes: 3064
s = gets.strip
p = Array.new(2019){0}
p[0] = 1
num = 0
d = 1
(s.length - 1).downto(0){
  num += s[_1].to_i * d
  d *= 10
  d %= 2019
  p[num%2019] += 1
}
cnt = 0
p.each{
  cnt += _1 * (_1 - 1) / 2
}
puts cnt

Measured memory_bytes: 14756
#include <iostream>
#include <stack>
#include <cstring>
#include <cstdio>
using namespace std;

int main(){
	stack<string> stk;
	char s[10];
	string token;
	while (scanf("%s", s) != EOF) {
		token = s;
		if (token == "+") {
			long b = atoi(stk.top().c_str());
			stk.pop();
			long a = atoi(stk.top().c_str());
			stk.pop();
			stk.push(to_string(a + b));
		} else if (token == "-") {
			long b = atoi(stk.top().c_str());
			stk.pop();
			long a = atoi(stk.top().c_str());
			stk.pop();
			stk.push(to_string(a - b));
		} else if (token == "*") {
			long b = atoi(stk.top().c_str());
			stk.pop();
			long a = atoi(stk.top().c_str());
			stk.pop();
			stk.push(to_string(a * b));
		} else {
			stk.push(token);
		}
	}

	while (!stk.empty()) {
		cout << stk.top() << endl;
		stk.pop();
	}
	return 0;
}

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

int main()
{
  int  n = 0;
  string s ="";
  cin >> n >> s;
  int counter = 0;

  for(int i = 0;i < n -2;i++){
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
      counter ++;
    }
  }

  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
class F:
 __neg__=lambda s:F(2-s.v)
 __add__=lambda s,t:F(max(s.v, t.v))
 __mul__=lambda s,t:F(min(s.v, t.v))
 def __init__(s,v):s.v = v
import itertools as i,re
while 1:
 s=raw_input()
 if s==".":break
 s=re.sub("([0-R])","F(\\1)",s)
 print sum(eval(s).v==2 for P,Q,R in i.product([0,1,2],repeat=3))

Measured memory_bytes: 6512
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: i64, b: i64, c: i64, d: i64
    }

    println!("{}", if (a - c).abs() <= d || (a-b).abs() <= d && (b-c).abs() <= d {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int n,v[5000],c[5000],t[5000],ans;

int  main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n;i++)cin>>c[i];
    for(int i=0;i<n;i++){
        t[i]=v[i]-c[i];
    }
    for(int i=0;i<n;i++){
        if(t[i]>0)ans+=t[i];
    }
    cout<<ans<<endl;

}


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

int next(int A,int B,int C,int x,int *Y,int N,int frame,int look){
  if(frame>10000){
    cout << -1 << endl;
    return 1;
  }
  
  if(Y[look]==x){
    if(look==N-1){
      cout << frame << endl;
      return 0;
    }
    look++;
  }
  return next(A,B,C,(A*x+B)%C,Y,N,frame+1,look);
}
  

int main(){
  int N,A,B,C,x_1,i;
  int Y[100];
  while(1){
    cin >>N>>A>>B>>C>>x_1;
    if(N+A+B+C+x_1==0){
      break;
    }
    for(i=0;i<N;i++){
      cin >> Y[i];
    }
    next(A,B,C,x_1,Y,N,0,0);
  }
  return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int64_t K;
    cin >> K;
    int64_t count=0;
    int64_t M=K;
    while(!(M==0))
    {
        M=M/2;
        count++;
    }
    cout <<setprecision(0)<<fixed<< pow(2,count)-1 <<endl;
}


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

def main():
    N, M = list(map(int, input().split()))
    E = [deque() for i in range(N)]
    
    for i in range(M):
        a, b = list(map(int, input().split()))
        a -= 1; b -= 1
        E[a].append(b)
        E[b].append(a)
        
    par = [-1] * N
    q = deque([(0, 0)])
    c = 0
    while q:
        v, p = q.popleft()
        
        if par[v] != -1: continue
        par[v] = p+1
        c += 1
        
        for u in E[v]:
            if par[u] != -1: continue
            q.append((u, v))
        
    if c < N: print('No')
    else: 
        print('Yes')
        print('\n'.join(list(map(str, par[1:]))))
            
if __name__ == '__main__':
    main()    

Measured memory_bytes: 97452
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0, ab = 2*c;
    if(x > y) swap(a, b), swap(x, y);
    if(ab < a+b) {
        ans = ab*x; y -= x; x = 0; 
    }
    else {
        ans = (a+b)*x; y -= x; x = 0;
    }
    if(ab < b) ans += ab*y;
    else ans += b*y;
    cout << ans;
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[10010];
int main(){
	int n,x,y,z;
	memset(ans,0,sizeof(ans));
	cin>>n;
	for(int a=2;a<142;a++){
		for(int b=2;b<142;b++){
			for(int c=2;c<142;c++){
				int temp=a*a+b*b+c*c;
				if(temp%2==1||temp>20000){
					continue;
				}
				if((a+b-c)%2==1||(a+c-b)%2==1||(b+c-a)%2==1){
					continue;
				}
				if((a+b-c)<2||(a+c-b)<2||(b+c-a)<2){
					continue;
				}
				ans[temp/2]++;
			}
		}
	} 
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<endl; 
	}
	return 0;
} 

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  // ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 1;
  string cs = "";
  cs = s[0];
  int st = 1;
  rep1(i, s.size() - 1) {
    if(cs != s.substr(st,((int)(i - st + 1)))) {
      //      cerr << cs << " ";
      cs = s.substr(st, (int)(i - st + 1));
      st = i + 1;
      ans ++;
    } 
  }

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	long int t=0,p=100;
  	long int x;
  	cin>>x;
  	while(p<x){
      	p+=p/100;
    	t++;
    }
  	cout<<t<<endl;
  return 0;
}

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

int main() {
	int a,b;cin>>a>>b;
	if(b<10)a*=10;
	else if(b<100)a*=100;
	else a*=1000;
	a+=b;
	for(int i=0;i<320;i++){
		if(a==i*i){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
numof4 = 0
numof2 = 0
numofodd = 0
for i in range(N):
    if A[i] % 4 == 0:
        numof4 += 1
    elif A[i] % 2 == 0:
        numof2 += 1
    else:
        numofodd += 1

if numof4 > 0:
    if numof4 >= numofodd:
        print("Yes")

    elif numof4 > 0 and numof4 >= numofodd - 1 and numof2 == 0:
        print("Yes")
    else:
        print("No")
else:
    if numofodd == 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 14224
#include<iostream>
#include<string>

using namespace std;

int main() {
	string X, Y;	cin >> X >> Y;

	if (X < Y) {
		cout << "<" << endl;
		return 0;
	}
	else if (X == Y) {
		cout << "=" << endl;
		return 0;
	}

	cout << ">" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
using namespace std;

    const ll N = 1e2 + 7;
    const ll mod = 1e9 + 7;



void solve(){
    int x , n , k;
    cin >> x >> n;
    map < int , int > mp;
    for(int i = 1; i <= n; ++ i){
        cin >> k;
        mp[k] = 1;
    }
    int mn = 1e9 , idx;
    for(int i = 0; i <= 1000; ++ i){
        if(!mp[i]){
            if(mn > abs(x - i)){
                idx = i;
                mn = abs(x - i);
            }
        }
    }
    cout << idx;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3704
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

num_like = []
for i in 1..M do
  num_like[i-1] = 0
end

for i in 1..N do
  k = lines[i][0]
  for j in 1..k do
    food = lines[i][j]
    num_like[food-1] += 1
  end
end

ans = 0
for i in 1..M do
  if num_like[i-1] == N then
    ans += 1
  end
end
puts ans

Measured memory_bytes: 14372
/* 
author: Hayato Kawakita
date: 2020/05/11 17:23
vertict:
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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 (a>b) { a=b; return 1; } return 0; }

//inputs
int n, k;
int x[100100];

void solve() {
  //distance between houses
  vector<int> dist;
  rep(i, n - 1) {
    dist.push_back(x[i + 1] - x[i]);
  }
  sort(dist.begin(), dist.end());
  chmin(k, n);
  //k-1箇所節約できる。
  rep(i, k - 1) {
    dist.pop_back();
  }
  int ans = 0;
  for (int d: dist) ans += d;
  cout << ans << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    rep(i, n) cin >> x[i];

    solve();
  }




  
  return 0;
}


Measured memory_bytes: 4244
import math
def GCD(a,N):
    gcd = a[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, a[i])
    return gcd


k = int(input())
# h, w = map(int, input().split())
# a = list(map(int, input().split()))
ans = 0
L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if i==1 or j==1 or l==1:
                ans += 1
            else:
                ans += GCD([i,j,l], 3)

print(ans)


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> hl(n);
    rep(i, n) cin >> h[i];
    h.push_back(0);
    int ans = 0;
    for(int i = 1; i < n + 1; i++){
        if(h[i] < h[i - 1]){
            ans += h[i-1] - h[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

class Prime {
private:
	void Eratos(lint N) {
		for (lint i = 2; i * i < N; i++) {
			if (Ptb[i]) {
				for (int j = 0; i * (j + 2) < N; j++) {
					Ptb[i *(j + 2)] = 0;
				}
			}
		}
	}
public:
	vector<int> Ptb;
	
	Prime(lint N = 10000) : Ptb(N + 1, 1) { Eratos(N + 1); }
	
	vector<pair<lint,int>> Pfact(lint num) {
		vector<pair<lint, int>> res;
		for (lint i = 2; i * i <= num; i++) {
				int cnt = 0;
				while (num % i == 0) {
					cnt++;
					num /= i;
				}
				if(cnt) res.emplace_back(i, cnt);
		}
		if (num != 1) res.emplace_back(make_pair(num, 1));
		return res;
	}

	bool isPrime(lint num) {
		if (num < 2) return false;
		else if (num == 2 || num == 3) return true;
		else if (num % 2 == 0 || num % 3 == 0) return false;
		else if (num % 6 != 1 && num % 6 != 5) return false;
		for (lint i = 5; i * i <= num; i += 6) {
			if (num % i == 0) return false;
			if (num % (i + 2) == 0) return false;
		}
		return true;
	}
};

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

int main() {

	cin.tie(0);

	int N;
	cin >> N;

	vector<lint> a(N + 1);
	set<lint> ans;
	FOR(i, 0, N + 1) cin >> a[i];

	Prime p(N);

	for (int prime = 2; prime <= N; prime++) {

		if (p.Ptb[prime]) {

			vector<lint> mod(prime);
			bool flag = true;
			mod[prime - 1] = a[N];
			FOR(i, 0, N + 1) {
				mod[i % (prime - 1)] += a[i];
			}

			FOR(i, 0, prime) if (mod[i] % prime) flag = false;

			if (flag) ans.insert(prime);
		}
	}

	lint a_gcd = 0;
	FOR(i, 0, N + 1) a_gcd = gcd(a_gcd, abs(a[i]));

	auto pfac = p.Pfact(a_gcd);
	for (const auto &elem : pfac) ans.insert(elem.first);

	for (const auto& elem : ans) cout << elem << "\n" ;
	return 0;
}

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


int main() {
string S;
  cin>>S;
  int counter=0;
  int ans=0;
  
  for(int i=0;i<S.size();i++){
    if(S[i]=='A'||S[i]=='C'||S[i]=='G'||S[i]=='T'){
      counter++;ans=max(counter,ans);}
    else{ans=max(counter,ans);counter=0;}
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
using System;
using System.Text.RegularExpressions;

namespace C_DiceAndCoin
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] numlist = {1,  2,  4,  8, 16 , 32 , 64,
                                128,256,512,1024,2048,4096,
                                8192,16384,32768,65536,131072};

            string[] tmplist = Regex.Split(Console.ReadLine(), @"\s+");

            int num;
            double Ans = 0;

            for (double tmpnum = 1; tmpnum <= Convert.ToDouble(tmplist[0]); ++tmpnum)
            { 
                num = Convert.ToInt32(Math.Ceiling(Math.Log10(Convert.ToDouble(tmplist[1])/tmpnum) / Math.Log10(2)));
                if (num < 0)
                    num = 0;
                Ans += 1.0/numlist[num];
            }
            Console.WriteLine(Ans/Convert.ToDouble(tmplist[0]));
        }
    }
}


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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

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

  int H, W, K;
  cin >> H >> W >> K;
  vector<string> s(H);

  for (int i = 0; i < H; ++i) {
    cin >> s[i];
  }

  vector<vector<int>> ans(H, vector<int>(W, -1));
  int cnt = 0;

  for (int i = 0; i < H; ++i) {
    bool t = false;
    int x = 0;
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '#') {
        t = true;
        ++x;
      }
    }
    int mx = cnt + x;
    if (t) {
      ++cnt;
      for (int j = 0; j < W; ++j) {
        ans[i][j] = cnt;
        if (s[i][j] == '#') cnt = min(cnt + 1, mx);
      }
    } else {
      if (cnt == 0) continue;
      for (int j = 0; j < W; ++j) {
        ans[i][j] = ans[i - 1][j];
      }
    }
  }
  for (int i = H - 2; i >= 0; --i) {
    for (int j = 0; j < W; ++j) {
      if (ans[i][j] == -1) ans[i][j] = ans[i + 1][j];
    }
  }

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cout << ans[i][j] << " \n"[j == W - 1];
    }
  }

  return 0;
}


Measured memory_bytes: 1280
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int q, n, m, dp[1007][1007]; string s, t;
int main() {
	cin >> q;
	while(q--) {
		cin >> s >> t;
		n = s.size(), m = t.size();
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				dp[i][j] = (s[i - 1] == t[j - 1] ? dp[i - 1][j - 1] + 1 : max(dp[i - 1][j], dp[i][j - 1]));
			}
		}
		cout << dp[n][m] << endl;
	}
}

Measured memory_bytes: 7108
#include<iostream>
using namespace std;
const int INF=1e9;

int fabs(int n){
  if(n>=0)return n;
  else return -n;
}

int min(int a,int b){
  if(a>=b)return b;
  else return a;
}

main(){
  string S;
  cin >> S;
  int n=0;
  do{
    if(S[n]==0)break;
    n++;
  }while(n<1e9);
  //  cout << n << endl;
  int ans=INF;
  for(int ii=0;ii<n-2;ii++){
    ans=min(ans,fabs((S[ii]-48)*100+(S[ii+1]-48)*10+(S[ii+2]-48)-753));
    //    cout << S[ii] << " " << S[ii+1] << " " << S[ii+2] << endl;
    //    cout << S[ii]*100+S[ii+1]*10+S[ii+2] << endl;
    //    cout << fabs((S[ii]-48)*100+(S[ii+1]-48)*10+(S[ii+2]-48)-753) << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

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

    int h, w;
    cin >> h >> w;
    string s[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)
        {
            int c = 0;
            if(s[i][j] == '#') continue;
            int cur_i, cur_j;
            cur_i = i - 1; cur_j = j - 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i;     cur_j = j - 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i + 1; cur_j = j - 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i - 1; cur_j = j;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i + 1; cur_j = j;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i - 1; cur_j = j + 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i;     cur_j = j + 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            cur_i = i + 1; cur_j = j + 1;
            if ((cur_i >= 0) && (cur_j >= 0) && (cur_i < h) &&(cur_j < w)) c += (s[cur_i][cur_j] =='#')?1:0;
            s[i][j] = c+'0';
        }
    }
    for (int i = 0; i < h; ++i) cout << s[i] << endl;;

    return 0;
}

Measured memory_bytes: 256
main(a,n){
	for(;scanf("%d",&a),a;){
		a=1000-a;
		n=a/500,a%=500;
		n+=a/100,a%=100;
		n+=a/50,a%=50;
		n+=a/10,a%=10;
		n+=a/5,a%=5;
		n+=a;
		printf("%d\n",n);
	}
	exit(0);
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> x(n), y(n);

    rep(i, n)
    {
        int a;
        cin >> a;
        x[i].resize(a);
        y[i].resize(a);
        rep(j, a) cin >> x[i][j] >> y[i][j];
    }

    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        bool ck = true;
        int cnt = 0;
        rep(i, n)
        {
            if (bit & (1 << i))
            {
                rep(j, x[i].size())
                {

                    if (y[i][j] && !(bit & (1 << x[i][j] - 1)))
                    {
                        ck = false;
                    }

                    if (!y[i][j] && bit & (1 << x[i][j] - 1))
                    {
                        ck = false;
                    }
                }
            }
        }
        if (ck)
        {
            ans = max(ans, __builtin_popcount(bit));
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        long sum = 0, min = 1000000, max = -1000000;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
            if (a[i] < min) {
                min = a[i];
            }
            if (a[i] > max) {
                max = a[i];
            }
        }
        System.out.printf("%d %d %d", min, max, sum);
        System.out.println();
    }
}

Measured memory_bytes: 42764
import re

s = input()
ptn = re.compile(r'maerd|remaerd|resare|esare')
tmp = s[::-1]

while(True):
  res = re.match(ptn , tmp)
  if res is None:
    break
  tmp = tmp.replace(res.group(),'',1)

if len(tmp) == 0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main()
{
	int a[4001]={};
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000;j++)
		{
			a[i+j]++;
		}
	}
	int n;
	while(cin>>n){
	long long int all=0;
	for(int i=0;i<=1000;i++)
	{
		for(int j=0;j<=1000&&j<=n-i;j++)
		{
			all+=a[n-i-j];
		}
	}
	cout<<all<<endl;}
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long max_diff = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            if (abs(A[i]-A[j])>max_diff) {
                max_diff = abs(A[i]-A[j]);
            }
        }
    }
    cout << max_diff << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	int A[4], i;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		A[i] = s[i] - '0';
	}
	int j, sum;
	char op[3];
	for (int i = 0; i < 8; ++i) {
		sum = A[0];
		for (int j = 0; j < 3; ++j) {
			if (i & (1 << j)) {
				op[j] = '+';
				sum += A[j + 1];
			}
			else {
				op[j] = '-';
				sum -= A[j + 1];
			}
		}
		if (sum == 7)
			break;
	}
	for (int i = 0; i < 3; ++i) {
		cout << A[i] << op[i];
	}
	cout << A[3] << '=' << 7;
}

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

/*
*/

const int mod=1000000007;
template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<mod> mint;

vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

mint ps[100010],qs[100010];
ll n,a,b,c;
mint ans=0,sum,p,q,d;

void init(){
	cin>>n>>a>>b>>c;
	p=a; p/=a+b;
	q=b; q/=a+b;
	d=100; d/=100-c;
	nCr_computeFactinv(2*n);
	ps[0]=1; qs[0]=1;
	reg(i,1,n){
		ps[i]=ps[i-1]*p;
		qs[i]=qs[i-1]*q;
	}
}

int main(void){
	init();
	rep(i,n){
		ans+=nCr(n-1+i,i)*ps[n-1]*qs[i]*(n+i)*p;
		ans+=nCr(n-1+i,i)*qs[n-1]*ps[i]*(n+i)*q;
	}
	ans*=d;
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long func(long x, long y){
    long r = y % x, tmpgcd;

    while(r != 0){
        y = x;
        x = r;
        r = y % x;
    }
    tmpgcd = x;
    
    return tmpgcd;
}

int main() {
	long a, b, c, d;
	std::cin >> a >> b >> c >> d;
	
	long sum = b - a + 1;
	
	//std::cout << sum << std::endl;
	
  	//FIXED HERE
	//long lcm = a * b / func(a, b);
  	long lcm = c * d / func(c, d);
  
	//std::cout << lcm << std::endl;
	
	long sumc = (b / c) - ((a - 1) / c);
	long sumd = (b / d) - ((a - 1) / d);
	long candd = (b / lcm) - ((a - 1) / lcm);
	
	/*
	std::cout << sumc << std::endl;
	std::cout << sumd << std::endl;
	std::cout << candd << std::endl;
	*/
	
	long ans = sum - sumc - sumd + candd;
	
	std::cout << ans << std::endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a,b;
int main() {
	// your code goes here
	cin>>a>>b;
	if(b==0)cout<<a<<endl;
	else if(a+b==24)cout<<0<<endl;
	else {
		if(a+b>24)
		cout<<a+b-24<<endl;
		else
		cout<<a+b<<endl;
	}
 
 
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='+'){
            ans++;
        }
        else{
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int n, m;
vector<int> c, memo;
int dp(int x) {
    if (x < 0) return INF;
    if (memo[x] != -1) return memo[x];
    int ret = INF;
    rep(i, m) chmin(ret, dp(x - c[i]) + 1);
    return memo[x] = ret;
}
int main() {
    cin >> n >> m;
    c.resize(m);
    memo.assign(n + 10, -1);
    rep(i, m) {
        cin >> c[i];
        memo[c[i]] = 1;
    }
    cout << dp(n) << endl;
}


Measured memory_bytes: 5484
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    public static void main(String args[]) throws IOException {
        double  A= in.nextInt();
        double B = in.nextInt();
        int outlet = 1;
        int ans =0;
      while(outlet<B){
          --outlet;
          outlet+=A;
        ans++;
      }
      out.println(ans);

        out.flush();
        }
       static boolean isEven(long a){
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
        static boolean same(int [] arr,int [] temp){
            Arrays.sort(arr);
           Arrays.sort(temp);
            for(int i=0;i<arr.length;i++){
                if(temp[i]!=arr[i])
                return false;
            }
            return true;
        }

 
  


    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
using namespace std;
const int N=110;
struct card{
    char suit,value;
};
void bubble(struct card a[],int n)
{
    for(int i=0;i<n;i++)
    {
        for(int j=n-1;j>=i+1;j--)
        {
            if(a[j].value<a[j-1].value)
            {
                card t;
                t=a[j];
                a[j]=a[j-1];
                a[j-1]=t;
            }
        }
    }
}

void selection(struct card a[],int n)
{
    for(int i=0;i<n;i++)
    {
        int min=i;
        for(int j=i;j<n;j++)
        {
            if(a[j].value<a[min].value)
                min=j;
        }
        card t=a[i];a[i]=a[min];a[min]=t;
    }
}
void print(struct card a[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(i) cout<<" ";
        cout<<a[i].suit<<a[i].value;
    }
    cout<<endl;
}
bool isstable(struct card a[],struct card b[],int n)
{
    for(int i=0;i<n;i++)
    {
        if(a[i].suit!=b[i].suit)
            return false;
    }
    return true;
}
int main()
{
    card a[N],b[N];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i].suit>>a[i].value;
        b[i]=a[i];
    }
    bubble(a,n);
    selection(b,n);
    print(a,n);
    cout<<"Stable"<<endl;
    print(b,n);
    if(isstable(a,b, n))
        cout<<"Stable"<<endl;
    else
        cout<<"Not stable"<<endl;
    return 0;
}

Measured memory_bytes: 3032
#include <cstdio>
#include <cstdlib>

void
read_matrix(long* mat, int h, int w)
{
  int i, j;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      std::scanf("%ld", &mat[i * w + j]);
    }
  }
  return;
}

void
print_matrix(long* mat, int h, int w)
{
  int i, j;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      if (j == 0) {
        std::printf("%ld", mat[i * w + j]);
      } else {
        std::printf(" %ld", mat[i * w + j]);
      }
    }
    std::printf("\n");
  }
  return;
}

int
main(void)
{
  int n, m, l, i, j, k;
  long *A, *B, *C;
  
  std::scanf("%d %d %d", &n, &m, &l);

  A = (long*)std::malloc(sizeof(long) * n * m);
  B = (long*)std::malloc(sizeof(long) * m * l);
  C = (long*)std::malloc(sizeof(long) * n * l);

  read_matrix(A, n, m);
  read_matrix(B, m, l);
  
  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      C[i * l + j] = 0;
      for (k = 0; k < m; k++) {
        C[i * l + j] += A[i * m + k] * B[k * l + j];
      }
    }
  }

  print_matrix(C, n, l);

  return 0;
}



Measured memory_bytes: 2908
# -*- coding: utf-8 -*-
from sys import stdin

def insertion_sort2(A, g):
  global cnt

  for i in range(g, len(A)):
    v = A[i]
    j = i - g
    while j >= 0 and A[j] > v:
      A[j + g] = A[j]
      j = j - g
      cnt += 1
    A[j + g] = v


def shell_sort2(A, b):
  global cnt
  cnt = 0
  G = [1]
  for i in range(100):
    val = 1 + b * G[-1]
    if len(A) < val:
      break
    G.append(val)
  m = len(G)
  G.reverse()
  print(m)
  print(' '.join(map(str, G)))
  for i in range(m):
    insertion_sort2(A, G[i])
  print(cnt)
  for e in A:print(e)


n = int(stdin.readline().rstrip())
A = [int(stdin.readline().rstrip()) for i in range(n)]
shell_sort2(A, 3)



Measured memory_bytes: 45528
# いつもの探索でいいです 終了

h, w = map(int, input().split())
table = []
for _ in range(h):
  table.append(list(input()))

for i in range(h):
  for j in range(w):
    if table[i][j] != "#":
      sub_h = [0] if h==1 else [-1, 0, 1] if 0<i<h-1 else [0, 1] if i==0 else [-1, 0]
      sub_w = [0] if w==1 else [-1, 0, 1] if 0<j<w-1 else [0, 1] if j==0 else [-1, 0]
      count = 0
      for sh in sub_h:
        for sw in sub_w:
          if sh == sw == 0:
            continue
          if table[i+sh][j+sw] == "#":
            count += 1
      table[i][j] = str(count)

for i in range(h):
  print("".join(table[i]))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, k;
  int cnt = 0;
  int ans;
  int dis[100];

  cin >> a >> b >> k;
  
  for(ans = 1;ans <= min(a, b);ans++){
    if(a % ans == 0 && b % ans == 0){
      dis[cnt] = ans;
      cnt++;
    }
  }

  cout << dis[cnt - k] << endl;
  return 0;
}



Measured memory_bytes: 256
N = int(input())
T = list(map(int,input().split()))
M = int(input())
for i in range(M):
  ans = 0
  p,x = map(int,input().split())
  for j in range(N):
    if j+1 == p:
      ans += x
    else:
      ans += T[j]
  print(ans)

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

using namespace std;

int main() {
	int a[10];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	int k;
	cin >> k;
	for (int i = 0; i < 5; i++) {
		for (int j = i; j < 5; j++) {
			if (a[j] - a[i]	> k) {
				cout << ":(" << endl;
				return 0;
			}
		}
	}
	cout << "Yay!" << endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        int A = N * N * N;
        println(A);
    }

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

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

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}

Measured memory_bytes: 23636