akhauriyash/Code-Regression huggingface dataset:
///****In the name of ALLAH, most Gracious, most Compassionate****//

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

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

#define ALL(a) a.begin(), a.end()
#define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define IN freopen("input.txt","r+",stdin)
#define OUT freopen("output.txt","w+",stdout)

#define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl
#define NL cout<<endl

template < class T1,class T2>
ostream &operator <<(ostream &os,const pair < T1,T2 > &p)
{
    os<<"{"<<p.first<<","<<p.second<<"}";
    return os;
}

const int N=500+5;
const int oo=1e9+7;
bool nai[N][N];
void delete_edge(int u,int v)
{
    nai[u][v]= 1;
}

int32_t main()
{
    FastIO;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        delete_edge(i,n%2 ? n-i : n-i + 1);
    }
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
            ans+=!nai[i][j];
    }
    cout<<ans<<"\n";
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
            if(!nai[i][j])
                cout<<i<<" "<<j<<"\n";
    }
}


Measured memory_bytes: 384
n, q = map(int, input().split())
union = [x for x in range(n)]
answer = []

def root(idx) :
    if idx == union[idx] :
        return idx
    else :
        union[idx] = root(union[idx])
        return union[idx]

for i in range(q) :
    com, x, y = map(int, input().split())
    
    # union
    if com == 0 :
        min_root = min(root(x), root(y))
        union[root(x)] = union[root(y)] = min_root
        
    # non-union
    else :
        if root(x) == root(y) :
            answer.append("1")
        else :
            answer.append("0")
            
for i in answer :
    print(i)


Measured memory_bytes: 6988
n = int(input())
a = list(map(int, input().split()))


l = []
ans = 0

cnt = 1

flg = True

for i in range(n):
    if a[i] == cnt:
        cnt += 1
        flg = False
    else:
        ans += 1


if flg:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 26268
#include <cstdio>
typedef long long int lli;

int main()
{
	lli K;
	scanf("%lld", &K);
	lli p = K / 50;
	lli q = K % 50;
	printf("50\n");
	for (int i = 0; i < q; i++)
		printf("%lld ", 100 - q + p);
	for (int i = 0; i < 50 - q; i++)
		printf("%lld ", 49 - q + p);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sum=0,b=0;
        while (true) {
            char a[] = sc.nextLine().toCharArray();
            if(a[0]-'0'==0){
                break;
            }
           for(int i=0;i<a.length;i++){
               b=a[i]-'0';
               sum=sum+b;
           }
        
           System.out.printf("%d\n",sum);
           sum=0;
        }
        sc.close();
    }

}


Measured memory_bytes: 26792
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderCs
{
    class Program
    {
        static void Main()
        {

            var K = long.Parse(Console.ReadLine());
            var Result = 0L;

            for (; 0 < K; K--)
            {

                if (K % 3 != 0 && K % 5 != 0) 
                    Result += K;

            }

            Console.WriteLine(Result);

        }


    }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    string T;
    T = "CODEFESTIVAL2016";

    ll count = 0;
    REP(i, S.length()){
        if(S[i] != T[i]) count++;
    }
    cout << count << endl;
    return 0;
}

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

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define digits(x) floor(log10(x) + 1)
#define countbits(x) ((int)log2(x)+1)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define init(arr,value) memset(arr,value,sizeof(arr))
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int tet;cin >> tet;while(tet--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const ll N   = 500500;

signed main(void)
{
    	fastio
        int n;
        cin >> n;
        int a[n+1],b[n+1],c[n+1],x[n+1],y[n+1],z[n+1];
        for(int i=1; i<=n; i++){
            cin >> a[i] >> b[i] >> c[i];
        }
        x[1] = a[1];
        y[1] = b[1];
        z[1] = c[1];
        for(int i=2; i<=n; i++){
            x[i] = a[i] + max(y[i-1],z[i-1]);
            y[i] = b[i] + max(x[i-1],z[i-1]);
            z[i] = c[i] + max(x[i-1],y[i-1]);
        }

        cout << max(x[n],max(y[n],z[n]));

    	return 0;
}



Measured memory_bytes: 8324
# https://atcoder.jp/contests/abc110/tasks/abc110_d
# 誤読をしないように気をつけよう
# 発想は惜しいところまで行っていたしもう一回解いてみよう

N, M = map(int, input().split())


def factorization(n: int):
    if n == 1:
        return []  # 1は素数ではない
    # 素因数分解
    arr = []
    temp = n
    for i in range(2, int(n**0.5) + 1):  # ここにバグがないか心配
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append((i, cnt))

    if temp != 1:
        arr.append((temp, 1))

    if arr == []:
        arr.append((n, 1))

    return arr


def combination_mod(n, r, mod):
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i) % mod
        rf = rf * (i + 1) % mod
    return nf * pow(rf, mod - 2, mod) % mod


MOD = 10**9 + 7
facts = factorization(M)
ans = 1
for i, n in facts:
    ans *= combination_mod(n + N - 1, n, MOD)  # 取り出したところがたまたま壁になるっていう発想でもいいかも
    ans %= MOD
print(ans)


Measured memory_bytes: 38512
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    if(n >= 3200){
        P(s);
    }else{
        P("red");
    }
}

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


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

int main(void) {
  vector<bool> isp(100001, true);
  isp[0] = isp[1] = false;
  REP(i, 0, isp.size()) if(isp[i]) for(ll j = i + i; j < isp.size(); j += i) isp[j] = false;
  vector<ll> prime;
  REP(i, 0, isp.size()) if(isp[i]) prime.push_back(i);

  ll M, A, B;
  while(cin >> M >> A >> B, M && A && B) {
    ll m = 0;
    ll ansp, ansq;
    for(ll q : prime) {
      ll pmax = min(q, M / q);
      ll pmin = (A * q + B - 1) / B;
      ll x = upper_bound(prime.begin(), prime.end(), pmax) - prime.begin() - 1;
      if(prime[x] >= pmin) {
        ll p = prime[x];
        if(m <= p * q && p * q <= M) {
          ansp = p;
          ansq = q;
          m = p * q;
        }
      }
    }
    cout << ansp << " " << ansq << endl;
  }
}



Measured memory_bytes: 3204
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int n, l[30];

void solve() {
  int rest = 32, ptr = 0;
  while (rest) {
    rest -= (rest - 1) % 5;
    cout << rest << endl;
    if (rest > l[ptr]) {
      rest -= l[ptr];
      ptr++;
      if (ptr >= n) ptr = 0;
    } else {
      rest = 0;
    }
    cout << rest << endl;
  }
}

int main() {
  while (cin >> n, n) {
    rep (i,n) {
      cin >> l[i];
    }
    solve();
  }
}

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

int main() {
  int a, b, c, x, y, sum = 0;
  cin >> a >> b >> c >> x >> y;
  int mini = min(x, y);
  if (a + b >= c * 2) {
    sum = c * 2 * min(x, y);
    x -= mini;
    y -= mini;
  }
  
  sum += min(a, c*2) * x + min(b, c*2) * y;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int a[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) scanf("%d", &a[i]);
    sort(a, a + N);
    if (a[N - 1] - a[0] >= 2) return !printf("No\n");
    int cnt0 = 1;
    for (int i = 1; i < N; i++) {
        if (a[i] == a[0]) cnt0++;
    }
    // 2 color distinct
    if (cnt0 != N) {
       int cnt1 = N - cnt0;
       if (cnt0 + 1 <= a[N - 1] && a[N - 1] <= cnt0 + cnt1 / 2) return !printf("Yes\n");
       return !printf("No\n");
    }
    // all the same
    if (a[0] * 2 > N) {
       if (a[0] == N - 1) return !printf("Yes\n");
       return !printf("No\n");
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n, m;
	cin >> n;
	map<string, int> s;
	rep(i, 0, n) {
		string str;
		cin >> str;
		s[str]++;
	}
	cin >> m;
	rep(i, 0, m) {
		string str;
		cin >> str;
		s[str]--;
	}
	int maxv = 0;
	for (auto itr = s.begin();itr != s.end();itr++) {
		maxv = max(maxv, itr->second);
	}
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let m: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut av = vec![true; n + 1];
    for _ in 0..m {
        av[read::<usize>(&mut stdin_lock, &mut buf, b'\n')] = false;
    }

    let mut tbl = vec![0i32; n + 1];
    tbl[0] = 1;
    tbl[1] = tbl[0];
    for i in 2..n + 1 {
        let a = if av[i - 1] { tbl[i - 1] } else { 0 };
        let b = if av[i - 2] { tbl[i - 2] } else { 0 };
        tbl[i] = (a + b) % 1_000_000_007;
    }
    println!("{}", tbl[n]);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }
  
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
  
typedef pair< int , int > Pi;
typedef pair< bool, Pi > Pii;
  
typedef long long int64;
 
int UF[40000];
int BF[40000];
int loger[400000];
int siz;
int Find(int a){
  return(UF[a] < 0 ? a : Find(UF[a]));
}
void Union(int a,int b, bool flag = false){
  if((a = Find(a)) != (b = Find(b))){
    if(flag) loger[siz++] = a,loger[siz++] = b;
    if(UF[a] > UF[b]) swap( a, b);
    UF[a] += UF[b], UF[b] = a;
  }
}

const int SQR = 200;
set< Pi > T; // 変化があった辺
set< Pi > S; // 存在する辺
 
int main(){
  int n, Q;
  int x[40000], y[40000], z[40000];
 
  scanf("%d %d", &n, &Q);
  for(int i = 0; i < Q; i++){
    scanf("%d %d %d", &x[i], &y[i], &z[i]);
  }
  for(int i = 0; i < Q; i++){
    if(i % SQR == 0){
      T.clear();
      for(int j = 0; j < n; ++j) UF[j] = BF[j] = -1;
      for(int j = 0; j < SQR && i + j < Q; j++){
        if(x[i + j] != 3){
          T.insert( make_pair( y[i + j], z[i + j]));
          if(x[i + j] == 1) S.insert( make_pair( y[i + j], z[i + j]));
          else if(x[i + j] == 2) S.erase( make_pair( y[i + j], z[i + j]));
        }
      }
      ForEach( it, S){
        if(T.find(*it) == T.end()){ // 以前に追加されていて変化がない辺を結合
          Union( it -> first, it -> second);
        }
      }
      for(int j = 0; j < n; ++j) BF[j] = UF[j];
    }
    if(x[i] == 3){
      set< Pi > u;
      int N = i / SQR * SQR;
      for(int k = 0; k < i % SQR; k++){ // それ以前
        if(x[k + N] == 1) u.insert( make_pair( y[N + k], z[N + k]));
        else if(x[k + N] == 2) u.erase( make_pair( y[N + k], z[N + k]));
      }
      for(int k = min( SQR - 1, Q - N - 1); k > i % SQR; k--){ // それ以後
        if(x[k + N] == 1) u.erase( make_pair( y[N + k], z[N + k]));
        else if(x[k + N] == 2) u.insert( make_pair( y[N + k], z[N + k]));    
      }
      siz = 0;
      ForEach( it, u) Union( it -> first, it -> second, true);
      puts(Find(y[i]) == Find(z[i]) ? "YES" : "NO");
      for(int j = 0; j < siz; j++) UF[loger[j]] = BF[loger[j]];
    }
  }
}

Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
using namespace std;

signed main(void)
{
	int n;
	vector<pair<int, int>> tasks;
	int now = 0;

	cin >> n;
	tasks.resize(n);
	rep(i, n)
	{
		int a, b;
		cin >> a >> b;
		tasks.emplace_back(b, a);
	}
	sort(tasks.begin(), tasks.end());
	for(auto v : tasks)
	{
		now += v.second;
		if (v.first < now)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 4864
#include<iostream>
#include<vector>
#include<string>
using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  int tmp = 0;
  for(int i = 1; i <= n; i+=2){
    for(int j = 1; j <= i; j++){
      if(i % j == 0) tmp++;
    }
    if(tmp == 8) ans++;
    tmp = 0;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
a = list(map(int, input().split()))

cnt = 0
for i in range(n - 1):
    if (a[i] + a[i + 1]) > x:
        diff = (a[i + 1] + a[i]) - x
        if diff <= a[i + 1]:
            a[i + 1] = a[i + 1] - diff
        else:
            a[i + 1] = 0
            a[i] = a[i] - (diff - a[i + 1])
        cnt += diff

print(cnt)


Measured memory_bytes: 14540
#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 = 0;
  // bool ok = false;
  for(int i = 0; i < N; i+=2) {
    ans += (a[i]%2==1)?1:0;
  }
  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


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


Measured memory_bytes: 3720
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

const int AMAX = 100000;
long long int cnt[AMAX + 1];

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

    for(int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }

    for(int i = 1; i <= 100000; i++)
    {
        if ( K <= cnt[i])
        {
            cout << i << endl;
            break;
        }
        K -= cnt[i];
    }
    
    return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
 
using namespace std;
int main()
{
    int l,d,r;
    cin>>l>>r>>d;
    int sum=0,temp=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            sum++;
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int a[1010];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int q, com, b, e, ans;
    cin >> q;
    for(int i=0; i<q; i++){
        cin >> com >> b >> e;
        if(com==0){
            ans=1000000010;
            for(int j=b; j<e; j++){
                ans=min(ans, a[j]);
            }
            cout << ans << "\n";
        }
        else{
            ans=-1000000010;
            for(int j=b; j<e; j++){
                ans=max(ans, a[j]);
            }
            cout << ans << "\n";
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

int d[1145];
int main(){
	int n=read(),m=read(),a=read(),b=read();
	REP(i,n)
		d[i]=read();
	vi g;
	REP(i,n)
		if(d[i]>=a)
			g.PB(d[i]);
		else
			break;
	if(int(n-g.size())<m){
		while(!g.empty())
			if(g.back()<=b)
				g.pop_back();
			else
				break;
	}
	cout<<g.size()<<endl;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;
    int ans = (B - 1 + A - 2) / (A - 1);
    cout << ans << endl;
}



Measured memory_bytes: 256
//E - Coprime
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>

#define LL long long
#define Lowbit(X) (X&(-X))
#define Lson (X<<1)
#define Rson (X<<1|1)
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(LL i=A;i<=B;i++)
#define BOR(i,A,B) for(LL i=A;i>=B;i--)
#define FOR_SIDE(i,A) for(LL i=Head[A];i;i=Next[i])
#define INF 0x7fffffff
using namespace std;
const LL MAXN=1e6+10;

LL Cnt[MAXN],Num[MAXN],Total;
LL Prime[MAXN],Max,Tot;
bool Jud[MAXN],Vis1,Vis2,Vis3;

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

inline LL GCD(LL X,LL Y) {
	return ((Y==0) ? X : GCD(Y,X%Y)); 
}

inline void Init() {
	Jud[1]=true;
	FOR(i,2,MAXN-5) {
		if(!Jud[i]) Prime[++Tot]=i;
		for(LL j=1;j<=Tot && i*Prime[j]<=MAXN-5;j++) {
			Jud[i*Prime[j]]=true;
			if(i%Prime[j]==0) break;
		}
	}
}

int main() {
    //File();
	scanf("%lld",&Total);
	FOR(i,1,Total) {
		scanf("%lld",&Num[i]);
		if(i!=1) Max=GCD(Max,Num[i]);
		else Max=Num[i];
		Cnt[Num[i]]++;
	}
	if(Max!=1) { cout<<"not coprime"<<endl; return 0; }
	Init();
	FOR(i,1,Tot) {
		LL Temp=0;
		for(LL j=Prime[i];j<=MAXN-5;j+=Prime[i]) 
			Temp+=Cnt[j];
		if(Temp>=2) { cout<<"setwise coprime"<<endl; return 0; }
	}
	cout<<"pairwise coprime"<<endl;
    //fclose(stdin); fclose(stdout);
    //system("pause");
    return 0;
}


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

const int MAX_N = 1e5;
int N, K;
map<lint, lint> A;

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++){
        lint a, b; cin >> a >> b;
        auto it = A.find(a);
        if(it == A.end()) A[a] = b;
        else it->second += b; 
    }

    vector<int> bk(30);
    for(int i=0;i<30;i++){
        if((K>>i) & 1) bk[i] = 1;
        else bk[i] = 0;
    }

    lint ans = 0;
    for(auto it : A){
        bool ok = true;
        for(int j=0;j<30;j++)
            if((it.first>>j) & 1 == 1 &&  bk[j] == 0) ok = false;

        if(ok) ans += it.second;
    }

    for(int i=1;i<30;i++){
        if(!bk[i]) continue;

        lint res = 0; bk[i] = 0;
        for(auto it : A){
            bool ok = true;
            for(int j=i;j<30;j++)
                if((it.first>>j) & 1 == 1 &&  bk[j] == 0) ok = false;

            if(ok) res += it.second;
        }

        ans = max(ans, res);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ul=unsigned long long;
int s[500],t[500],tmp[500][500],S[500],T[500],n,bit=-1,IN;
ul ans[500][500],u[500],v[500];
void ng(){
  cout<<-1;
  exit(0);
}
struct P{int va,idx,ve,ne,al;};
bool operator <(const P&a,const P&b){return a.va<b.va;};
priority_queue<P> que;
#define REP(i) for(int i=0;i<n;i++)
#define U ((u[i]>>bit)&1)
#define V ((v[j]>>bit)&1)
#define F(va) {\
  if(!~tmp[i][j]){\
    ans[i][j]+=((ul)1<<bit)*(tmp[i][j]=va);\
    if(++S[i]<n&&IN)que.push({S[i],i,'S',s[i]});\
    if(++T[j]<n&&IN)que.push({T[j],j,'T',t[j]});\
  }\
}
void AL(){
  int KO=1;
  while(KO--){
    REP(i)
      if(s[i]==U){
        bool f=0;
        REP(j)f|=tmp[i][j]==s[i];
        if(f)REP(j){KO|=tmp[i][j]<0;F(s[i]^1);}
      }
    REP(j)
      if(t[j]==V){
        bool f=0;
        REP(i)f|=tmp[i][j]==t[j];
        if(f)REP(i){KO|=tmp[i][j]<0;F(t[j]^1);}
      }
  }
}
bool same(int a,int b,int c,int d){return a==b&&b==c&&c==d;}
int main(){
  cin>>n;
  REP(i)cin>>s[i];
  REP(i)cin>>t[i];
  REP(i)cin>>u[i];
  REP(i)cin>>v[i];
  while(++bit<64){
    memset(tmp,-1,sizeof(tmp));
    memset(S,0,sizeof(S));
    memset(T,0,sizeof(T));
    IN=0;
    REP(i)if(s[i]^U)REP(j)F(s[i]^1);
    REP(j)if(t[j]^V)REP(i)F(t[j]^1);
    REP(i)REP(j)if(same(s[i],(u[i]>>bit)&1,t[j],(v[j]>>bit)&1))F(s[i]);
    AL();
    IN=1;
    REP(i)if(S[i]<n)que.push({S[i],i,'S',s[i],1});
    REP(j)if(T[j]<n)que.push({T[j],j,'T',t[j],1});
    while(que.size()){
      P p=que.top();que.pop();
      if(p.ve=='S'){
        int i=p.idx;
        if(p.va<S[i])continue;
        REP(j)
          if(!~tmp[i][j]){
            F(p.ne);
            p.ne^=p.al;p.al=0;
          }
        AL();
      }
      else{
        int j=p.idx;
        if(p.va<T[j])continue;
        REP(i)
          if(!~tmp[i][j]){
            F(p.ne);
            p.ne^=p.al;p.al=0;
          }
        AL();
      }
    }
  }
  REP(i){
    ul A=ans[i][0];
    REP(j)
      if(s[i])A|=ans[i][j];
      else A&=ans[i][j];
    if(A!=u[i])ng();
  }
  REP(j){
    ul A=ans[0][j];
    REP(i)
      if(t[j])A|=ans[i][j];
      else A&=ans[i][j];
    if(A!=v[j])ng();
  }
  REP(i){
    REP(j)cout<<ans[i][j]<<" ";cout<<endl;
  }
}


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

int main() {

    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i, n+1){
        cin >> a[i];
    }
    vector<ll> b(n);
    rep(i, n){
        cin >> b[i];
    }

    ll ans = 0;
    rep(i, n){
        if(a[i] <= b[i]){
            ans += a[i];
            b[i] -= a[i];
            if(a[i+1] > b[i]){
                ans += b[i];
                a[i+1] -= b[i];
            }
            else{
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
        else{
            ans += b[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
double n,m,x,y;
int main()
{
	cin>>n>>m>>x>>y;
	if(x==n/2&&y==m/2) printf("%.12f 1",n*m/2.0);
	else printf("%.12f 0",n*m/2.0);
	return 0;
}

Measured memory_bytes: 256
require('fs').readFile('/dev/stdin', 'utf-8', (err, data) => {
  var lines = data.split('\n');
  var n = +lines[0];
  var a = lines[1];
  var b = lines[2];
  var c = lines[3];
  var answer = 0;
  for (var i = 0; i < n; i++) {
    if (a[i] === b[i]) {
      if (a[i] !== c[i]) {
        answer++;
      }
    } else {
      if (a[i] === c[i]) {
        answer++;
      } else if (b[i] === c[i]) {
        answer++;
      } else {
        answer += 2;
      }
    }
  }
  console.log(answer);
});

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 200000 + 5, mod = 1e9 + 7;
long long A[N], B[N];
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int n, pow2[N];
map<pair<long long, long long>, int> K;
int main()
{
	scanf("%d", &n);
	pow2[0] = 1;
	for(int i = 1; i <= n; ++i) pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
	for(int i = 1; i <= n; ++i) {
		scanf("%lld%lld", &A[i], &B[i]);
		if(B[i] < 0) A[i] *= -1, B[i] *= -1;
		if(!A[i] && !B[i]) K[make_pair(0, 0)] += 1;
		else if(!A[i]) K[make_pair(0, 1)] += 1;
		else if(!B[i]) K[make_pair(1, 0)] += 1;
		else {
			long long t = gcd(A[i] > 0 ? A[i] : -A[i], B[i]);
			K[make_pair(A[i] /= t, B[i] /= t)] += 1;
		}
	}
	int ans = 1;
	for(int i = 1; i <= n; ++i) {
		if(!A[i] || !B[i]) continue;
		long long t1 = K[make_pair(A[i], B[i])];
		long long t2 = K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))];
		if(!t1) continue;
		K[make_pair(A[i], B[i])] = K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))] = 0;
		if(t1 && t2) ans = 1LL * ans * (pow2[t1] + pow2[t2] - (t1 && t2 ? 1 : 0)) % mod;
		else ans = 1LL * ans * pow2[t1] % mod;
	}
	ans = (ans - 1 + mod) % mod;
	if(K[make_pair(0, 1)] || K[make_pair(1, 0)]) ans = 1LL * ans * (pow2[K[make_pair(0, 1)]] + pow2[K[make_pair(1, 0)]] - (K[make_pair(0, 1)] && K[make_pair(1, 0)] ? 1 : 0)) % mod;
	int ans2 = 0;
	if(K[make_pair(0, 0)] || K[make_pair(1, 0)] || K[make_pair(0, 1)]) {
		ans2 = 0;
		ans2 = (ans2 + K[make_pair(0, 0)]) % mod;
		ans2 = (ans2 + pow2[K[make_pair(1, 0)]] - 1) % mod;
		ans2 = (ans2 + pow2[K[make_pair(0, 1)]] - 1) % mod;
	}
	printf("%d\n", (ans + ans2) % mod);
	return 0;
}


Measured memory_bytes: 32504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

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

    int count[3] = {0, 0, 0};
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(a % 4 == 0){
            count[0]++;
        }else if(a % 2 == 0){
            count[1]++;
        }else{
            count[2]++;
        }
    }

    if(count[2] <= count[0] + (count[1] == 0 ? 1 : 0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> A(n+1, 0);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            A[a]++;
        }
    }
    int ans = 0;
    for(int i = 1; i < n+1; i++){
        if(A[i] == 0){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
def lower_bound(ary, x)
  i = ary.bsearch_index { |y| x <= y }
  i ? i : ary.size
end

def upper_bound(ary, x)
  i = ary.bsearch_index { |y| x < y }
  i ? i : ary.size
end

N = gets.to_i
a_list = N.times.map { gets.to_i }
list = []
a_list.each do |a|
  i = lower_bound(list, a)
  if i == 0
    list.unshift(a)
  else
    list[i - 1] = a
  end
end
puts list.size


Measured memory_bytes: 3892
#include <iostream>
using namespace std;
typedef long long ll;
ll M = 1e9 + 7;
int main()
{
    int n, k;
    ll ans = 0;
    auto sum = [](ll n) -> ll {return ( ( (n%M)*((n+1)%M) / 2 ) % M );};
    cin >> n >> k;
    for(int i = k; i <= n+1; i++) {
        ans += sum(n) - sum(n-i) - sum(i-1) + 1;
        while(ans < 0) ans += M;
        ans %= M;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
N = int(input())
S = input()
count = []
for i in range(1, N):
    z = []
    x = list(set(S[:i]))
    y = list(set(S[i:]))
    for j in x:
        z += filter(lambda str: str == j, y)
    count.append(len(z))
print(max(count))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z,cnt=0;
    scanf("%d%d%d",&x,&y,&z);
    x-=z;
    for(int i=x;i>=y+z;i-=y+z) cnt++;
    printf("%d\n",cnt);
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <algorithm>
#include <numeric>
#include <cassert>

using namespace std;

char s[10000];

int Abs(int x) {
  return (x < 0) ? -x : x;
}

int main(void) {
  scanf("%s", s);
    
  int n = strlen(s);
  
  vector<vector<int>> d(2);
  int at = 0, sum = 0;
  for (int i = 0; i <= n; i++) {
    if (s[i] == 'F') {
      sum++;
    } else {
      d[at].push_back(sum);
      at ^= 1;
      sum = 0;
    }
  }

  int x, y;
  scanf("%i %i", &x, &y);
  
  if (s[0] == 'F') {
    x -= d[0][0];
    d[0].erase(begin(d[0]));
  }
    
  vector<int> targets = {x, y};
  for (int a = 0; a < 2; a++) {
    auto& s = d[a];    
    int m = int(s.size());
        
    vector<vector<int>> f(m+1, vector<int>(2*n+1));
    f[0][n] = 1;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j<= 2*n; j++) {
        if (f[i][j]) {
          if (j + s[i] <= 2*n) f[i+1][j+s[i]] = 1;
          if (j - s[i] >= 0) f[i+1][j-s[i]] = 1;
        }
      }
    }
    
    if (!f[m][n+targets[a]]) {
      puts("No");
      return 0;
    }
  }
  
  puts("Yes");
  
  return 0;
}

Measured memory_bytes: 246528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int main() {
  int N;
  cin >> N;
  int a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int streak = 1;
  int ans = 0;
  for (int i = 1; i < N; i++) {
    if (a[i-1] == a[i]) {
      streak++;
    } else {
      ans += streak / 2;
      streak = 1;
    }
  }
  ans += streak / 2;
  cout << ans << endl;
  return 0;
}

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

const long long mod = 1e9+7;
const int MAX = 4000005;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
	long long int n,k;
	cin >> n >> k;
	COMinit();
	if(k>=n-1){
		cout << COM(n+n-1,n);
	}
	else{
		long long int ans=1;
		for(int i=1;i<=k;i++){
			ans+= (COM(n,i)*COM(n-1,i)%mod);
			ans %= mod;
		}
		cout << ans;
	}
}

Measured memory_bytes: 97304
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
const int MAXN = 200000 + 10;
int ret[MAXN];
pii items[MAXN];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int val;
    for (int i = 0; i < n; i++) {
        cin >> val;
        items[i] = {val, i};
    }
    sort(items, items+n);
    for (int i = 0; i < n; i++) {
        int mid = n / 2;
        if (items[i].first >= items[mid].first) {
            mid--;
        }
        ret[items[i].second] = items[mid].first;
    }
    for (int i = 0; i < n; i++) {
        cout << ret[i] << '\n';
    }


    return 0;
}

Measured memory_bytes: 4608
def main():
    n = int(input())
    A = input()
    B = input()
    C = input()
    ans = 0
    for a in zip(A, B, C):
        if len(set(a)) == 2:
            ans += 1
        elif len(set(a)) == 3:
            ans += 2
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<char> s(3), t(3);
  for (int i = 0; i < 3; i++)
    cin >> s.at(i);
    for (int i = 0; i < 3; i++)
      cin >> t.at(i);//入力完了
  int counter = 0;
    for (int i = 0; i < 3; i++)
      if (s.at(i) == t.at(i))
        counter++;
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
  int N, ans=0;
  cin >> N;
  vector<int> stick(N);
  for(int i=0;i<N;i++){
    cin >> stick[i];
  }  
  sort(stick.begin(), stick.end());
  for(int i=1;i<N-1;i++){
    for(int j=0;j<i;j++){
      for(int k=i+1;k<N;k++){
        if(stick[k] >= stick[i]+stick[j]){
          break;
        }  
        ans++;
      }  
    }  
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String args[]) throws Exception {
    Scanner sc=new Scanner(System.in);
    
	
		    int n=sc.nextInt();
		    int d=sc.nextInt();
		    long count=0;
		  for(int i=0;i<n;i++){
		      int x=sc.nextInt();
		      int y=sc.nextInt();
		      double ans = Math.sqrt(Math.pow(x,2) + Math.pow(y,2));
		      if(ans<=d){
		          count+=1;
		      }
		  }
		  System.out.println(count);
		
    }
}

Measured memory_bytes: 48964
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

bool check(vector<pii> &px, int w){
    vector<int> a(w+1, 0);
    for(auto &p: px){
        ++a[p.fi];
        --a[p.se];
    }
    partial_sum(a.begin(), a.end(), a.begin());
    rep(i, w)if(a[i] == 0) return false;
    return true;
}

int main(){
    int n, w, h;
    scanf("%d%d%d", &n, &w, &h);
    vector<pii> px(n), py(n);
    rep(i, n){
        int x, y, d;
        scanf("%d%d%d", &x, &y, &d);
        px[i] = {max(0, x-d), min(w, x+d)};
        py[i] = {max(0, y-d), min(h, y+d)};
    }
    puts(check(px, w) || check(py, h) ? "Yes" : "No");
}


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

int main() {
  int N, M, start, end;
  vector<int> roads(N);
  
  cin >> N >> M;
  
  for (int i = 0; i < M; i++) {
    cin >> start >> end;
    roads.at(start-1) += 1;
    roads.at(end-1) += 1;
  }
  
  for (int i = 0; i < N; i++) {
    cout << roads.at(i) << endl;
  }
}

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

}

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

fn main(){
    let mut n = read_as_string().chars().map(|x| x.to_digit(10).unwrap() as usize).collect::<Vec<usize>>();
    n.reverse();

    let mut pay_num = 0;
    let mut curry = false;
    for i in 0..n.len(){
        let d;
        if curry{
            d = n[i] + 1;
        }else{
            d = n[i];
        }


        if d > 10 {
            return;
        }
        if d == 10{
            curry = true;
            continue;
        }

        // if d < 5{
        //     pay_num += d;
        //     curry = false;
        // }else{
        //     pay_num += 10-d;
        //     curry = true;
        // }

        if d < 5{
            pay_num += d;
            curry = false;
        }else if d == 5{
            if i < n.len()-1{
                if 4 < n[i+1]{
                    pay_num += 10-d;
                    curry = true;
                }else{
                    pay_num += d;
                    curry = false;
                }
            }else{
                pay_num += d;
                curry = false;
            }
        }else{
            pay_num += 10-d;
            curry = true;
        }
    }

    if curry{
        pay_num += 1;
    }

    println!("{}", pay_num);
}


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

#define int long long



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


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

using namespace std;

int main(void) {
  int n;
  cin >> n;

  for(int i = n; i >= 1; i--) {
    if(sqrt(i) - round(sqrt(i)) == 0) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
long long nn,mm;
long long ans=1;

using namespace std;
long long a[1000001][2];
long long tot;
inline void prim()
{
	long long sq=sqrt(mm)+1,cnt;
	for(long long i=2;i<=sq;i++)
	if(mm%i==0)
	{
		tot++;
		cnt=0;
		a[tot][1]=i;
		while(mm%i==0)
		{
			cnt++;
			mm/=i;
		}
		a[tot][0]=cnt;
	}
}
long long kuai(long long kk,long long pp)
{
	long long anss=1,tmp=kk;
	for(long long i=pp;i;i>>=1)
	{
		if(i&1ll)
		{
			anss=anss*tmp;
		}
		tmp=tmp*tmp;
	}
	return anss;
}
/*
void did(long long mm)
{
	for(long long i=1;i<=1000001;i++)
	{
		long long bs=0;
		while(mm%prim[i]==0)
		{
			mm=mm/prim[i];
			bs++; 
		}
		long long ph=bs/nn;
		ans=ans*kuai(prim[i],ph);
		if(mm==1||prim[i+1]==0)
		{
			break;
		}
	}
}
*/
signed main()
{
	cin>>nn>>mm;
//	prime();
//	did(mm);
	if(nn==1)
	{
		cout<<mm<<endl;
		return 0;
	}
	a[++tot][1]=1;a[tot][0]=nn;
	prim();
	for(long long i=tot;i>=1;i--)
	if(a[i][0]>=nn)
	{
		long long tmp=a[i][0]/nn;
		ans*=kuai(a[i][1],tmp);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 400400;
const int N = 100100;
const int A = 27;

struct Node {
  Node *to[A];
  int sz;
  int fin;

  Node() {
    fill(to, to + A, nullptr);
    sz = 0;
    fin = 0;
  }
} pool[M];
int last = 0;
Node *root;

int cnt[N][A][A], low[N];
int n;
string s[N];


Node *getNode() {
  return pool + last++;
}

void add(string s) {
  Node* cur = root;
  for (char c : s) {
    int x = c - 'a';
    cur->sz++;
    if (cur->to[x] == nullptr)
      cur->to[x] = getNode();
    cur = cur->to[x];
  }
  cur->sz++;
  cur->fin++;
}

void calc(string s, int id) {
  Node *cur = root;
  for (char c : s) {
    int x = c - 'a';

    for (int k = 0; k < A; ++k)
      if (cur->to[k]) 
        cnt[id][x][k] += cur->to[k]->sz;

    low[id] += cur->fin;
    cur = cur->to[x];
  }
}

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


void kill() {
  root = getNode();
  for (int i = 0; i < n; ++i)
    add(s[i]);
  for (int i = 0; i < n; ++i)
    calc(s[i], i);

  int q;
  cin >> q;
  while (q--) {
    int k;
    string ord;
    cin >> k >> ord;
    --k;
    int ans = low[k];
    for (int i = 0; i < (int) ord.length(); ++i)
      for (int j = 0; j < i; ++j) {
        int x = ord[i] - 'a';
        int y = ord[j] - 'a';
        ans += cnt[k][x][y];
      }
    cout << ans + 1 << "\n";
  }
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 379008
#include <iostream>

using namespace std;

void solve()
{
	int count = 0;
	int n;
	while (cin >> n, n)
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if (count)
		{
			cout << endl;
		}
		++count;
		int result = a * 10 + b * 50 + c * 100 + d * 500 - n;
		int coin[4] = {0};
		coin[3] = result / 500;
		result -= coin[3] * 500;
		coin[2] = result / 100;
		result -= coin[2] * 100;
		coin[1] = result / 50;
		result -= coin[1] * 50;
		coin[0] = result / 10;
		result -= coin[0] * 10;
		if (a - coin[0] > 0)
		{
			cout << 10 << " " << a - coin[0] << endl;
		}
		if (b - coin[1] > 0)
		{
			cout << 50 << " " << b - coin[1] << endl;
		}
		if (c - coin[2] > 0)
		{
			cout << 100 << " " << c - coin[2] << endl;
		}
		if (d - coin[3] > 0)
		{
			cout << 500 << " " << d - coin[3] << endl;
		}
	}
}

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

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 1e9 + 7;

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n;
    string s;
    cin >> n >> s;
    int l = 0, r = n - 1;
    int cnt = 0;
    while (1) {
        while (l+1 < n && s[l] == 'R') l++;
        while (r-1 >= 0 && s[r] == 'W') r--;
        if (l >= r) break;
        cnt++;
        l++;
        r--;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int x,a;
cin >> x >> a;
if(x<a) {
  cout << "0" << endl;
} else {
  cout << "10" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n; cin>>n;
    map<string,ll>mp;
    rep(i,n){
        string s; cin>>s;
        mp[s]++;
    }
    ll m=0;
    for(auto p:mp) if(m<p.second) m=p.second;
    for(auto p:mp) if(p.second==m) cout<<p.first<<endl;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

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 int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;

int N,cnt[200005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N-1){
		int a;cin>>a;a--;cnt[a]++;
	}
	rep(i,N)cout<<cnt[i]<<"\n";
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
    int n, ans;
    cin >> n;
    vector<int> l(n);
    rep(i, n){
        cin >> l[i];
    }
    ans = 0;
    int right = 0, left = 0, mid = 0;
    sort(l.begin(), l.end(), greater<>());
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            right = n;
            left = j;
            while(right - left > 1){
                mid = (right + left) / 2;
                if(l[i] < l[j] + l[mid] && l[j] < l[i] + l[mid] && l[mid] < l[i] + l[j]){ //OK
                    left = mid;
                }else{ //NG
                    right = mid;
                }
            }
            //cout << i << "," << j << ">>" << left << "," << right << endl;
            ans += (left - j);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import collections

def gcd(m, n):
    while n != 0:
        m, n = n, m%n
    return m

def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a, b = map(int, input().split())
n = gcd(a,b)
c = collections.Counter(prime_factorize(n))
print(len(c))

Measured memory_bytes: 3316