akhauriyash/Code-Regression huggingface dataset:
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////
/*
 * 強連結成分分解
 */
struct StronglyConnectedComponents{
    int V;//頂点数
    vector<vector<int> > G; // グラフの隣接リスト表現
    vector<vector<int> > rG; //辺の向きを逆にしたグラフ
    vector<int> vs; // 帰りがけ順の並び
    vector<bool> used; // すでに調べたか
    vector<int> cmp; // 属する今日連結成分のトポロジカル順序

    StronglyConnectedComponents(int V):V(V){
        G = vector<vector<int> >(V,vector<int>(0)); rG = vector<vector<int> >(V,vector<int>(0)); 
        vs = vector<int>(V,0); used = vector<bool>(V,0); cmp = vector<int>(V,0); 
    }

    void add_edge(int  from,int to){ G[from].push_back(to); rG[to].push_back(from); }
    void dfs(int v){
        used[v] = 1;
        for(int i = 0;i < G[v].size();i++){ if(!used[G[v][i]])dfs(G[v][i]); }
        vs.push_back(v);
    }
    void rdfs(int v,int k){
        used[v] = 1; cmp[v] = k;
        for(int i = 0;i < rG[v].size();i++){ if(!used[rG[v][i]]) rdfs(rG[v][i],k); }
    }
    int calc(){
        for(int i = 0;i < V;i++)used[i] = 0;
        vs.clear();
        for(int v = 0;v < V;v++){ if(!used[v])dfs(v);}
        for(int i = 0;i < V;i++)used[i] = 0;
        int k = 0;
        for(int i = vs.size() - 1;i >= 0;i--){ if(!used[vs[i]]) rdfs(vs[i],k++); }
        return k;
    }
};
////////////////////////////////////////////////////////////////////////////////////////////
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int n,m;cin >> n >> m;
    StronglyConnectedComponents scc(n);
    rep(i,m){
        int a,b;cin >> a >> b;
        scc.add_edge(a,b);
    }
    int q;cin >> q;
    scc.calc();
    //rep(i,n)cout << i << " : " << scc.cmp[i] << '\n';
    rep(i,q){
        int a,b;cin >> a >> b;
        cout << (scc.cmp[a] == scc.cmp[b]) << '\n';
    }
    return 0;
}




Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,but;
    cin >> a >> b;
    if(a>b){
        but = a;
        a--;
    }else{
        but = b;
        b--;
    }
    if(a>b){
        but = but + a;
        a--;
    }else{
        but = but + b;
        b--;
    }
    cout << but << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long a[n];
  long long d=0,e=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    d=d+a[i];
  }
  for(int i=0;i<n;i++){
    e=e+a[i];
    if(e>d/2){
      long long f=-d+e*2;
      long long g=d-(e-a[i])*2;
      if(f<g){
        cout << f << endl;
      }
      else{
        cout << g << endl;
      }
      return 0;
    }
  }
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int Pow(int n, int m);
int Max(int N[], int n);
int Min(int N[], int n);
int Sum(int N[], int n);

#define St 500

int main()
{
	int N = 0, K = 0;
	scanf("%d%d", &N, &K);

	int* x = (int*)calloc(N, sizeof(int));
	for (int i = 0; i < N; i++) scanf("%d", &x[i]);

	int d = 0;
	int* y1 = (int*)calloc(N, sizeof(int));
	int* y2 = (int*)calloc(N, sizeof(int));
	for (int i = 0; (i + K - 1) < N; i++) {
		y1[i] = x[i + K - 1];
		y2[i] = 0 -x[i];
		d++;
	}

	int* ans = (int*)calloc(d, sizeof(int));

	for (int i = 0; i < d; i++) {
		if ( (y1[i] >= 0) && (y2[i] >= 0) ) {
			int small = y1[i] <= y2[i] ? y1[i] : y2[i];
			int big = y1[i] >= y2[i] ? y1[i] : y2[i];


			ans[i] = big + 2 * small;
		}
		else if ( (y1[i] >= 0) && (y2[i] <= 0) ) {
			ans[i] = y1[i];
		}
		else if ( (y1[i] <= 0) && (y2[i] >= 0) ) {
			ans[i] = y2[i];
		}
	}

	int ret = Min(ans, d);

	printf("%d", ret);



	return 0;
}

int Pow(int n, int m) {
	int ret = 1;

	for (int i = 0; i < m; i++) {
		ret *= n;
	}

	return ret;
}

int Max(int N[], int n) {
	int max = N[0];

	for (int i = 0; i < n; i++) {
		max = max < N[i] ? N[i]: max;
	}

	return max;
}

int Min(int N[], int n) {
	int min = N[0];

	for (int i = 0; i < n; i++) {
		min = min > N[i] ? N[i] : min;
	}

	return min;
}

int Sum(int N[], int n) {
	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += N[i];
	}

	return sum;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
int main(int argc, char *argv[])
{
  int n;
  std::vector<long long> d;
  std::cin >> n;
  if (n == 1)
  {
    long long tmp;
    std::cin >> tmp;
    std::cout << "Yes" << std::endl;
    return 0;
  }

  d.reserve(n - 1);
  long long tmp;
  std::cin >> tmp;
  for (auto i = 1; i < n; i++)
  {
    long long hi;
    std::cin >> hi;
    d.push_back(hi - tmp);
    tmp = hi;
  }

  for (auto i = n - 2; i > 0; i--)
  {
    if (d[i] < -1){
      std::cout << "No" << std::endl;
      return 0;
    }
    else if (d[i] == -1){
      d[i - 1]--;
    }
  }
  if (d[0] >= -1) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

struct node_t {
    int key;
    struct node_t *next;
};
typedef struct node_t Node;

Node *enqueue(Node *node, int key) {
  Node *p, *q;

  if (node == NULL) {
    node = malloc(sizeof(Node));
    node->key = key;
    node->next = NULL;
    return node;
  }

  for (p = node; p != NULL; p = p->next) {
    q = p;
  }
  q->next = malloc(sizeof(Node));
  q->next->key = key;
  q->next->next = NULL;
  return node;
}

Node *dequeue(Node *node, int *key) {
  Node *p;

  if (node != NULL) {
    *key = node->key;
    p = node->next;
    free(node);
        return p;
  }
  return NULL;
}

int main(void) {
  int num, i, j, k, u;
  int way[101][101] = {{0}};
  int d[101];
  Node *q = NULL;

  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++) {
      scanf("%d", &way[u-1][j]);
    }
  }

  d[0] = 0;
  for (i = 1; i < num; i++) {
    d[i] = -1;
  }
  q = enqueue(q, 0);

  while (q != NULL) {
    q = dequeue(q, &u);
    for (i = 0; i < num; i++) {
      k = way[u][i] - 1;
      if (d[k] < 0) {
    d[k] = d[u] + 1;
    q = enqueue(q, k);
      }
    }
  }

  for (i = 0; i < num; i++) {
    printf("%d %d\n", i+1, d[i]);
  }
  return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    vector<Int> a(n), b(n), c(n);
    for (Int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    Int dp[3][100005] = {};
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    for (Int i = 0; i < n - 1; i++) {
        dp[0][i + 1] = max(dp[0][i + 1], max(dp[1][i] + a[i + 1], dp[2][i] + a[i + 1]));
        dp[1][i + 1] = max(dp[1][i + 1], max(dp[0][i] + b[i + 1], dp[2][i] + b[i + 1]));
        dp[2][i + 1] = max(dp[2][i + 1], max(dp[0][i] + c[i + 1], dp[1][i] + c[i + 1]));
    }
    dump(max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])));
    return 0;  
} 

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

int main()
{
	int W , H , x , y , r ;
	cin >> W >> H >> x >> y >> r;
	if ( x - r < 0 || x + r > W || y - r < 0 || y + r > H )
	{
		cout << "No" << endl;
		}
	else
		cout << "Yes" << endl;
	

}

Measured memory_bytes: 1156
# AOJ 0071 Bombs Chain
# Python3 2018.6.22 bal4u

n = int(input())
for i in range(n):
	print("Data ", i+1, ":", sep='')
	input()
	a = [[0 for c in range(15)] for r in range(15)]
	for r in range(8): a[r] = list(input())
	Q = []
	c,r = int(input())-1, int(input())-1
	Q.append((r, c))
	while len(Q):
		r, c = Q.pop(0)
		a[r][c] = '0';
		for nr in range(r-3, r+4):
			if nr >= 0 and nr < 8:
				if a[nr][c] == '1':
					Q.append((nr, c))
					a[nr][c] = '2'
		for nc in range(c-3, c+4):
			if nc >= 0 and nc < 8:
				if a[r][nc] == '1':
					Q.append((r, nc))
					a[r][nc] = '2'
	for r in range(8):
		t = ''.join(a[r])
		s = t.replace("2", "0")
		print(s[0:8], sep='')


Measured memory_bytes: 5612
from collections import deque

n, d, a = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(n)])

ans = 0
dam_sum = 0
q = deque()
for i, (x, h) in enumerate(xh):
    while q and q[0][0] < x:
        ran, dam = q.popleft()
        dam_sum -= dam
    h -= dam_sum
    if h <= 0:
        continue 
    c = -(-h//a)
    ans += c
    dam_sum += c*a
    q.append((x+d*2, c*a))
print(ans)

Measured memory_bytes: 60528
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];
    int ans = 1;
    int up = 0;
    REP(i, n) {
        if (i != 0) {
            if (up == 1) {
                if (a[i - 1] > a[i]) {
                    ans++;
                    up = 0;
                }
            } else if (up == -1) {
                if (a[i - 1] < a[i]) {
                    ans++;
                    up = 0;
                }
            } else {
                if (a[i - 1] < a[i]) {
                    up = 1;
                } else if (a[i - 1] > a[i]) {
                    up = -1;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN = 305;
int n, ans = 0; char a[MAXN][MAXN], b[MAXN][MAXN];
inline bool check()
{
	for (int i = 0; i < n; i ++)
		for (int j = i + 1; j < n; j ++)
			if (b[i][j] != b[j][i]) return 0;
	return 1;
}
inline void operate(int x, int y)
{
	for (int i = 0; i < n; i ++)
		for (int j = 0; j < n; j ++)
			b[(i + x) % n][(j + y) % n] = a[i][j];
}
inline bool check(int x, int y) {operate(x, y); return check();}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i ++)
		scanf("%s", a[i]);
	for (int x = 0; x < n; x ++)
		if (check(x, 0)) ans += n - x;
	for (int y = 1; y < n; y ++)
		if (check(0, y)) ans += n - y;
	printf("%d\n", ans);
}

Measured memory_bytes: 384
#include<iostream>
#define I(i,n)for(int i=0,p=0;i<n;i++)
long long M=1e9+7,n,a[2],s[100000],w[2][100001],e[2],l[2][100000];
int main(){
	std::cin>>n>>*a>>a[1];
	I(i,n)std::cin>>s[i];
	I(k,2)I(i,n){for(w[k][0]=1;s[i]-s[p]>=a[k]&&p<i-1;p++);l[k][i]=p;}
	I(i,n){if(i){
		I(k,2)w[k][i]=(e[!k]<=l[k][i])*w[!k][l[k][i]];
		I(k,2)if(s[i]-s[i-1]<a[k])e[k]=i;else(w[k][i]+=w[k][i-1])%=M;
	}}
	std::cout<<(w[0][--n]+w[1][n])%M;
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  int h[N];
  for(int i = 0;i < N;i++) scanf("%d",&h[i]);

  int ans = 1;
  for(int i = 1;i < N;i++){
    for(int j = 0;j < i;j++){
      if(h[j] > h[i]) break;
      if(j == i-1) ans++;
    }
  }

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

  return 0;
}

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

int main(){
    int L;
    cin >> L;
    int A[L];
    int sum=0;
    for(int i=0;i<L;i++){
        cin >> A[i];
        sum += A[i];
    } 
    sort(A,A+L);
    if(A[L-1]<(sum-A[L-1])) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

const int maxn=1e5+10;

int n,m,a[maxn],k[maxn];
LL Sum,b[maxn];

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[i]--;
	}
	for (i=1;i<n;i++)
	{
		int u=a[i],v=a[i+1];
		Sum+=(v+m-u)%m;
		if ((u+1)%m==v) continue;
		if (u<v)
		{
//			printf("[%d,%d) : -= x-%d\n",u+1,v+1,u+1);
			k[u+1]++;
			b[u+1]-=u+1;
			k[v+1]--;
			b[v+1]+=u+1;
		}
		else
		{
//			printf("[%d,%d) : -= x-%d\n",(u+1)%m,m,u);
			k[u+1]++;
			b[u+1]-=u+1;
			k[m]--;
			b[m]+=u+1;

//			printf("[%d,%d) : -= x+%d\n",0,v+1,m-u);
			k[0]++;
			b[0]+=m-u-1;
			k[v+1]--;
			b[v+1]-=m-u-1;
		}
	}

	for (i=1;i<m;i++)
		k[i]+=k[i-1],b[i]+=b[i-1];


	LL Ans=1ll<<60;
	for (i=0;i<m;i++)
	{
		Ans=min(Ans,Sum-(LL)i*k[i]-b[i]);
	}
	printf("%lld\n",Ans);
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main(){
int a[50000],b,c=3,i=0,d=0,e;
for(b=1;b<50235;b++){
if(b==2){
a[i]=b;
i++;
}
else if(b%2==0 || b==1){
}
else{
while(sqrt(b)>=c){
if(b%c==0){
d++;
}
c=c+2;
}
if(d==0){
a[i]=b;
i++;
}
else{
d=0;
}
c=3;
}
}
while(scanf("%d\n",&e)!=EOF){
for(i=0;a[i]<e;i++){
}
if(a[i]==e){
printf("%d %d\n",a[i-1],a[i+1]);
}
else{
printf("%d %d\n",a[i-1],a[i]);
}
}
return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
 int main(){
	 int N,R;
	 scanf("%d %d", &N, &R);
	 if(N<10){
		 printf("%d", 100 * (10 - N)+R);
	 }else{
		 printf("%d", R);
	 }
	 return 0;
 }

Measured memory_bytes: 128
N=gets.to_i
abs=[]
N.times do
    a,b=gets.chomp.split(" ").map(&:to_i)
    abs.push([a,b])
end
abs=abs.sort_by{|a,b| -a-b}

ret=0
abs.each_with_index do |ab, index|
    a,b=ab
    if index%2==0
        ret += a
    else
        ret -= b
    end
end
puts ret


Measured memory_bytes: 24080
n=int(input())
arr=list(map(int,input().split()))
arr2=list(map(int,input().split()))
ans=sum(arr2)
arr3=list(map(int,input().split()))
arr3=[0]+arr3
for i in range(1,n):
	if(arr[i]==arr[i-1]+1):
		ans+=arr3[arr[i-1]]
	#print(ans)

print(ans)



Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        while (true) {
            String line = scanner.nextLine();
            if (line.equals("0")) {
                scanner.close();
                return;
            }
            int x = 0;
            for (int i = 0; i < line.length(); i++) {
                x += Integer.parseInt("" + line.charAt(i));
            }
            System.out.println(x);
        }
    }
}



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

using namespace std;

void count(vector<string>& square){
    for(int i=0; i < square.size(); i++){
        for(int j=0; j < square.at(i).size(); j++){
            if(square.at(i).at(j) != '#'){
                // count the number of mines
                int num=0;
                for(int y=-1; y<=1; y++){
                    for(int x=-1; x<=1; x++){
                        int pY = i+y, pX = j+x;
                        // avoid null
                        if(0 <= pY && pY < square.size() && 0 <= pX && pX < square.at(i).size()){
                            if(square.at(pY).at(pX) == '#'){
                                num++;
                            }
                        }
                    }
                }
                square.at(i).at(j) = '0' + num;
            }
        }
    }
}

int main(){
    int X, Y;

    cin >> Y >> X;
    
    vector<string> square(Y);
    for (int i = 0; i < Y; i++) {
        cin >> square.at(i);
    }

    count(square);

    for(int i=0; i<Y; i++){
        cout << square.at(i) << "\n";
    }
}


Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]

count = 0
flag = True
while True:
    flag = False
    for i in range(N):
        if a[i] % 2 == 0:
            a[i] = int(a[i] / 2)
            count += 1
            flag = True
    if not flag:
        break
print(count)

Measured memory_bytes: 40432
import sys
sys.setrecursionlimit(200000)

n = int(input())
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)

if n == 2:
    a,b = map(int,input().split())
    g = gcd(a,b)
else:
    a,b,c = map(int,input().split())
    g = gcd(a,b)
    g = gcd(g,c)

from collections import Counter
answers = [g]
primes = []
f = 2
while f**2<=g:
    if g%f==0:
        primes.append(f)
        g//=f
    else:
        f+=1
if g != 1:
    primes.append(g)
primes = Counter(primes)

for p,v in primes.items():
    tmp = []
    for e in range(1,v+1):
        for a in answers:
            tmp.append(a//(p**e))
    answers += tmp
answers.sort()
for a in answers:
    print(a)


Measured memory_bytes: 6004
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = in.readLine()

    def isPalindrome(s: String): Boolean = {
      s == s.reverse
    }

    out.println({
      if (isPalindrome(s) &&
        isPalindrome(s.substring(0, (s.length - 1) / 2)) &&
        isPalindrome(s.substring((s.length + 3) / 2 - 1))) {
        "Yes"
      } else {
        "No"
      }
    })

    out.flush()
  }
}


Measured memory_bytes: 27212
#include <bits/stdc++.h>
#define int long long
#define rng(i, l, r) for (size_t i = (l); i < (r); ++i)
#define rep(i, n) rng(i, 0, n)
#define gnr(i, l, r) for (size_t i = (r)-1; i >= (l); i--)
#define per(i, b) gnr(i, 0, b)
#define ALL(obj) (obj).begin(), (obj).end()    //1,2,3,...
#define rALL(obj) (obj).rbegin(), (obj).rend() //...,3,2,1

using namespace std;
const int INF = 1e18;

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

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

    int n, m;
    cin >> n >> m;
    int p[m], y[m];
    rep(im, m)
    {
        cin >> p[im] >> y[im];
    }

    vector<pair<pair<int, int>, int>> yp;
    rep(i, m)
    {
        yp.push_back(make_pair(make_pair(y[i], p[i]), i));
    }
    sort(ALL(yp));
    map<int, int> mp;
    vector<pair<int, string>> ans;
    rep(i, m)
    {
        auto now = yp[i].first;
        auto num = yp[i].second;
        int ny = now.first;
        int np = now.second;
        mp[np]++;
        //string nyStr = to_string(ny);
        string nnStr = to_string(mp[np]);
        string npStr = to_string(np);
        while (nnStr.size() < 6)
        {
            nnStr = '0' + nnStr;
        }
        while (npStr.size() < 6)
        {
            npStr = '0' + npStr;
        }

        ans.push_back(make_pair(num, npStr + nnStr));
    }
    sort(ALL(ans));
    rep(i, m)
    {
        cout << ans[i].second << endl;
    }
}

signed main()
{
    solve();
    return 0;
}


Measured memory_bytes: 17904
n=int(input())
s=([(input() )for _ in range(n)])
m=int(input())
t=([(input()) for _ in range(m)])
#print(s,t)
a=0
max=0
for i in set(s):
    a=(s.count(i)-t.count(i))
    if a>max:
        max=a
print(max)


Measured memory_bytes: 3060
N, M, C = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N+1)]
cnt = 0
for i in range(1, N+1):
    sums = 0
    for p in range(M):
        sums += A[i][p]*A[0][p]
    if sums > -C:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int ans = 0, i;
  string s;
  cin >> s;
  for(int i = 1; i < s.size(); i++){
    if(s[i-1] != s[i]) ans++;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 512
#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;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

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

signed main(){
    double N,K; cin>>N>>K;
    double ans = 0;
    FOR(i,1,N+1){
        int t = i;
        int MUST = 1;
        while(t<K){
            MUST *= 2;
            t *=2;
        }
        ans += 1/(N*MUST);
    }
    Out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int s, data, ten = 100, out = 0;
    cin >> s;

    for(int i = 1; i <= 3; i++)
    {
        data = s / ten;
        if (data != 0)
        {
            out += 1;
        }
        s %= ten;
        ten /= 10;
    }
    cout << out << endl;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
    ac = list(map(int, input().split()))
    c.append(ac[0])
    a.append(ac[1:])

ans = -1

for i in range(1 << n):
    xi = 0
    algo = [0] * m
    money = 0
    for j in range(n):
        if i & (1 << j):
            money += c[j]
            for k in range(m):
                algo[k] += a[j][k]

    flag = True

    for al in algo:
        if al < x:
            flag = False

    if flag:
        if ans != -1:
           ans = min(ans, money)
        else:
            ans = money


print(ans)


Measured memory_bytes: 9228
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int E = sc.nextInt();
        int F = sc.nextInt();
        ArrayList<Integer> listx = new ArrayList<>();
        ArrayList<Integer> listy = new ArrayList<>();

        for(int i=0; i<=40; i++){
            for(int j=0; j<=40; j++){
                int x = A * 100 * i + B * 100 * j;
                if(x>F){
                    break;
                }
                else{
                    listx.add(x);
                }
            }
        }

        for(int i=0; i<=4000; i++){
            for(int j=0; j<=4000; j++){
                int y = C * i + D * j;
                if(y>F){
                    break;
                }
                else{
                    listy.add(y);
                }
            }
        }

        double max = 0;
        int ansx = 0;
        int ansy = 0;
        for(int i=0; i<listx.size(); i++){
            for(int j=0; j<listy.size(); j++){
                int x = listx.get(i);
                int y = listy.get(j);
                if((double)y/x<=E/100.0 && x+y<=F){
                    max = Math.max(max, y * 100.0 / (x + y));
                    if(max==y*100.0/(x+y)){
                        ansx = x + y;
                        ansy = y;
                    }
                }
            }
        }
        System.out.println(ansx + " " + ansy);
    }
}

Measured memory_bytes: 29012
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int a[1001];
    int n;
    while(cin >> n){
        if(n == 0)  break;
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        int min = 10000001;
        for(int i = 0; i < n; i++){
            for(int j = i+1; j < n; j++){
                if(fabs(a[i]-a[j]) < min){
                    min = fabs(a[i]-a[j]);
                }
            }
        }
        cout << min << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3112
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long N = sc.nextInt();
		long h = 0L;
		long n = 0L;
		long w = 0L;
		for(long i=1L; i<=N*3/4; i++){
			for(long j=1L; j<=3500; j++){
				if(4*i*j-N*i-N*j>0 && (N*i*j)%(4*i*j-N*i-N*j)==0){
					h = i;
					n = (N*i*j) / (4*i*j-N*i-N*j);
					w = j;
					break;
				}
			if(h!=0)break;
			}
		}
		System.out.println(h + " " + n + " " + w);
	}
}

Measured memory_bytes: 22868
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int n, a[100];
int cnt = 0;
int main() {
	cin >> n;
	lp(n)
		cin >> a[i];
	lp(n-1)
		if (a[i] == a[i + 1]) {
			cnt++;
			a[i + 1] = 0;
		}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	string ss;
	int64 aa, zz;
	cin >> ss;
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		if(ss[ii] == 'A')
		{
			aa = ii;
			break;
		}
	}
	for(int64 ii = ss.length() - 1;ii >= 0;ii--)
	{
		if(ss[ii] == 'Z')
		{
			zz = ii;
			break;
		}
	}
	cout << zz - aa  + 1 << endl;
	return 0;
}


Measured memory_bytes: 3692
let n = read_int ()
let c = read_line()

let rec r i s =
  if i = n then s
  else if c.[i] = 'R' then
    r (i + 1) (s + 1)
  else
    r (i + 1) s

let rec f i w r =
  if w == r then r
  else if c.[i] = 'W' then
    f (i + 1) (w + 1) r
  else
    f (i + 1) w (r - 1)

let () =
  let ans = f 0 0 (r 0 0) in
  Printf.printf "%d\n" ans


Measured memory_bytes: 4080
# a.py
num = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(num[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
using namespace std;
string ls, rs;
int pos;
string s;
int state;
char c;
void next(){
  c = s[pos++];
}
bool formula(){
  next();
  if(c == '('){
    bool f, lf = formula();
    next();
    if(c == '*') f = (formula() && lf);
    else if(c == '+') f = ( formula() || lf);
    else{
      next();
      f = (formula() || !lf);
    }
    next();
    return f;
  }
  else if(c == 'T') return true;
  else if(c == 'F') return false;
  else if(c == '-') return (!formula());
  else return (1<<(c-'a'))&state;
}
bool equation(){
  for(int i = 0; i < (1 << 11); i++){
    state = i;
    pos = 0;
    bool l = formula();
    next();
    bool r = formula();
    if(l != r)return false;
  }
  return true;
}
void solve(){
  cout << (equation() ? "YES":"NO") << endl;  
}
int main(){
  while(cin >> s && s!="#"){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1208
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    X = II()

    n = 400
    for i in range(8, 0, -1):
        for j in range(200):
            # print(n)
            if X == n:
                print(i)
                return
            n += 1

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9236
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    ll k;
    int n;
    cin>>k>>n;

    ll arr[n];
    ll dist=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i!=0){
            dist=max(abs(arr[i]-arr[i-1]),dist);
        }
    }
    dist=max(abs(arr[0]+(k-arr[n-1])),dist);
    cout<<k-dist<<"\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAXN 200000
#define INF 1000000001
int v[MAXN+1];
int main(){
   int i,n,t;
   scanf("%d %d " ,&n,&t);
   for(i=1;i<=n;i++)
      scanf("%d " ,&v[i]);
   int ans=0;
   v[0]=-INF;
   for(i=2;i<=n;i++)
     if(v[i]-v[i-1]>=t)
        ans+=t;
    else
        ans+=v[i]-v[i-1];
    ans+=t;
    printf("%d\n" ,ans); 
   return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

void rotate_dice(char *direction, int *top, int *right, int *front)
{
	int temp;
	
	if (strcmp(direction, "North") == 0){
		temp = *top;
		*top = *front;
		*front = 7 - temp;
	}
	
	else if (strcmp(direction, "East") == 0){
		temp = *right;
		*right = *top;
		*top = 7 - temp;
	}
	
	else if (strcmp(direction, "West") == 0){
		temp = *top;
		*top = *right;
		*right = 7 - temp;
	}
	
	else if (strcmp(direction, "South") == 0){
		temp = *front;
		*front = *top;
		*top = 7 - temp;
	}
	
	else if (strcmp(direction, "Right") == 0){
		temp = *front;
		*front = *right;
		*right = 7 - temp;
	}
	else {
		temp = *right;
		*right = *front;
		*front = 7 - temp;
	}
}

int main(void)
{
	char direction[10];
	int top, right, front;
	int sum;
	int move;
	int i;
	while (1){
		scanf("%d", &move);
		
		if (move == 0){
			break;
		}
		
		sum = 1;
		top = 1;
		front = 2;
		right = 3;
		
		for (i = 0; i < move; i++){
			scanf("%s", direction);
			getchar();
			rotate_dice(direction, &top, &right, &front);
			sum += top;
		}
		
		printf("%d\n", sum);
	}
	return (0);
}

Measured memory_bytes: 0
// 1_4_D
#include<stdio.h>

int main(void)
{
	int i, n;
	long a, min = 1000000, max = -1000000, sum = 0;

	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%ld", &a);
		if(a < min){
			min = a;
		}
		if(a > max){
			max = a;
		}
		sum += a;
	}

	printf("%ld %ld %ld\n", min, max, sum);

	return 0;
}

Measured memory_bytes: 600
from itertools import chain

N = int(input())
An = list(map(int, input().split()[0:N]))

An_pos = [ a for a in An if a >= 0]
An_neg = [ -a for a in An if a < 0]

ans = sum(An_pos) + sum(An_neg)

if len(An_neg) % 2 == 1:
    ans -= 2 * min(chain(An_pos, An_neg))
    pass

print(ans)


Measured memory_bytes: 15280
#include<stdio.h>
#include<string.h>
typedef long long ll;
const ll maxn=1e5+10;
int fn,tn,n,odd;
int main(){
	while(~scanf("%d",&n)){
		fn=tn=odd=0;
		for(int i=1;i<=n;i++){
			ll x;
			scanf("%lld",&x);
			if(x&1) odd++;
			if(x%4==0) fn++;
			else if(x%2==0) tn++; 
		}
		if(tn==0&&fn+1>=odd||tn>0&&fn>=odd) printf("Yes\n");
	//	if(tn+2*fn+1>=n) 
		else printf("No\n");
	}
	
	return 0;
}



/*
B

char s[110];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	printf("%c%d%c\n",s[0],len-2,s[len-1]);
	return 0;
}
*/ 




/*A
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",(a-1)*(b-1));
	return 0;
} 

*/

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

int main() {
    char T;
    while (cin >> T, T != '#') {
        int table[4][13];
        char suit[4][13];
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                char a, b;
                cin >> a >> b;
                suit[i][j] = b;
                if ('0' <= a && a <= '9') table[i][j] = a - '0';
                else if (a == 'A') table[i][j] = 14;
                else if (a == 'T') table[i][j] = 10;
                else if (a == 'J') table[i][j] = 11;
                else if (a == 'Q') table[i][j] = 12;
                else if (a == 'K') table[i][j] = 13;
                if (b == T) table[i][j] += 14;
            }
        }

        int ns = 0;
        int we = 0;

        int leader = 0;
        for (int i = 0; i < 13; i++) {
            char suit_ = suit[leader][i];
            int max_ = table[leader][i];
            for (int j = 0; j < 4; j++) {
                if ((suit_ == suit[j][i] || T == suit[j][i]) && table[j][i] > max_) {
                    max_ = table[j][i];
                    leader = j;
                }
            }
            if (leader % 2) we++;
            else ns++;
        }

        if (ns > we) cout << "NS " << ns - 6 << endl;
        else cout << "EW " << we - 6 << endl;
    }

    return 0;
}

Measured memory_bytes: 3084
def main():
    S = list(input())
    c1, c2 = 0, 0
    for i in range(len(S)):
        if i % 2 == 0 and S[i] == '0':
            c1 += 1
        if i % 2 == 1 and S[i] == '1':
            c1 += 1

        if i % 2 == 0 and S[i] == '1':
            c2 += 1
        if i % 2 == 1 and S[i] == '0':
            c2 += 1
    print(min(c1, c2))




if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#coding:UTF-8
def FN(n):
    if n==0 or n==1:
        F[n]=1
        return F[n]
    if F[n]!=None:
        return F[n]
    F[n]=FN(n-1)+FN(n-2)
    return F[n]

if __name__=="__main__":
    n=int(input())
    F=[None]*(n+1)
    ans=FN(n)
    print(ans)

Measured memory_bytes: 7712
#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 ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  vector<vector<ll>> a(3, vector<ll>(3, 0));
  vector<vector<bool>> d(3, vector<bool>(3, false));
  REP(i, 3) REP(j, 3) cin >> a[i][j];
  ll n;
  cin >> n;

  REP(i, n) {
    ll b;
    cin >> b;
    REP(j, 3) REP(k, 3) {
      if (b == a[j][k]) d[j][k] = true;
    }
  }

  ll ans = false;
  REP(i, 3) {
    bool ok = true;
    REP(j, 3) {
      if (!d[i][j]) ok = false;
    }
    if (ok) ans = true;
  }

  REP(j, 3) {
    bool ok = true;
    REP(i, 3) {
      if (!d[i][j]) ok = false;
    }
    if (ok) ans = true;
  }

  if (d[0][2] && d[1][1] && d[2][0]) ans = true;
  if (d[0][0] && d[1][1] && d[2][2]) ans = true;

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

  return 0;
}

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

using namespace std;

typedef long long ll;
ll MOD = 1000000007;


ll my_pow(ll b, ll e) {
    if (e == 1) return b % MOD;
    if (e % 2 == 1){
        ll r = my_pow(b, (e-1) / 2);
        r = (r * r) % MOD;
        return (r * b) % MOD;
    } else {
        ll r = my_pow(b, e / 2);
        r = (r * r) % MOD;
        return r;
    }
}

int main() {
    int K, N;
    cin >> N >> K;

    ll result = 0;
    vector<ll> cof(K+10);
    for (int n = K; n >= 1; n--) {
        cof[n] = my_pow(floor(K / n), N);
        for (int i = n*2; i <= K; i+=n) {
            cof[n] = (MOD + cof[n] - cof[i]) % MOD;
        }
        // cout << n << " " << cof << endl;
        result = (result + cof[n] * n) % MOD;
    }

    cout << result;
}


Measured memory_bytes: 3668
#include <iostream>
using namespace std;
int main()
{
	long long s,c,k;
    cin >> s >> c;
    k = min(s,c / 2);
    c = c - s * 2;
	s = 0;
    c = max(c,s);
    cout << k + c / 4 << endl;
    return 0;
} 

Measured memory_bytes: 256
///**Bismillahir Rahmanir Rahim.**

#include <bits/stdc++.h>
#define clr(a, v)             memset(a, v, sizeof a)
#define all(v)                v.begin(), v.end()
#define ast(v)                sort(v.begin(),v.end())
#define dst(v)                sort(v.begin(),v.end(), greater <int> ())
#define fast ios_base::       sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ass(tmp, v)           tmp.assign(v.begin(), v.end())
#define mid(b, e)             (b+e)/2
#define left(node)            node*2
#define right(node)           node*2+1
#define rep(i, l, r)          for (int i = l; i < r; i++)
#define rep2(i, l, r)         for (int i = l-1; i >= r; i--)
#define sf(n)                 scanf("%d", &n)
#define sff(n, m)             scanf("%d %d",&n,&m)
#define sfl(n)                scanf("%lld", &n)
#define sffl(n, m)            scanf("%lld %lld",&n,&m)
#define sfff(n, m, o)         scanf("%d %d %d",&n,&m, &o)
#define pf(n)                 printf("%d", n)
#define sp                    printf(" ")
#define nl                    printf("\n")
#define prln(n)               printf("%d\n", n)
#define pfl(n)                printf("%lld", n)
#define pb                    push_back
#define pii                   pair<int,int>
#define mp                    make_pair
#define S                     second
#define F                     first
#define PI                    3.1415926

struct greaters
{
    bool operator()(const long& a, const long& b) const
    {
        return a > b;
    }
};

//-----------------------------------***********************----------------------------------------------//

typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
const int N = 200050;
const int mod = 1e9+7;

void reset(){

}

int main(){
    //freopen("test.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int tc = 1, cas = 0;
    while(tc--){
      //reset();
	  int a, b; cin >> a >> b; a--, b--;
	  cout << ceil((float)b/a) << '\n';

      ///printf("Case %d: %lld\n", ++cas, ans);
    }
    return 0;

}

//-----------------------------------***********************----------------------------------------------//



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

/*
答えはXに依存しないと予想できる -> はずれ

N=2 len=3
N=3 len=6
N=4 len=9 (X=2 -> len=6)
N=5 len=12

*/

#define KABE_MIGI 1
#define KABE_UE 2
#define KABE_SITA 4

char kabe[2000][2000];

uint64_t solve(uint64_t N, uint64_t X) {
	memset(kabe, 0, sizeof(kabe));
	if (N <= 1000) {
		static const uint64_t dputtern[6][2] = {
			{0, 1}, /* 右 */
			{-1, 0}, /* 右上 */
			{1, 1}, /* 右下 */
			{0, -1}, /* 左 */
			{-1, -1}, /* 左上 */
			{1, 0} /* 左下 */
		};
		uint64_t i;
		uint64_t y, x;
		int d;
		int invalid;
		uint64_t answer = 0;
		for (i = 1; i <= N; i++) {
			kabe[10+i][10+0] = KABE_UE; /* 左 */
			kabe[10+i - 1][10+i - 1] = KABE_SITA; /* 右 */
			kabe[10+N][10+i - 1] = KABE_MIGI; /* 底辺 */
		}
		y = 10+X;
		x = 10;
		d = 0; /* 右 */
		while (answer == 0 || y != 10+X || x != 10) {
			/* 壁を生やして移動する */
			switch(d) {
				case 0: kabe[y][x] |= KABE_MIGI; break;
				case 1: kabe[y][x] |= KABE_UE; break;
				case 2: kabe[y][x] |= KABE_SITA; break;
				case 3: kabe[y][x-1] |= KABE_MIGI; break;
				case 4: kabe[y-1][x-1] |= KABE_SITA; break;
				case 5: kabe[y+1][x] |= KABE_UE; break;
			}
			y += dputtern[d][0];
			x += dputtern[d][1];
			answer++;
#if 0
			printf("%d %d %d %d\n", (int)(x-10),(int)(y-10),d, kabe[y][x]);fflush(stdout);
			if(answer>20)break;
#endif
			/* 反射する */
			invalid = 1;
			if ((kabe[y][x] & KABE_MIGI) || (kabe[y][x-1] & KABE_MIGI)) {
				invalid = 0;
				switch(d) {
					case 0: invalid = 1; break;
					case 1: d = 2; break;
					case 2: d = 1; break;
					case 3: invalid = 1; break;
					case 4: d = 5; break;
					case 5: d = 4; break;
				}
			}
			if (invalid && ((kabe[y][x] & KABE_UE) || (kabe[y+1][x] & KABE_UE))) {
				invalid = 0;
				switch(d) {
					case 0: d = 4; break;
					case 1: invalid = 1; break;
					case 2: d = 3; break;
					case 3: d = 2; break;
					case 4: d = 0; break;
					case 5: invalid = 1; break;
				}
			}
			if (invalid && ((kabe[y][x] & KABE_SITA) || (kabe[y-1][x-1] & KABE_SITA))) {
				switch(d) {
					case 0: d = 5; break;
					case 1: d = 3; break;
					case 2: invalid = 1; break;
					case 3: d = 1; break;
					case 4: invalid = 1; break;
					case 5: d = 0; break;
				}
			}
		}
		return answer;
	} else {
		/* not implemented */
		return  UINT64_C(3) * (N - 1);
	}
}

uint64_t gcd(uint64_t a, uint64_t b) {
	uint64_t r;
	while (b) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}

int main(void) {
	uint64_t N, X;
#if 0
	int wacount = 0;
	for (N = 2; N < 200; N++) {
		for (X = 1; X < N; X++) {
			uint64_t a = solve(N, X);
			uint64_t p = UINT64_C(3) * (N - gcd(N, X));
			if (a != p) {
				printf("Wrong answer N = %"PRIu64", X = %"PRIu64", a = %"PRIu64", p = %"PRIu64"\n", N, X, a, p);
				if (++wacount >= 10) return 0;
			}
		}
	}
#else
	if (scanf("%"SCNu64"%"SCNu64, &N, &X) != 2) return 1;
#if 0
	printf("%"PRIu64"\n", solve(N, X));
#else
	printf("%"PRIu64"\n", UINT64_C(3) * (N - gcd(N, X)));
#endif
#endif
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=2000000+10;
const int base=1000000000+7;

int x,y;
long long gt[maxn];
long long kq;

long long power(int n,int k){
    if (k==0) return 1%base;
    if (k==1) return n%base;
    long long tmp=power(n,k/2);
    tmp=(tmp*tmp)%base;
    if (k%2==1) tmp=(tmp*n)%base;
    return tmp;
}

long long inv(long long z){
    return power(z,base-2);
}

long long C(int k,int n){
//    cout<<"C("<<k<<" "<<n<<")\n";
    long long tu=gt[n];
    long long mau=(gt[k]*gt[n-k])%base;
    mau=inv(mau);
    return (tu*mau)%base;
}

int main(){
    gt[0]=1;for(int i=1;i<=2000000;i++) gt[i]=(gt[i-1]*i)%base;
    cin>>x>>y;kq=0;
    if ((x+y)%3==0){
        int z=x+y;
        if (x<z/3 || x>2*z/3) kq=0;
        else{
            int n=z/3;
            int k=x-z/3;
            kq=C(k,n);
        }
    }
    cout<<kq;
}


Measured memory_bytes: 15872
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()
dp = [-1] * (N+1)
dp[0] = 0
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
for x in range(N):
    for a in A:
        y = match[a]
        if x + y > N:
            continue
        dp[x+y] = max(dp[x+y], dp[x] * 10 + a)

answer = dp[N]
print(answer)
# 32

Measured memory_bytes: 51548
from functools import reduce
import math

def main():
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input().rstrip())
    S = []
    ans = []
    min_len = 1e10
    min_i = 0
    for i in range(N):
        s = list(_ for _ in input())
        if(min_len>len(s)):
            min_len = len(s)
            min_i = i
        s.sort()
        S.append(s)
    for i in range(min_len):
        search_char = S[min_i][i]
        flag = True
        for j in range(N):
            if(search_char in S[j]):
                S[j][S[j].index(search_char)] = '0'
            else:
                flag=False
                break
        if flag:
            ans.append(search_char)
    print(''.join(ans))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3700