akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int m,n,nissu=0;;
	cin >> n >> m ;
	vector<int> a(m);
	
	for(int i=0;i<m;i++)
	{cin >> a.at(i);
		nissu += a.at(i);
	}
	if(n-nissu >= 0)
	{cout << n-nissu << endl;}
     else
	 {cout << "-1" << endl;}

	
  
}


Measured memory_bytes: 3636
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, v = map(int, input().split())
    b, w = map(int, input().split())
    t = int(input())
    dist = abs(a - b)
    sokudo = v - w
    if sokudo <= 0:
        print("NO")
    else:
        T = dist / sokudo
        print("YES" if T <= t else "NO")


if __name__ == '__main__':
    resolve()


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> ans(n), c(n - 1), s(n - 1), f(n - 1);
    rep (i, n - 1) {
        cin >> c[i] >> s[i] >> f[i];
    }
    rep (i, n) {
        int time = 0;
        for (int j = i; j < n - 1; ++j) {
            if (time < s[j]) time = s[j];
            else if (time % f[j] != 0) time = time + f[j] - (time % f[j]);
            time += c[j];
        }
        cout << time << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 256
function main(input) {
  const inputs = input.split('\n')
  const [N, K] = inputs[0].split(' ').map(Number)
  const su = Array.from(new Array(N + 1))
  for(let i = 1; i <= K * 2; i += 2) {
    const d = inputs[i]
    const Ai = inputs[i+1].split(' ')
    // console.log(d, Ai)
    Ai.forEach(e => {
      su[e] = true
    })
  }
  // console.log(su)
  console.log(
    su.slice(1).reduce((h, e) => {
      return e === undefined ? h + 1 : h
    }, 0)
  )
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29976
#include <stdio.h>

int main(void){
	int a,b;
	scanf("%d %d", &a,&b);
	
	if(a < b){
		printf("a < b\n" , a,b);
	}else if(a > b){
		printf("a > b\n" , a,b);
	}else{
		printf("a == b\n" , a,b);
	}
	
	return 0;
}



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

int main()
{
	string s;
	cin>>s;

	if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(s=="Rainy")
        cout<<"Sunny"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int mod = 1e9 + 7;

inline int add(int a, int b) {
  return a+b >= mod ? a+b-mod : a+b;
}

inline int sub(int a, int b) {
  return a >= b ? a-b : a-b+mod;
}

inline int mul(int a, int b) {
  return llint(a)*b % mod;
}

int powmod(int a, llint b) {
  if (b == 0) return 1;
  if (b&1) return mul(a, powmod(a, b-1));
  return powmod(mul(a, a), b/2);
}

const int MAX = 110;

int h[MAX], pw[MAX];

pair<int, int> solve(int a, int b, int s) {
  if (b - a == 1) {
    return {powmod(2, h[a] - s - 1), 0};
  }

  assert(b - a > 1);
  int m = *min_element(h + a, h + b);

  vector<pair<int, int>> v;
  int i = a;
  while (i < b) {
    int j = i;
    while (j < b && (h[i] == m) == (h[j] == m)) j++;
    v.push_back({i, j});
    i = j;
  }

  int f0 = 0, f1 = 1;
  bool first = true;
  for (auto& p: v) {
    int x = p.first, y = p.second;
    if (h[x] != m) {
      if (y - x > 1) {
        auto g = solve(x, y, m);
        if (first) {
          f1 = mul(2, g.first);
          f0 = g.second;
        } else {
          f0 = mul(f0, add(mul(4, g.first), g.second));
          f0 = add(f0, mul(mul(2, f1), mul(2, g.first)));
          f0 = add(f0, mul(mul(2, f1), g.second));
          f1 = mul(f1, mul(2, g.first));
        }
      } else {
        if (first) {
          f0 = 0;
          f1 = powmod(2, h[x] - m);
        } else {
          f0 = mul(f0, 2);
          f0 = add(f0, mul(2, f1));
          f0 = mul(f0, powmod(2, h[x] - m));
          f1 = mul(f1, powmod(2, h[x] - m));
        }
      }
    } else {
      if (first) {
        f0 = sub(pw[y - x], 2);
        f1 = 1;
      } else {
        f0 = mul(f0, pw[y - x]);
        f0 = add(f0, mul(mul(2, f1), sub(pw[y - x], 1)));
      }
    }
    first = false;
  }

  int good_ways = powmod(2, m - s - 1);

  f1 = mul(f1, good_ways);

  return {f1, f0};
}

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", &h[i]);

  pw[0] = 1;
  REP(i, N) pw[i + 1] = mul(pw[i], 2);

  auto g = solve(0, N, 0);

  int ret = add(mul(2, g.first), g.second);
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
import Data.List
import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  ss <- replicateM n getLine
  let baseab = length . filter (=="AB") . concatMap pair $ ss
      lasta  = length . filter (not . isPrefixOf "B") . filter (isSuffixOf "A") $ ss
      firstb = length . filter (not . isSuffixOf "A") . filter (isPrefixOf "B") $ ss
      bothab = length . filter (      isSuffixOf "A") . filter (isPrefixOf "B") $ ss
  -- print $ baseab + solve lasta firstb bothab
  print $ baseab + if lasta == 0 && firstb == 0 && bothab > 0
                   then bothab - 1
                   else bothab + min lasta firstb

-- solve :: Int -> Int -> Int -> Int
-- solve x y z
--   | z == 0 = min x y
--   | z > 0 && x + y > 0 = z + min x y
--   | z > 0 && x + y == 0 = z - 1

pair :: [a] -> [[a]]
pair [] = []
pair [x] = []
pair (x:y:xs) = [x,y] : pair (y:xs)


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

int main() {
  list<char> inp;
  char a;
  while(cin.get(a) && a != '\n') {
    inp.push_back(a);
  }
  int q;
  cin >> q;
  list<char> front;
  list<char> back;
  front.push_back(*inp.begin());
  inp.pop_front();
  if (inp.size() > 0) {
    back.push_back(*(--inp.end()));
    inp.pop_back();
  }
  bool reversed = false;

  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      reversed = reversed ? false : true;
    } else {
      int f;
      cin >> f;
      char c;
      cin >> c;
      if (f == 1) {
        if (reversed) {
          back.push_back(c);
        } else {
          front.push_front(c);
        }
      } else {
        if (reversed) {
          front.push_front(c);
        } else {
          back.push_back(c);
        }
      }
    }
  }

  if (reversed) {
    for (auto itr = back.rbegin(); itr != back.rend(); ++itr) {
      cout << *itr;
    }
    for (auto itr = inp.rbegin(); itr != inp.rend(); ++itr) {
      cout << *itr;
    }
    for (auto itr = front.rbegin(); itr != front.rend(); ++itr) {
      cout << *itr;
    }
  } else {
    for (auto itr = front.begin(); itr != front.end(); ++itr) {
      cout << *itr;
    }
    for (auto itr = inp.begin(); itr != inp.end(); ++itr) {
      cout << *itr;
    }
    for (auto itr = back.begin(); itr != back.end(); ++itr) {
      cout << *itr;
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 9856
;; -*- coding:utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 1))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload :cl-debug-print))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline make-prime-dict))
(defun make-prime-dict (size)
  "Erzeugt die Primzahlentabelle 0 zu SIZE-1."
  (declare (optimize (speed 3) (safety 1)))
  (let ((dict (make-array size :element-type 'bit :initial-element 1)))
    (setf (aref dict 0) 0 (aref dict 1) 0)
    (loop for even-num from 4 below size by 2
          do (setf (aref dict even-num) 0))
    (loop for p from 3 to (ceiling (sqrt size)) by 2
          when (= 1 (aref dict p))
          do (loop for composite from (+ p p) below size by p
                   until (>= composite size)
                   do (setf (aref dict composite) 0)))
    dict))

(defmacro println (obj &optional (stream '*standard-output*))
  `(prog1 (princ ,obj ,stream) (terpri ,stream)))

;; Hauptteil

;; Sei gcd(a1, ..., aN) = 2^f(2)*3^f(3)*....
;; Da P = a1* ... *aN, gilt gcd(a1, ..., aN)^N | P und somit
;; 2^(f(2)*N)*3^(f(3)*N)*... | P
;; Wir müssen nur so ein f finden, so dass jedes f(k) maximal ist.
;; Nun sei 2^g(2)*3^g(3)*.... die Primfaktorzerlegung von P.
;; Dann muss f Folgendes erfüllen:
;; f(2)* N <= g(2)
;; f(3)* N <= g(3)...

(deftype uint nil `(integer 0 ,(expt 10 9)))

(declaim (inline zerlegen))
(defun zerlegen (num prime-dict)
  (let ((factor-table (make-array (length prime-dict)
                                  :element-type '(unsigned-byte 15)
                                  :initial-element 0)))
    (loop for prime from 2 to (min num (- (length prime-dict) 1))
          when (= 1 (aref prime-dict prime))
          do (setf (aref factor-table prime)
                   (loop with pow = 0
                         while (zerop (mod num prime))
                         do (incf pow)
                            (setf num (floor num prime))
                         finally (return pow)))
          finally (return factor-table))))

(defun restore-from-factorization (factor-table)
  (loop for prime from 2 below (length factor-table)
        with product = 1
        when (>= (aref factor-table prime) 1)
        do (setf product (* product (expt prime (aref factor-table prime))))
        finally (return product)))

(defun main ()
  (let* ((n (read))
         (p (read))
         (size 100001)
         (prime-dict (make-prime-dict size))
         (factor-table (zerlegen p prime-dict)))
    (if (= n 1)
        (println p)
        (loop for prime from 2 below size
              with product = 1
              when (>= (aref factor-table prime) 1)
              do (setf product
                       (* product (expt prime (floor (aref factor-table prime) n))))
              finally (println product)))))

#-swank(main)


Measured memory_bytes: 18792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define reep(num,num2,num3) for(int num=num3;num<num2;num++)
#define rep(num,num2) for(int num=0;num<num2;num++)
using namespace std;
int dp[1024][1024];
int D[1024];
int ht[1024];
int lt[1024];
int C[1024];
int main()
{
    int d,n;
    cin>>d>>n;
    rep(i,d){
        int t;
        cin>>t;
        D[i]=t;
    }
    rep(i,n){
        int h,l,c;
        cin>>h>>l>>c;
        lt[i]=h;
        ht[i]=l;
        C[i]=c;
    }
    rep(i,1024)
        rep(j,1024)dp[i][j]=-1;
    rep(i,n)if(ht[i]>=D[0]&&D[0]>=lt[i])dp[0][i]=0;
    rep(i,d-1)
        rep(j,n)
            if(dp[i][j]!=-1)
                rep(k,n)
                    if(ht[k]>=D[i+1]&&D[i+1]>=lt[k]&&dp[i+1][k]<dp[i][j]+abs(C[k]-C[j]))dp[i+1][k]=dp[i][j]+abs(C[k]-C[j]);
    int res=-1;
    rep(i,n)res=max(res,dp[d-1][i]);
    cout<<res<<endl;
}

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

int main() {
  int x, a, b, da = 0, db = 0;
  cin >> x >> a >> b;
  
  if(x - a > 0){
    da = x - a;
  }
  else{
    da = a - x;
  }
  
   if(x - b > 0){
    db = x - b;
  }
  else{
    db = b - x;
  }
  
   if(da > db){
    cout << "B" << endl;
  }
  else{
    cout << "A" << endl;
  }
}


Measured memory_bytes: 256
# coding: utf-8
x1, y1, x2, y2 = map(int, input().split())
a, b = x2 - x1, y2 - y1
x3, y3 = x2 - b, y2 + a
x4, y4 = x1 - b, y1 + a
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)       __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

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

void solve()
{

	 ll n;cin>>n;
	 vll v;
	 enter(v,n);
	 map<ll,ll>mp;
	 ll sum=0;
	 for(int i=0;i<n;i++)
	 {
	 	  sum+=v[i];
	 	  mp[v[i]]++;
	 }
	 ll q;cin>>q;
	 for(int i=0;i<q;i++)
	 {
	 	ll x,y;
	 	cin>>x>>y;
	 	sum=sum-(mp[x]*x);
	 	sum=sum+(mp[x]*y);
	 	cout << sum << endl;
	 	mp[y]=mp[y]+mp[x];
	 	mp[x]=0;
	 }





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

	return 0;
}

Measured memory_bytes: 9888
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;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; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N,ans=0;
  map<int,int> mp;
  cin >> N;
  rep(i,N){
    int a;
    cin >> a;
    if(mp[a]==0) mp[a]++;
    else mp[a]=0;
  }
  for(auto p:mp) ans+=p.second;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

lli Gcd(lli x, lli y)
{
  if (y == 0)
    return x;
  return Gcd(y, x % y);
}

int main(void)
{
  int n;
  scanf("%d", &n);
  int a[MAX];
  rep(i, 0, n) scanf("%d", &a[i]);

  int ans = a[0];
  rep(i, 0, n)
  {
    ans = Gcd(ans, a[i]);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void)
{
    int a[10+1],b[10+1],c[10+1],ten[10+1],i,j,n,max,cnt;
    char name[10+1][20+1];
    cnt=0;
    scanf("%d",&n);
    while(n!=0) {
        if(0<cnt) {
            printf("\n");
        }
        for(i=0;i<n;i++) {
            scanf("%s %d %d %d",name[i],&a[i],&b[i],&c[i]);
            ten[i]=a[i]*3+b[i]*0+c[i]*1;
        }
        for(j=0;j<n;j++) {
            max=-1;
            for(i=0;i<n;i++) {
                if(max<ten[i]) {
                    max=ten[i];
                }
            }
            for(i=0;i<n;i++) {
                if(max==ten[i]) {
                    printf("%s,%d\n",name[i],ten[i]);
                    ten[i]=-2;
                }
            }
        }
        cnt++;
    scanf("%d",&n);
    }
    return 0;
}

Measured memory_bytes: 600
a,b = map(int,input().split())
flag = False
c = 0
for i in range(1,1251):
    x = int(i*0.08)
    y = int(i*0.1)
    if x == a and y == b:
        flag = True
        c = i
        break
if flag == False:
    print("-1")
else:
    print(c)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll A, B;
	cin >> A >> B;
	if (abs(A - B) > 1)
		puts("Alice");
	else
		puts("Brown");
	return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
ta,ao,su=a,b,c
cnt=0
f=True
while f:
	if ta%2!=0 or ao%2!=0 or su%2!=0:
		f=False
	elif ta==ao==su:
		f=False
		cnt=-1
	else:
		ta=(b+c)/2
		ao=(a+c)/2
		su=(a+b)/2
		cnt+=1
		a=ta
		b=ao
		c=su
print(cnt)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(f.readLine());
        long[] arr = new long[n+1];
        StringTokenizer st = new StringTokenizer(f.readLine());
        long sum = 0;
        for(int i = 0; i < n+1; i++){
            arr[i] = Long.parseLong(st.nextToken());
            sum+=arr[i];
        }
        long currLeaves = 1;
        long totalNodes = 1;
        boolean good = true;
        if(n != 0 && arr[0] != 0){
            out.println(-1);
            out.close();
            System.exit(0);
        }
        if(n == 0 && arr[0] == 1){
            out.println(1);
            out.close();
            System.exit(0);
        }else if(n == 0){
            out.println(-1);
            out.close();
            System.exit(0);
        }
        for(int i = 1; i <= n; i++){
            currLeaves = Math.min(2*currLeaves, sum);
            totalNodes+=currLeaves;
            if(arr[i] > currLeaves){
                good = false;
                break;
            }
            currLeaves -= arr[i];
            sum-= arr[i];
        }
        if(good){
            out.println(totalNodes);
        }else{
            out.println(-1);
        }





        out.close();
    }
}


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

int main(){
	int H,W,A[10005],N;
	int ans[105][105],c=1;
	bool b=1;
	cin>>H>>W>>N;
	for(int i=1;i<=N;++i){
		cin>>A[i];
	}
	for(int i=0;i<H;++i){
		if(b){
			for(int j=0;j<W;j++){
				ans[i][j]=c;
				A[c]--;
				if(A[c]==0)++c;
			}
		}else{
			for(int j=W-1;j>=0;j--){
				ans[i][j]=c;
				A[c]--;
				if(A[c]==0)++c;
			}
		}
		b=!b;
	}
	for(int i=0;i<H;++i){
		for(int j=0;j<W-1;++j){
			cout<<ans[i][j]<<" ";
		}
		cout<<ans[i][W-1]<<endl;;
	}
	return 0;
}


Measured memory_bytes: 384
import Data.List

main = getLine >>= putStrLn . maybe "-1" show . untilodd . map read . words

untilodd [a,b,c]
 | any odd [a,b,c] = Just 0
 | a==b && b==c = Nothing
 | otherwise = Just $ length $ unfoldr exchange [a,b,c]

exchange [a,b,c]
 | any odd [a,b,c] = Nothing
 | otherwise = Just (next, next)
  where next = [div b 2 + div c 2, div a 2 + div c 2, div a 2 + div b 2]

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;

struct node {
    int a, b;

    bool operator<(const node &t) const {
        return a * (t.b + 1) > t.a * (b + 1);
    }
} p[N];

ll pre[N];
int n, cnt = 0, tot = 0;
ll t;
ll dp[50];

ll calc() {
    for (int i = 0; i < 35; i++)dp[i] = (i ? 1e9 : 0);
    for (int i = 1; i <= cnt; i++) {
        for (int j = 30; j >= 0; j--) {
            if (dp[j] == 1e9)continue;
            dp[j + 1] = min(dp[j + 1], (dp[j] + 1) * (p[i].a + 1) + p[i].b);
            if (dp[j + 1] > t)dp[j + 1] = 1e9;
        }
    }
    ll ans = -1;
    for (int i = 0; i < 32; i++) {
        if (dp[i] != 1e9) {
            ll x = t - dp[i];
            ll pos = upper_bound(pre + 1, pre + tot + 1, x) - pre - 1;
            ans = max(ans, pos + 1ll * i);
        }
    }
    return ans;
}

int main() {
    scanf("%d%lld", &n, &t);
    int a, b;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &a, &b);
        if (a == 0)pre[++tot] = b;
        else p[++cnt] = {a, b};
    }
    sort(p + 1, p + cnt + 1);
    sort(pre + 1, pre + tot + 1);
    for (int i = 1; i <= tot; i++)pre[i] += pre[i - 1] + 1;
    printf("%lld\n", calc());
    return 0;
}


Measured memory_bytes: 5396
#include<bits/stdc++.h>
using namespace std;
int d[]={0,6000,4000,3000,2000};

int main(){
  for(int i=0;i<4;i++){
    int t,n;
    cin>>t>>n;
    cout<<d[t]*n<<endl;
  }
  return(0);
}



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  bool serve = true;
  while(1){
    rep(i,3){
      int a = 0,b = 0;
      string s;
      cin >> s;
      if(s == "0") goto LABEL;
      REP(j,1,s.size()){
        if(s[j] == 'A'){
          ++a;
        }
        else{
          ++b;
        }
      }
      ((a < b)? b : a) += 1;
      cout << a << " " << b << endl;
    }
  }
LABEL:
  return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

bool not_allowed[10];
bool ok(int a)
{
    while(a)
    {
        if(not_allowed[a%10])
            return false;
        a/=10;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    for(int i=0; i<k; i++)
    {
        int d;
        cin >> d;
        not_allowed[d] = true;
    }

    for(int i=n; i<=1000000; i++)
    {
        if(ok(i))
        {
            cout << i;
            break;
        }
    }
    return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;
ll  a[N];
ll dp[N];

void solve(int testCase){

    scanf("%d" , &n);

    for(int i = 0 ; i < n ; i ++){
            scanf("%lld" , &a[i]);
            dp[i] = INF;
    }

    dp[0] = 0;
    for(int i = 0 ; i < n ; i ++){
            if(i < n - 1)
                dp[i+1] = min(dp[i+1] , dp[i] + abs(a[i] - a[i+1]));
            if(i < n - 2)
                dp[i+2] = min(dp[i+2] , dp[i] + abs(a[i] - a[i+2]));
    }

    printf("%lld\n" , dp[n-1]);

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 1792
#入力部
N, K = map(int, input().split())
V = list(map(int, input().split()))
V2 = list(reversed(V))  #反転したリスト
ans = 0 #最終出力


for i in range(K+1):
  for j in range(K+1-i):
    mylist = []
    #指定回数以上はbreak
    if i+j > N:
      break
    mylist = (V[:i])
    mylist.extend(V2[:j])
    #加算のみでの最大値を求める
    mysum = sum(mylist)
    #減算した方が良い場合を求める
    mylist.sort()
    for m in range(min(K - i - j, i+j)): #規定回数と実際に加算されている数を考慮
      #0以上の数は減算非対象
      if mylist[m] >= 0:
        break
      mysum -= mylist[m]
    #減算しない場合かする場合かの最大値が解
    ans = max(mysum, ans)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    vector<vector<int>> B(3,vector<int>(3));
    for(int i = 0;i<3;i++){
        for(int j=0;j<3;j++)cin>>B.at(i).at(j);
    }
    int N;cin>>N;
    vector<int> hit(N);
    for(int i=0;i<N;i++)cin>>hit.at(i);
    vector<vector<int>> Crash(3,vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<N;k++){
                if(B.at(i).at(j)==hit.at(k))Crash.at(i).at(j)=1;
            }
        }
    }
    bool ans=0;
    if(Crash.at(0).at(0)&&Crash.at(0).at(1)&&Crash.at(0).at(2))ans=1;
    if(Crash.at(1).at(0)&&Crash.at(1).at(1)&&Crash.at(1).at(2))ans=1;
    if(Crash.at(2).at(0)&&Crash.at(2).at(1)&&Crash.at(2).at(2))ans=1;
    if(Crash.at(0).at(0)&&Crash.at(1).at(0)&&Crash.at(2).at(0))ans=1;
    if(Crash.at(0).at(1)&&Crash.at(1).at(1)&&Crash.at(2).at(1))ans=1;
    if(Crash.at(0).at(2)&&Crash.at(1).at(2)&&Crash.at(2).at(2))ans=1;
    if(Crash.at(0).at(0)&&Crash.at(1).at(1)&&Crash.at(2).at(2))ans=1;
    if(Crash.at(0).at(2)&&Crash.at(1).at(1)&&Crash.at(2).at(0))ans=1;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
long long gcd(long long x,long long y)
{
    long long r=1;
    while(r!=0){
        r=x%y;
        x=y;
        y=r;
        }
        return x;
}
long long lcm(long long x,long long y)
{
    return x*(y/gcd(x,y));
}
int main(void)
{
    long long T[100];
    long long N;
    long long A=0;
    scanf("%lld",&N);
    for (int i=1;i<=N;i++)
    {
        scanf("%lld",&T[i]);
    }
    A=T[1];
    for(int i=1;i<=N;i++)
    {
        A=lcm(A,T[i]);
    }
    printf("%lld",A);
}        

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

def valid(two_num, four_num, one_num, c):
    t = 0
    f = 0
    o = 0
    for v in c.values():
        while v >= 4:
            f += 1
            v -= 4
        if v >= 2:
            t += 1
            v -= 2
        if v == 1:
            o += 1
            v -= 1
    if one_num == 1:
        return o == 1 and f * 4 >= four_num
    else:
        return o == 0 and f * 4 >= four_num
        

H, W = map(int, input().split())
c = Counter()
for h in range(H):
    s = input()
    c.update(s)

def solve(H, W, c):
    ok = True
    if H == W == 1:
        pass
    elif H == 1 or W == 1:
        HW = H * W
        odd_num = sum(1 for x in c.values() if x % 2)
        even_num = HW - odd_num
        # print("odd, even = ", odd_num, even_num)
        if HW % 2 == 1 and odd_num != 1: ok = False
        elif HW % 2 == 0 and odd_num != 0: ok = False
    elif H % 2 == W % 2 == 0:
        # all 4
        for v in c.values():
            if v % 4 != 0:
                ok = False
                break
    elif H % 2 == W % 2 == 1:
        two_num = H + W - 2
        one_num = 1
        four_num = H * W - two_num - one_num
        if not valid(two_num, four_num, one_num, c):
            ok = False
    else:
        if W % 2 == 0:
            two_num = W
        else:
            two_num = H
        four_num = H * W - two_num
        if not valid(two_num, four_num, 0, c):
            ok = False
        
    return ok

if solve(H, W, c):
    print("Yes")
else:
    print("No")


        


Measured memory_bytes: 5416
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define repB(i, z, n) for(int i = n - 1; i >= z; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
//#define P pair<int, int>
typedef pair<int, int> P;

int main(){
    int64_t A, D = 0;
    string B, C;
    cin >> A >> B;
    if (B.size() == 1){
        D = B.at(0) - 48;
    }
    else{
        if(B.at(0) == '0'){
            rep(i, 2, B.size()){
                if (i == 2) D += (B.at(i) - 48) * 10;
                if (i == 3) D += (B.at(i) - 48);
            }
        }
        else{
            rep(i, 0, B.size()){
            if (i == 0) D += (B.at(i) - 48) * 100;
            if (i == 1) continue;
            if (i == 2) D += (B.at(i) - 48) * 10;
            if (i == 3) D += (B.at(i) - 48);
            }
        }
    }
    int64_t E = (A * D) / 100;
    cout << E << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>

int main(){
  int n;
  std::map<int,long long> m;
  std::vector<int> v;
  //m数値保存v順序保存
  long long a,b,c;
  //a番号b単価c数量
  bool f; //真か偽を格納
  while(std::cin>>n && n){
     m.clear();
     v.clear();
     f=true;
    for(;n;n--){
      std::cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++){
      if(m[v[i]]>=1000000){
	f=false;
	std::cout<<v[i]<<std::endl;}
    }
    if(f)std::cout<<"NA"<<std::endl;
  }
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 2 == 0 or b % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード
ll a, b, c, k, ans;

int main() {

	cin >> a >> b >> c >> k;
	if (k <= a) cout << k << endl;
	else if (k <= a + b) cout << a << endl;
	else cout << a - (k - a - b) << endl;
	




	return 0;
}



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

long long int compare(const void *a, const void *b)
{
    return *(long long int*)a - *(long long int*)b;
}

long long int ab(long long int x){
	if(x<0)return -x;
	return x;
}

int main(){
	long long N,i,ans=0;
	scanf("%lld",&N);
	
	long long A[N+1],B[N],C[N+1];
	for(i=0;i<N;i++)scanf("%lld",&A[i]);
	for(i=0;i<N;i++)scanf("%lld",&B[i]);
	for(i=0;i<N;i++)scanf("%lld",&C[i]);
	
	A[N]=0;
	C[N]=1000000001;
	
	qsort(A,N+1,sizeof(long long int),compare);
	qsort(C,N+1,sizeof(long long int),compare);
	
	for(i=0;i<N;i++){
		long long a,c,ok,ng;

		ok=0;
		ng=N+1;
		while(ab(ok-ng)>1){
			long long mid=(ok+ng)/2;
			if(A[mid]<B[i])ok=mid;
			else ng=mid;
		}
		a=ok;
		
		ok=N;
		ng=-1;
		while(ab(ok-ng)>1){
			long long mid=(ok+ng)/2;
			if(C[mid]>B[i])ok=mid;
			else ng=mid;
		}
		c=N-ok;
		
		ans+=a*c;
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3324
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 1010;
const int maxK = 19;
int a[maxN];
int main()
{
	for(int i=1;i<=3;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+4);
	int d = a[1] + a[2];
	printf("%d\n",d);
	return 0;
}

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

int main() {
  string S;
  cin>>S;
  int Z=0;
  for(int i=1;i<S.size();i++){
    if(S.at(i-1)==S.at(i)){
      cout<<i<<" "<<i+1<<endl;
      Z++;
      break;
    }
    if(i!=1){
      if(S.at(i-2)==S.at(i)){
        cout<<i-1<<" "<<i+1<<endl;
        Z++;
        break;
      }
    }
  }
  if(Z==0){
    cout<<"-1"<<" "<<"-1"<<endl;
  }
}





Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        int ans = 0;
        if(a <= k){
            ans += a;
            if(k-a >= b){//aを使い切った後まだ使えるならb
                //bを使えるだけ使う
                if(k-a-b >= c){//bも使い切って、残りの枚数がcより少なければ
                    ans -= c;
                }else{//cの方が多ければ
                    ans -= k-a-b;//全部使い切る
                }
            }else{
                //bで使い切って終わり
            }
        }else{//aだけで終わるなら
            ans += k;
        }
        System.out.println(ans);
    }
}


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

int main(){
    int n;
    char c;
    while(true){
        cin >> n;
        if(n == 0)
            break;

        int ans=-1, vote[27] = {0};
        vote[26] = 0;
        int no1=26, no2=26;
        for(int i=0; i<n; i++){
            cin >> c;
            if(ans != -1)
                continue;

            vote[c - 'A']++;
            if((int)(c-'A') != no1 && (int)(c-'A') != no2){
                if(vote[c - 'A'] > vote[no1]){
                    no2 = no1;
                    no1 = (int)(c-'A');
                }else if(vote[c - 'A'] > vote[no2]){
                    no2 = (int)(c-'A');
                }
            }else if(vote[no2] > vote[no1]){
                int tmp = no1;
                no1 = no2;
                no2 = tmp;
            }
            //cout << no1 << no2 << endl;

            if(vote[no1] != vote[no2] && vote[no1] > vote[no2] + n-i-1)
                ans = i+1;
        }
        if(ans != -1)
            cout << (char)(no1+'A') << ' ' << ans << endl;
        else
            cout << "TIE" << endl;
    }
  
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,p;
	cin>>n>>p;
	if(n==1){
		cout<<p;
		return 0;
	}
	int a[1000005]={},P=p,i;
	for(i=2;i<=sqrtl(p)&&p!=1;i++){
		while(p%i==0){
			p/=i;
			a[i]++;
		}
	}
	if(P==p){
		cout<<1;
		return 0;
	}
	int ans=1;
	for(int j=2;j<i;j++){
		while(a[j]>=n){
			a[j]-=n;
			ans*=j;
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4096
#include "stdio.h"
int main(void){
  int N,i,count,check;
  int A[300];

  check = 65535;
  
  scanf("%d", &N);
  
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }

  for(i = 0; i < N; i++){
      count = 0;
    while(A[i] % 2 == 0){
      A[i] = A[i]/2;
      count++;
    }
    
    if(check > count){
      check = count;
    }
  }

  printf("%d\n", check);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

/*
* 扩展KMP算法
*/
//nxt[i]:x[i...m-1]与x[0...m-1]的最长公共前缀
//extend[i]:y[i...n-1]与x[0...m-1]的最长公共前缀
int nxt[maxn];
int extend[maxn + maxn];
bool s[maxn + maxn], t[maxn];
void pre_EKMP(bool x[],int m,int nxt[])
{
  nxt[0]=m;
  int j=0;
  while(j+1<m && x[j]==x[j+1]) j++;
  nxt[1]=j;
  int k=1;
  for(int i=2;i<m;i++)
  {
    int p=nxt[k]+k-1;
    int L=nxt[i-k];
    if(i+L<p+1)nxt[i]=L;
    else
    {
      j=max(0,p-i+1);
      while(i+j<m && x[i+j]==x[j])j++;
      nxt[i]=j;
      k=i;
    }
  }
}
void EKMP(bool x[],int m,bool y[],int n,int nxt[],int extend[])
{
  pre_EKMP(x,m,nxt);
  int j=0;
  while(j<n && j<m && x[j]==y[j]) j++;
  extend[0]=j;
  int k=0;
  for(int i=1;i<n;i++)
  {
    int p=extend[k]+k-1;
    int L=nxt[i-k];
    if(i+L<p+1)
      extend[i]=L;
    else
    {
      j=max(0,p-i+1);
      while(i+j<n && j<m && y[i+j]==x[j]) j++;
      extend[i]=j;
      k=i;
    }
  }
}

int a[maxn], b[maxn];
int ans[maxn];
int n;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<31;i++){
    for(int j=0;j<n;j++){
      s[j] = s[j+n] = (a[j]&(1<<i));
      t[j] = (b[j]&(1<<i));
    }
    EKMP(t, n, s, n + n, nxt, extend);
    for(int j=0;j<n;j++)if(extend[j]==n){
      ans[j]|=(1<<i);
    }
    for(int j=0;j<n;j++){
      s[j] = s[j+n] = (a[j]&(1<<i));
      t[j] = !(b[j]&(1<<i));
    }
    EKMP(t, n, s, n + n, nxt, extend);
    for(int j=0;j<n;j++)if(extend[j]==n){
        ans[j]|=(1<<i);
    }
  }
  for(int i=0;i<n;i++){
    if(ans[i]==(1<<30) - 1 + (1<<30)) {
      cout<<i<<" "<<(b[0]^a[i])<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 


int main()
{
  __;
  ll n,a,b;
  cin >> n >> a >> b;
  ll temp = n%(a+b);
  ll temp2 = n/(a+b);

  ll cnt = temp2*a;
  cnt += min(a,temp);
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){
  int a, b, c;
  cin >> a >> b >> c;

  if( a < b && b < c ) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}








// EOF

Measured memory_bytes: 3044
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535;

int main()
{
    int n;
    cin >> n;
    int count[200000] = { 0 };
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        a--;
        count[a]++;
    }
    rep(i, n) cout << count[i] << endl;
    return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N, T = 0;
	vector<llong> t,v;

	cin >> N;
	t.resize(N+1, 0), v.resize(N+1,0);
	for(int i = 1; i <= N; i++){
		cin >> t[i];
		t[i] += t[i-1];
	}
	for(int i = 1; i <= N; i++)
		cin >> v[i];

	map<double, long double> res;
	for(llong i = N; i >= 1; i--){
		for(double j = t[i]; j >= t[i-1]; j -= 0.5){
			if(res.find(j) == res.end())
				res[j] = inf;
			if(i == N)
				res[j] = min({(long double)res[j],(long double)t[i]-j, (long double)v[i]});
			else if(i == 1)
				res[j] = min({(long double)res[j], (long double)j, res[j+0.5]+0.5, (long double)v[i]});
			else{
				res[j] = min({(long double)res[j], res[j+0.5]+0.5, (long double)v[i]});
			}
		}
	}

	// for(double i = 0; i < t[N]; i += 0.5)
	// 	cerr << res[i] << endl;

	long double ans = 0.0;
	long double now = 0;
	for(double i = 0; i < t[N]; i += 0.5){
		if(now < res[i+0.5]){
			ans += (now+now+0.5)/4.0;
			now += 0.5;
		}else if(now > res[i+0.5]){
			ans += (now+now-0.5)/4.0;
			now -= 0.5;
		}else{
			ans += now/2.0;
		}
	}

	cout << fixed << setprecision(12) << ans << endl;

	return 0;
}


Measured memory_bytes: 3328
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int tapNumber = 0;
        int mouseNumber = 1;
        int min = 0;

        while(true){
            mouseNumber = tapNumber * (A - 1) + 1;
            if(mouseNumber >= B){
                min = tapNumber;
                break;
            }
            tapNumber ++;
        }


        System.out.println(min);

    }
}





Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;

string S;
int N, K, A[1009];
long long dp[1009][5][2];

int main() {
	cin >> S >> K; N = S.size();
	for (int i = 0; i < S.size(); i++) A[i] = (S[N - 1 - i] - '0');

	dp[101][0][1] = 1;
	for (int i = 100; i >= 0; i--) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k < 2; k++) {
				if (dp[i + 1][j][k] == 0) continue;

				for (int l = 0; l < 10; l++) {
					if (k == 1 && l > A[i]) continue;
					int c1 = i, c2 = j, c3 = k;
					if (l != 0) c2 += 1;
					if (k == 1 && l < A[i]) c3 = 0;
					dp[c1][c2][c3] += dp[i + 1][j][k];
				}
			}
		}
	}

	cout << dp[0][K][0] + dp[0][K][1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char moji;
    int num, sum = 0, count = 0;
    for(;;){
        scanf("%c", &moji);
        if( moji == '0' && count == 0){
            break;
        }else{
            num = moji - 48;
            if( moji == '\n' ){
                printf("%d\n", sum);
                sum = 0;
                count = 0;
                continue;
            }
            sum += num;
            count += 1;
        } 
    }
    return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,a,b;
ll v[1000];

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

ll C(ll n,ll m) {
	if(n / 2 < m) {
		m = n - m;
	}

	ll bunsi[m];

	for(ll i = 0;i < m;i++) {
		bunsi[i] = n - i;
	}

	for(ll i = 2;i <= m;i++) {
		ll bunbo = i;
		for(ll j = 0;j < m && bunbo > 1;j++) {
			ll g = gcd(bunbo,bunsi[j]);
			bunbo /= g;bunsi[j] /= g;
		}
	}

	ll ret = 1;
	for(ll i = 0;i < m;i++) {
		ret *= bunsi[i];
	}
	return ret;
}

int main(){
	cin >> n >> a >> b;
	REP(i,n) {
		cin >> v[i];
	}

	sort(v,v+n);

	double sum = 0;
	FOR(i,n - a,n) {
		sum += v[i];
	}
	printf("%0.10f\n",sum / a);

	int c = 0;

	FOR(i,n - a,n) {
		if(v[n - a] == v[i]) {
			c++;
		}
	}

	if(c < a) {
		ll d = 0;
		REP(i,n) {
			if(v[i] == v[n - a]) {
				d++;
			}
		}
		cout << C(d,c) << endl;
	}else {
		ll d = 0;
		REP(i,n) {
			if(v[i] == v[n - a]) {
				d++;
			}
		}
		ll ans = 0;
		FOR(i,a,min(d,b) + 1) {
			ans += C(d,i);
		}
		cout  << ans << endl;
	}

	return 0;
}


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

using namespace std;

const int MAXN=100002;
int N,H,W;
int a[MAXN],b[MAXN];
long long pTotal[11]={0};

void solve(){
	cin>>H>>W>>N;
	for (int i=0;i<N;i++){
		cin>>a[i]>>b[i];
	}
	pTotal[0] = (long long)(H-2)*(long long)(W-2);
	set<pair<long long,long long> > points;
	for (int i=0;i<N;i++){
		for (int j=max(1,a[i]-2);j<=min(H-2,a[i]);j++)
			for (int k=max(1,b[i]-2);k<=min(W-2,b[i]);k++) {
				int pCount = 0;
				for (int j1=0;j1<3;j1++)
					for (int k1=0;k1<3;k1++)
						if (points.find(make_pair(j+j1,k+k1))!=points.end())
							pCount++;
				pTotal[pCount]--;
				pTotal[pCount+1]++;
			}
		points.insert(make_pair(a[i],b[i]));
	}
	for (int i=0;i<=9;i++)
		cout<<pTotal[i]<<endl;
}


int main(){
//	freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<int> a(n), A(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    
    copy(a.begin(), a.end(), A.begin());
    sort(A.begin(), A.end());

    int cnt = 0;
    for(int i = 0; i < n; i += 2){
        int id = lower_bound(A.begin(), A.end(), a[i]) - A.begin();
        
        if(id % 2 != 0)     ++cnt;
    }
    
    cout << cnt << endl;
}

Measured memory_bytes: 1024