akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

struct data {
  int index;
  char orig;
  char update;
};

int main(){
  int N,Q;
  scanf("%d", &N);
  std::string s;
  std::cin >> s;
  scanf("%d", &Q);
  std::vector<int > type(Q), I(Q), l(Q), r(Q);
  std::vector<char > c(Q);
  for (int i=0; i<Q; i++){
    std::cin >> type[i];
    if (type[i]==1){
      std::cin >> I[i] >> c[i];
      I[i]--;
    } else {
      std::cin >> l[i] >> r[i];
      l[i]--;
      r[i]--;
    }
  }
  std::vector<int > cumsum[26];
  for (int i=0; i<26; i++){
    cumsum[i].push_back(0);
  }
  for (int i=0; i<N; i++){
    int val = int(s[i])-int('a');
    for (int j=0; j<26; j++){
      if (j==val){
	cumsum[j].push_back(cumsum[j][cumsum[j].size()-1]+1);
      } else {
	cumsum[j].push_back(cumsum[j][cumsum[j].size()-1]);
      }
    }
  }

  std::vector<data> change[26];
  for (int i=0; i<Q; i++){
    if (type[i]==1) {
      change[int(s[I[i]])-int('a')].push_back((data){I[i], s[I[i]], c[i]});
      change[int(c[i])-int('a')].push_back((data){I[i], s[I[i]], c[i]});
      s[I[i]]=c[i];
    } else {
      int ans=0;
      for (int k=0; k<26; k++){
	//printf("k=%d\n", k);
	int count = 0;
	count = cumsum[k][r[i]+1]-cumsum[k][l[i]];
	for (int j=0; j<change[k].size(); j++){
	  int index = change[k][j].index;
	  int orig = int(change[k][j].orig)-int('a');
	  int update = int(change[k][j].update)-int('a');
	  if (index<l[i] || index>r[i]) continue;
	  if (k==orig){
	    count--;
	  }
	  if (k==update){
	    count++;
	  }
	  }
	//printf("count=%d\n", count);
	if (count>0) ans++;
      }
      std::cout << ans << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 54492
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int main(void)
{
    ll n;
    cin >> n;
    map<ll, int> c;
    ll k = (ll)floor(sqrt((double)n)+EPS);
    for (ll i = 2; i <= k; ++i) {
        while(n % i == 0) {
            n /= i;
            c[i]++;
        }
    }
    if (n != 1)
        c[n]++;
    int ret = 0;
    for (auto &p : c) {
        int n = p.second;
        int v = 0;
        for (int m = 1; m*(m+1)/2 <= n; m++) {
            v = m;
        }
        assert(v > 0);
        ret += v;
    }
    cout << ret << endl;
    return 0;
}


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

int main(){
    const int N = 1e9;
    int h,n;
    cin>>h>>n;
    vector<int> dp(h+1,N);
   dp[0] = 0;
    while(n--){
        int val,cost;
        cin>>val>>cost;
        for(int i = 0; i <= h; i++){
            int j = min(i+val,h);
            dp[j] = min(dp[j],dp[i]+cost);
        }
    }
    cout<<dp[h];
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N, ll mod){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % mod, N / 2, mod);
  else return Pow(A * A % mod, N / 2, mod) * A % mod;
}


ll DP[int(2e5 + 5)];
ll Solve(int num){
  if (num == 0) return DP[0] = 0;
  if (DP[num] > 0) return DP[num];

  int cnt = 0, now = num;
  while (now > 0){
    if (now % 2 != 0) cnt++;
    now /= 2;
  }
  return DP[num] = Solve(num % cnt) + 1;
}


ll ans1, ans2;

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

  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (S[i] == '1') cnt++;
  }

  ll now = 1;
  for (int i = N - 1; i >= 0; i--){
    if (S[i] == '1'){
      ans1 += now; ans1 %= cnt + 1;
    }
    now *= 2; now %= cnt + 1;
  }

  if (cnt > 1){
    now = 1;
    for (int i = N - 1; i >= 0; i--){
      if (S[i] == '1'){
        ans2 += now; ans2 %= cnt - 1;
      }
      now *= 2; now %= cnt - 1;
    }
  }

  for (int i = 0; i < N; i++){
    if (S[i] == '0') {
      now = ans1;
      now += Pow(2, N-1-i, cnt+1);
      now %= cnt + 1;
    }else{
      now = ans2;
      if (cnt == 1){
        cout << 0 << endl;
        continue;
      }
      now -= Pow(2, N-1-i, cnt-1);
      now %= cnt-1;
      if (now < 0) now += cnt - 1;
    }

    cout << Solve(now) + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 4544
n=int(input())
s=input()
mod=10**9+7

def get_num(s, iii):
    if s=="B":
        for i in range(iii,-1,-1):
            if i%2==1:
                return i
    else:
        for i in range(iii,-1,-1):
            if i%2==0:
                return i

ans=1
thread=1 if s[0]=="B" else 0
for i in range(1, 2*n):
    cnt=i+1 if i<n else 2*n-i
    if s[i]=="B":
        if thread%2==0:
            thread+=1
        else:
            ans*=thread
            thread-=1
    elif s[i]=="W":
        if thread%2==0:
            ans*=thread
            thread-=1
        else:
            thread+=1
    ans%=mod

if thread==0:
    for i in range(1, n+1):
        ans*=i
        ans%=mod
    print(ans)
else:
    print(0)



Measured memory_bytes: 3572
#include <stdio.h>

int main(){

int a,b;

scanf("%d %d",&a,&b);

if(a < b){

printf ("a < b\n");

}

else if( a > b ){

printf ("a > b\n");

}

else if(a == b){

printf ("a == b\n");

}
 return 0;

}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N,K; cin >> N >> K;
  vector<ll> h(N);
  ll ans = 0;
  REP(i,N) {
    cin >> h[i];
    if(h[i]>=K) ans++;
  }
  cout << ans << endl;
} 

Measured memory_bytes: 1024
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        xs: [usize; n]
    }
    let mut xs = xs.iter().enumerate().collect::<Vec<_>>();
    xs.sort_by_key(|&(_, v)| v);
    let mut ans = vec![];
    for i in 0..n {
        let idx = xs[i].0;
        if i < n/2 {
            ans.push((idx, xs[n/2].1))
        } else {
            ans.push((idx, xs[n/2-1].1))
        }
    }
    ans.sort_by_key(|&(i, _)| i);
    for &(_, v) in ans.iter() {
        println!("{}", v);
    }
}


Measured memory_bytes: 18672
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (n); i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;
 
template <class T> inline void read(T &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar());
  if (f) x = -x;
}
const int N = 1e6 + 233;
struct E {
  int nxt, to;
}e[N << 2];
int head[N], e_cnt = 0, du[N];
int n, ans, dif[N], tot[N], son[N], res[N];
inline void add(int x, int y) {
  e[++ e_cnt] = (E) {head[x], y}; head[x] = e_cnt; ++ du[y];
}
 
inline void U(int x, int y) {
  dif[x] += res[y] != 0;
  tot[x] += res[y];
  son[x] ++;
  res[x] = tot[x] + max(0, son[x] - 1 - dif[x]);
}
 
inline void D(int x, int y) {
  dif[x] -= res[y] != 0;
  tot[x] -= res[y];
  son[x] --;
  res[x] = tot[x] + max(0, son[x] - 1 - dif[x]);
}
 
inline void dfs(int u, int fat) {
  travel (i, u) {
    int v = e[i].to; if (v != fat) {
      dfs(v, u);
      U(u, v);
    }
  }
}
 
inline void DP(int u, int fat) {
  ans = min(ans, res[u] + 1);
  travel (i, u) {
    int v = e[i].to; if (v != fat) {
      D(u, v); U(v, u);
      DP(v, u);
      D(v, u); U(u, v);
    }
  }
}
 
int main(void) {
  read(n); ans = n;
  rep (i, n - 1) {
    int x, y; read(x); read(y); ++ x; ++ y;
    add(x, y); add(y, x);
  }
  if (n == 1) {
    cout << "0\n";
    return 0;
  }
  dfs(1, 0); DP(1, 0);
  cout << ans << "\n";
}

Measured memory_bytes: 22144
#include<iostream>
using namespace std;
int main()
{
    long n, h, a, sum=0;
    cin >> h >> n;
    while(n--)
    {
        cin >> a;
        sum+=a;
        if(sum>=h)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){ 
  int n;
  cin >> n;
  set<int> st;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    st.insert(a);
  }
  if (st.size() % 2 == 0) cout << st.size() - 1 << endl;
  else cout << st.size() << endl;
  return 0;
} 

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    
    int r1 = abs(b-a) + abs(c-b);
    int r2 = abs(c-a) + abs(b-c);
    int r3 = abs(b-a) + abs(a-c);
    int r4 = abs(b-c) + abs(c-a);
    int r5 = abs(c-a) + abs(a-b);
    int r6 = abs(c-b) + abs(b-a);
    cout << min({r1, r2, r3, r4, r5, r6}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    int v[] = {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};
    ll k;
    cin >> k;
    cout << v[k - 1] << endl;
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N,H = ilint()
H = [0]+H[:]
H = [-(H[i+1]-H[i]) for i in range(N)]+[INF]
ans = 0
for l in range(N):
    while H[l]<0:
        r = 0
        while r<N and H[r]<=0:
            r += 1
        tmp = min(-H[l],H[r])
        ans += tmp
        H[l] += tmp
        H[r] -= tmp
print(ans)

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

int main() {
	// your code goes here
	int m,p,tmp;
	while(cin >> m >> p && m!=0){
		vector<int> v;
		int sum=0;
		for(int i=0;i<m;i++){
			cin >> tmp;
			v.push_back(tmp);
		}
		sort(v.begin(),v.end());
		int mods=m%p;
		for(int i=0;i<mods;i++)
		sum+=v[i];
		for(int i=mods;i<v.size();i++){
			if((i-mods)%p==0);
			else
				sum+=v[i];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC141
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            long q = s[2];
            long k = s[1];
            int n = s[0];
            int[] parti = new int[n];
            for(int i=0;i<q;i++){
                int a = int.Parse(ReadLine());
                parti[a-1]++;
            } 
            for(int i =0;i<n;i++){
                if(k-(q-parti[i])<=0){
                    WriteLine("No");
                }else{
                    WriteLine("Yes");
                }

            }
        }
    }
}


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

int pnjg, j;
string input, output;

int main (){
    cin>>input;
    pnjg=input.length();
    if (pnjg%2==0){
        pnjg--;
    }
    for (int i=0; i<=pnjg; i+=2){
        output+=input[i];
        j++;
    }
    cout<<output<<endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,ans=0,c,x,i,j;
    cin>>n>>k;
    int a[n+1];
    for(i=0;i<=n+1;i++)
    a[i]=0;
    for(i=1;i<=k;i++)
    {
       cin>>c;
       for(j=0;j<c;j++)
       {
           cin>>x;
           a[x]++;
       }
       
    }
    for(i=1;i<=n;i++)
    {
        if(a[i]==0)
        ans++;
    }
    cout<<ans;
  return 0;
}

Measured memory_bytes: 3624
void main()
{
    long n, q;
    rdVals(n, q);

    auto st = SegTree!("a < b ? a : b", long, (1L<<31)-1)(n);

    foreach (i; 0 .. q)
    {
        long com, x, y;
        rdVals(com, x, y);

        if (com) st.query(x, y+1).writeln;
        else st.update(x, y);
    }
}

struct SegTree(alias pred, T, T init)
{
    import core.bitop;
    alias F = binaryFun!pred;

    long n;
    T[] tree;

    this(long n)
    {
        this.n = n == 1 ? 1 : 1L << bsr(n-1) + 2;
        tree.length = this.n << 1;
        tree[] = init;
    }

    ref T opIndex(long idx) pure nothrow
    {
        return tree[idx+this.n];
    }

    void update(long idx, T x)
    {
        idx += this.n;
        this.tree[idx] = x;
        while (idx >>= 1)
        {
            tree[idx] = F(tree[(idx<<1)], tree[(idx<<1)+1]);
        }
    }

    T query(long x, long y)
    {
        T l = init, r = init;
        for (x += this.n, y += this.n; x < y; x >>= 1, y >>= 1)
        {
            if (x & 1) l = F(l, tree[x++]);
            if (y & 1) r = F(tree[--y], r);
        }
        return F(l, r);
    }
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;


Measured memory_bytes: 7384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    map<string, int>mp;
    string s;
    for(int i=0;i<n;++i){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3632
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  int a = 1, b = 1;
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    int m = max((a - 1) / c + 1, (b - 1) / d + 1);
    a     = m * c;
    b     = m * d;
  }
  cout << a + b << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		new Main().run();
	}

	public void run() {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		scanner.nextLine();
		final char[] charSequence = scanner.nextLine().toCharArray();

		final Map<Integer, MyLong> wordCount = new HashMap<>();
		for (int index = 0; index < counter; index++) {
			wordCount.computeIfAbsent(Integer.valueOf(charSequence[index]) % 26, e -> new MyLong()).increment();
		}

		final List<MyLong> longs = new ArrayList<>(wordCount.values());

		long answer = 1;
		for (MyLong value : longs) {
			answer *= value.getValue() + 1;
			answer %= 1000000007;
		}

		--answer;
		System.out.println(answer);

		scanner.close();

	}

	class MyLong {
		private long value;

		public MyLong() {
			this.value = 0;
		}

		public void increment() {
			this.value++;
		}

		public long getValue() {
			return this.value;
		}
	}

}

Measured memory_bytes: 29756
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}	
pair<pair<int,int>,int> p[114514];
int ans[114514];
signed main(){
	ic(n) ic(m)
	rep(0,i,m)cin>>p[i].f.f>>p[i].f.s;	
	rep(0,i,m)p[i].s=i;
	sort(p,p+m);
	int sum=1;
	rep(0,i,m){
		ans[p[i].s]=p[i].f.f*1000000+sum;
		if(p[i].f.f!=p[i+1].f.f)sum=1;
		else sum++;
	}
	rep(0,i,m){
		rep(0,j,12-keta(ans[i]))cout<<0;
		c(ans[i])	
	}	
}	


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    pair<int, int> stores[N];

    long long int cost, limit;
    for(int i = 0; i < N; i++)
    {
        cin >> cost >> limit;
        stores[i] = make_pair(cost, limit);
    }

    sort (stores, stores + N);
    
    long long int price = 0, to_buy = 0;
    for (int i = 0; i < N && M > 0; i++)
    {   
        to_buy = min(M, stores[i].second);
        M -= to_buy;
        price += to_buy * stores[i].first;
    }

    cout << price;
}


Measured memory_bytes: 1024
N,K = map(lambda i: int(i),input().split())

def Base_10_to_n(X, n):
    if (int(X / n)):
        return Base_10_to_n(int(X / n), n) + str(X % n)
    return str(X % n)

x2 = Base_10_to_n(N, K)
print(len(x2))

Measured memory_bytes: 3060
n = gets.to_i
# 末尾3文字と文字列の数をメモ
memo = Array.new(n + 1) { Hash.new(0) }
keys = []
queue = [""]
until queue.empty?
  string = queue.shift
  if string.size == 3
    keys << string if string != "AGC" && string != "ACG" && string != "GAC"
  else
    queue.push(string + "A")
    queue.push(string + "C")
    queue.push(string + "G")
    queue.push(string + "T")
  end
end
values = Array.new(61, 1)
ary = [keys, values].transpose
# 3文字目到達時の、末尾3文字(key)と文字列の数(value)を保存
memo[3] = ary.to_h

(3...n).each do |index|
  memo[index].each do |key, value|
    [key + "A", key + "C", key + "G", key + "T"].each do |string|
      unless string =~ /AGC.|GAC.|ACG.|.AGC|.GAC|.ACG|A.GC|AG.C/
        memo[index + 1][string[1, 3]] += value
      end
    end
  end
end

puts memo[n].values.inject(:+) % (10 ** 9 + 7)


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector <long double> data;
    for(int i=1;i<=17;i++){
        long double a = powf(2,i);
        data.push_back(a);
        //cout<<data[i-1]<<endl;
    }
    //cout<<data.size()<<endl;
    //cout<<data[0]<<endl;
    long double n,k; cin>>n>>k;
    long double ans=0.0;
    for(int i=1;i<=n;i++){
        
        long double need=0;
        if(i>=k) {ans += (1.0/n); continue;}
        for(long double j=0;j<=16;j++){
            //cout<<data[j]<<endl;
            if(i*data[j] >=k) {need = j+1.0; break;}
        }
        //cout<<need<<endl;
        ans+= (1.0/n)* powl(0.50,need);
    }
   
    cout << std::setprecision(20) << ans;
}

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

using namespace std;
typedef long long int ll;

void solve()
{
	int n, d, y;
	cin >> n >> d >>y;
	if(n <= d*y) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3648
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static int n,m,sum;
	static int cnt1=0,cnt2=0;
	static int[]id;
	static int[]num;
	static HashMap<Integer,Boolean> map=new HashMap<Integer,Boolean>();
	static int[][] dp;
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		n=cin.nextInt();
		id=new int[n];
		
		char[] s=cin.next().toCharArray();
		char[] sss=new char[s.length];
		for(int i=0;i<sss.length;i++){
			sss[i]=s[(s.length-i-1)];
		}
//		System.out.println(s);
//		System.out.println(sss);
		for(int i=0;i<sss.length;i++){
			if(sss[i]=='*'){
				if(i%2==0){
					cnt1++;
				}
				else{
					cnt2++;
				}
			}
			else{
				int b=sss[i]-'0';
				if(i%2==0){
					sum=sum+b;
				}
				else{
					int a=b*2;
					if(a>=10){
						sum+=a%10;
						sum+=a/10;
					}
					else{
						sum+=a;
					}	
				}
				sum=sum%10;
			}
		}
//		System.out.println(cnt1+" "+cnt2+" "+sum);
		dp=new int[cnt1+cnt2][100];
		for(int i=0;i<cnt1+cnt2;i++){
			Arrays.fill(dp[i],-1);
		}
		m=cin.nextInt();
		num=new int[m];
		for(int i=0;i<m;i++){
			num[i]=cin.nextInt();
		}
		System.out.println(bt(0,sum));
	}
	static int bt(int cnt,int sum){
		if(cnt==cnt1+cnt2){
//			System.out.println(cnt+" "+sum);
			if((sum%10)==0){
				return 1;
			}
			else{
				return 0;
			}
		}
		if(dp[cnt][sum]!=-1){
//			System.out.println(dp[cnt][sum]);
			return dp[cnt][sum];
		}
		dp[cnt][sum]=0;
		int re=0,orgSum=sum;
		for(int i=0;i<num.length;i++){
			int add=0;
			if(cnt>=cnt1){
				int a=num[i]*2;
				if(a>=10){
					add+=a%10;
					add+=a/10;
				}
				else{
					add+=a;
				}
			}
			else{
				add=num[i];
			}
			dp[cnt][orgSum]+=bt(cnt+1,(sum+add)%10);
		}
		return dp[cnt][orgSum];
	}
	static boolean isTrue(){
		int sum=0;
		for(int i=0;i<id.length;i++){
			if(i%2==0){
				sum+=id[i];
			}
			else{
				int a=id[i]*2;
				if(a>=10){
					sum+=a%10;
					sum+=a/10;
				}
				else{
					sum+=a;
				}
			}
		}
		return (sum%10)==0;
	}
}

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

using namespace std;
int main(){
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0 ; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    ll mx = a[0];
    for (int i = 0; i < n; i++) {
        ans += max(0LL, mx - a[i]);
        mx = max(mx, a[i]);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 4844
N = int(input())
L = []

Ans = True

for i in range(N):
    a =input()
    L.append(a)

for j in range(N-1):
    if list(L[j])[-1] != list(L[j+1])[0]:
        Ans = False

for k in range(N):
    if L[k] in L[:k]:
        Ans = False
        
if Ans == True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#include "atcoder/all"
using namespace atcoder;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N, Q;
	cin >> N >> Q;
	vector<int>a(N);
	cin >> a;
	fenwick_tree<int>seg(N);
	REP(i, N) seg.add(i, a[i]);
	while(Q--) {
		int t;
		cin >> t;
		if(t) {
			int l, r;
			cin >> l >> r;
			out(seg.sum(l, r));
		} else {
			int p, x;
			cin >> p >> x;
			seg.add(p, x);
		}
	}
}

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

int main(){
    int a, b;
    stringstream ss;
    string s;

    while(cin >> a >> b){
        ss.clear();
        ss.str("");
        ss << a + b;
        s = ss.str();
        cout << s.length() << endl;
    }
    return 0;

}

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

int N, U[2], M, A[2][500][500];
int sum[2][2][500], f[2], g[2];
vector< tuple< int, int, int > > memo[1000001];
int main()
{
  
  scanf("%d %d %d %d", &N, &U[0], &U[1], &M);

  for(int k = 0; k < 2; k++) {
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < N; j++) {
        scanf("%d", &A[k][i][j]);
        memo[A[k][i][j]].emplace_back(k, i, j);
      }
      sum[k][0][i] = sum[k][1][i] = N; 
    }
    f[k] = g[k] = N;
  }
  
  while(M--) {
    int num;
    scanf("%d", &num);
    for(auto& d : memo[num]) {
      int k, i, j;
      tie(k, i, j) = d;
      U[k] -= --sum[k][0][i] == 0;
      if(N > 1) {
        U[k] -= --sum[k][1][j] == 0;
        if(i == j) U[k] -= --f[k] == 0;
        if(j == N - i - 1) U[k] -= --g[k] == 0;
      }
    }
    if(U[0] <= 0 || U[1] <= 0) {
      if(U[0] <= 0 && U[1] <= 0) break;
      puts(U[1] <= 0 ? "NEKO" : "USAGI");
      exit(0);
    }
  }
  puts("DRAW");
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, m; cin >> n >> m;
    vector<int> s(m), c(m);
    for (int i = 0; i < m; i++) cin >> s[i] >> c[i];

    int b, e;
    if (n == 1) {
        b = 0, e = 10;
    } else { 
        b = 1;
        for (int i = 0; i < n - 1; i++) b *= 10;
        e = b * 10;
    }

    for (int i = b; i < e; i++) {
        bool flag = true;
        for (int j = 0; j < m; j++) {
            if ((i / (int)pow(10, n - s[j])) % 10 != c[j]) flag = false;
        }
        if (flag) {
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(long long val):value((int)(val<0?MOD+val%MOD:val%MOD)){ }

    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const{
        if(value == 0)return 0;
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

mint dp[3002][3002];

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

    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    // iにある文字はto[i]まで運べる(i<=to[i])
    vi to(N);
    iota(all(to), 1);
    rep(i, M) {
        int l, r;
        cin >> l >> r;
        --l;
        smax(to[l], r);
    }
    rep(i, N - 1)smax(to[i + 1], to[i]);

    vi a(N);
    rep(i, N)a[i] = S[i] - '0';

    
    int right = 0;
    dp[0][0] = 1;
    // 1桁ずつ決めていく
    rep(i, N) {
        int x = 0;
        while(right < to[i]) {
            x += a[right++];
        }
        for(int j = 0; j <= N; ++j)if(dp[i][j].toi()) {
            // cntはrightまで自由に移動できる1の数
            int cnt = j + x;
            // ここを1にする
            if(cnt > 0)dp[i + 1][cnt - 1] += dp[i][j];
            // ここを0にする
            if(right - i - 1 >= cnt)dp[i + 1][cnt] += dp[i][j];
        }
    }
    cout << dp[N][0] << endl;
}

Measured memory_bytes: 35456
def rec(i,j)
  @m[i][j]=0
  rec(i,j+1) if j<11 and @m[i][j+1]==1
  rec(i,j-1) if j>0 and @m[i][j-1]==1
  rec(i+1,j) if i<11 and @m[i+1][j]==1
  rec(i-1,j) if i>0 and @m[i-1][j]==1
end
loop do
  @m,c,t=[],0,12
  t.times{@m<<gets.split("").map(&:to_i)}
  t.times{|i|
    t.times{|j|
      if @m[i][j]==1
        rec(i,j);c+=1
      end
    }
  }
  p c
  break if !gets
end

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

#define pb push_back
#define fi first
#define SZ(x) (int((x).size()))
#define se second
#define ll long long
#define pq priority_queue
#define MP make_pair
#define pii pair<int,int>
#define mod 998244353
#define debug(x) cerr<<#x<<"="<<x<<'\n'

string s;
int f[1000010][2];

int main(){
	cin>>s;
	s="0"+s;
	int n=SZ(s)-1;
	f[n][0]=(int)(s[n]-'0');
	f[n][1]=10-f[n][0];
	for (int i=n-1;i>=0;i--) {
		f[i][0]=(int)(s[i]-'0')+f[i+1][0];
		f[i][1]=min(9-(int)(s[i]-'0')+f[i+1][1],f[i+1][0]+10-(int)(s[i]-'0'));
		if (s[i]!='9') f[i][0]=min(f[i][0],(int)(s[i]-'0')+1+f[i+1][1]);
//		debug(f[i][0]),debug(f[i][1]);
	}
	cout<<f[0][0];
	return 0;
}


Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n;
    n = s.size();
    if(n&1)
    {
        cout<<"No\n";
    }
    else
    {
        for(int i=0;i<s.size();i++)
        {
            if(i&1)
            {
                if(s[i]!='i')
                {
                    cout<<"No\n";
                    return 0;
                }
            }
            else
            {
                if(s[i]!='h')
                {
                    cout<<"No\n";
                    return 0;
                }
            }
        }
        cout<<"Yes\n";
    }
    return 0;

}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    ll N, H;
    cin >> N >> H;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    ll X = A[0];

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ++ans;
        H -= max(X, B[i]);
        if (H <= 0) break;
    }

    if (H > 0)
        ans += (H + X - 1) / X;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i <= (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
   string s;
   cin >> s;
   ll k;
   cin >> k;
   int a = 0;
   rep(i,100){
       if(s[i] != '1'){
           a = i;
           break;
       }
   }
   if(k-1 < a) dunk(1);
   else dunk(s[a]);
}

Measured memory_bytes: 384
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0)cout<<b+a<<endl;
    else cout<<b-a<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
  int N;
  int ans[55];
  int pn[100000];

  cin >> N;

  pn[0] = 2;
  pn[1] = 3;
  pn[2] = 5;
  pn[3] = 7;
  int len = 4;

  int lena = 0;

  for (int i = 11; i < 55555; i += 2) {
    bool f = true;
    for (int j = 0; j < len; j++) {
      if (i % pn[j] == 0) {
        f = false;
        break;
      }
    }
    if (f == false) continue;
    pn[len] = i;
    len += 1;

    if (i % 5 != 1) continue;
    ans[lena] = i;
    lena += 1;

    if (lena >= N) break;
  }
  
  cout << ans[0];
  for (int i = 1; i < N; i++) {
    cout << " " << ans[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Card {
  char suit, value;
};

#define MAX_N 36

void bubble(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    for (int j = N - 1; j >= i; j--) {
      if (A[j].value < A[j-1].value) {
        Card t = A[j];
        A[j] = A[j-1];
        A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[j].value < A[minj].value)
        minj = j;
    }
    Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0)
      cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for (int i = 0; i < N; i++) {
    if (C1[i].suit != C2[i].suit)
      return false;
  }
  return true;
}

int main() {
  Card C1[MAX_N], C2[MAX_N];
  int N;
  char ch;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }
  for (int i = 0; i < N; i++)
    C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if (isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;



int main(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll flag=-inf;

	if(n < b){
		cout<<(a*n)/b<<endl;
		return 0;
	} 
	else{
		flag = max(a*(b-1)/b,flag);
		flag = max(flag,(a*n)/b-a*(n/b));
	}
	cout<<flag<<endl;
	return 0;
}

Measured memory_bytes: 3600
import bisect


def memoize(f):
    cache = {}

    def func(x):
        if x not in cache:
            cache[x] = f(x)
        return cache[x]

    return func


@memoize
def get_bisect(y):
    return bisect.bisect(vy, (y,))


n = int(input())
vx, vy = [], []
for _ in range(n):
    x1, y1, x2, y2 = map(int, input().split())
    if x1 == x2:
        if y1 > y2:
            y1, y2 = y2, y1
        vx.append((x1, y1, y2))
    else:
        if x1 > x2:
            x1, x2 = x2, x1
        vy.append((y1, x1, x2))
vy.sort()

ans = 0

for x, y1, y2 in vx:
    it1, it2 = get_bisect(y1), get_bisect(y2 + 1)
    ans += sum(1 for y, x1, x2 in vy[it1:it2] if x1 <= x <= x2)

print(ans)

Measured memory_bytes: 29588
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

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

int main() {
	int X, A;
	cin >> X >> A;

	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
# author:  Taichicchi
# created: 25.09.2020 23:35:11

import sys

a, b, c, x, y = map(int, input().split())

ans = 10 ** 18

for m in range(max(x, y) + 1):
    tmp = a * max(0, (x - m)) + b * max(0, (y - m)) + 2 * m * c
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 9104
#include <iostream>
#include <cstdio>
using namespace std;
 
int main(){
    int a, b;
    char op;
 
    while(1){
        cin >> a >> op >> b;
 
        if(op == '+'){
            cout << a + b << endl;
        }else if(op == '-'){
            cout << a - b << endl;
        }else if(op == '*'){
            cout << a * b << endl;
        }else if(op == '/'){
            cout << a / b << endl;
        }else{
            break;
        }
    }
 
    return(0);
}

Measured memory_bytes: 3080
N,x = map(int,input().split())
A = list(map(int,input().split()))
count = 0
for i in range(1,N):
    diff = A[i-1]+A[i]-x
    if diff > 0:
        if A[i]>=diff:
            A[i]-=diff
            count += diff
        else:
            A[i] = 0
            A[i-1] -= diff - A[i]
            count += diff
print(count)



Measured memory_bytes: 63984
#include<iostream>
#include<string>
#define SA 32
using namespace std;
int main(void){
	string tan;
	cin >> tan;
	int bou,gou,ansa=0;
	bou=tan.size();
	for(int a=0;a<bou;a++){
		if(tan[a]>='A' && tan[a]<='Z')tan[a]+=SA;
	}
	while(1){
		string bin;
		cin>>bin;
		gou=bin.size();
		if(bin=="END_OF_TEXT")break;
		for(int b=0;b<gou;b++){
			if(bin[b]>='A' && bin[b]<='Z')bin[b]+=SA;
		}
		if(tan==bin)ansa++;
	}
	cout << ansa<<endl;
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	char a[33];
	for(int i = 1;i<=9;i++)
	{
		scanf("%c",&a[i]);
		if(a[i]=='\n') i--;
	}
	cout<<a[1]<<a[5]<<a[9];
	return 0;
}

Measured memory_bytes: 256
import math

while(1):
    z=int(raw_input())
    if z==0:
        break
    else:
        k=0
        for x in range(1,z):
            y=int(pow(z**3-x**3,1/3.))
            k=max(k,x**3+y**3)
        print z**3-k

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

#if debug
#include "printer.hpp"
#define dump(a) cerr << #a << "(" << __LINE__ << ") = " << a << endl;
#else
#define dump(...)
#endif

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a, b) for (int i = (b)-1; i >= a; i--)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
const ll mod = 1000000007;

ll pow(ll x, ll y) {
  ll ret = 1, tmp = x;
  while (y) {
    if (y % 2) ret = ret * tmp % mod;
    tmp = tmp * tmp % mod;
    y /= 2;
  }
  return ret;
}

ll inverse(ll x) { return pow(x, mod - 2); }

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

  ll A, B;
  cin >> A >> B;

  cout << A * B / __gcd(A, B) << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
switch = []
for _ in range(M):
  tmp = list(map(int, input().split()))
  switch.append(tmp[1:])
p = list(map(int, input().split()))

from itertools import product
candidate = list(product([0,1], repeat=N))

ans = 0
for cand in candidate:
  flag = True
  for idx, snum in enumerate(switch):
    tmp = 0
    for s in snum:
      tmp += cand[s-1]
    if p[idx] != tmp%2:
      flag = False
      break
  if flag:
    ans += 1
print(ans)

Measured memory_bytes: 9272
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
    ll i,j,n,b,r,c=0;
    cin>>n>>b>>r;
    l1:
    ll val=n/(b+r);
    c=val*(b+r);
    ll val2=n-c;
    if(val2>b)
    val2=b;
    cout<<val*b+val2;
}

Measured memory_bytes: 256
s = input()
Aplace = len(s)-1
Zplace = 0
for i in range(len(s)):
    if s[i]=='A':
        Aplace = min(Aplace, i)
    elif s[i]=='Z':
        Zplace = max(Zplace, i)
print(Zplace-Aplace+1)

Measured memory_bytes: 3516
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a,b;
int main(){
    scanf("%d%d%d",&n,&a,&b);
    if(n==1){
        if(a!=b)printf("0\n");
        else printf("1\n");
        return 0;
    }
    if(a>b)printf("0\n");
    else printf("%lld\n",a+1ll*b*(n-1)-b-1ll*a*(n-1)+1);
}

Measured memory_bytes: 128
N,M= map(int, input().split())
yakusu =[]

for i in range(int(M**(1/2)),0,-1):
    if M % i == 0:
        yakusu.append(i)
        yakusu.append(int(M/i))

yakusu.sort(reverse=True)

for i in yakusu:
    if i <= M/N:
        print(i)
        break

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <climits>
#include <utility>
#include <cmath>

using namespace std;

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define printi(x) printf("%d ", x)
#define printiln(x) printf("%d\n", x)
#define printiarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1])
#define scani(x) scanf("%d", &x)
#define scaniarray(a,n) for(int i=0; i<n; i++){scanf("%d", &a[i]);}
#define scans(str) scanf("%s",str)
#define scanc(ch) scanf("%c", &ch)
#define mk make_pair
#define printd(x) printf("%lf ", x)
#define printdln(x) printf("%lf\n", x)

const double root3 = sqrt(3);

typedef struct {
    double x;
    double y;
} Point;

typedef struct {
    Point p1,p2;
} Line;

const int KochMax = 1;
int EndK;

void Kochcurve(int k, Point a, Point b) {

    if (k == 0){

    } else {
        // p1, p2 から s, t, u を計算
        Point s,t,u;
        s.x = (2*a.x+b.x)/3; s.y = (2*a.y+b.y)/3;
        u.x = (a.x+2*b.x)/3; u.y = (a.y+2*b.y)/3;
        t.x = ((u.x-s.x)-root3*(u.y-s.y)+2*s.x)/2;
        t.y = (root3*(u.x-s.x)+(u.y-s.y)+2*s.y)/2;
        Point point[] = {a, s, t, u, b};

        rep(i,0,3) {
            Kochcurve(k-1,point[i],point[i+1]);
            if(i != 3) {
                printd(point[i+1].x); printdln(point[i+1].y);
            }
        }

    }

}

int main() {
    int n;
    scani(n);
    EndK = n;

    Point p1;
    p1.x = 0.0; p1.y = 0.0;
    Point p2;
    p2.x = 100.0; p2.y = 0.0;
    printd(p1.x); printdln(p1.y);
    Kochcurve(n,p1,p2);
    printd(p2.x); printdln(p2.y);

    return 0;
}



Measured memory_bytes: 2676