akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define NOFILE 1
#define NOARG 2
#define NCOINS 25
#define SMAX 50005

const int inf = (1 << 31) - 1;

int solve (int sum, int *coins, int n)
{
    int min_to_obtain [SMAX];
    int i, j;

    min_to_obtain [0] = 0; //we need 0 coins to obtain the sum 0
    ///initialising the array with an infinite value
    for (i = 1; i <= sum; ++ i)
        min_to_obtain [i] = inf;

    for (i = 0; i < n; ++ i)
    {
        for (j = 1; j <= sum; ++ j)
        {
            if (j >= coins [i])
            {
                if (min_to_obtain [j] > 1 + min_to_obtain [j - coins [i]])
                {
                    min_to_obtain [j] = 1 + min_to_obtain [j - coins [i]];
                }
            }
        }
    }

    return min_to_obtain [sum];

}

int main()
{

    int sum, n, v [NCOINS], i, min_coins = inf;

    scanf ("%d %d", &sum, &n);
    for (i = 0; i < n; ++ i)
    {
        scanf ("%d", &v [i]);
    }

    min_coins = solve (sum, v, n);

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


    return 0;
}

Measured memory_bytes: 788
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  s = input().strip()
  k = int(input())
  mode = s[0] == s[-1]

  pre = 1
  idx = 1

  while idx < len(s) and s[idx] == s[0]:
    pre += 1
    idx += 1

  s = s[idx:]

  if len(s) == 0:
    print(pre * k // 2)
    return

  post = 1
  idx = -2

  while idx >= -len(s) and s[idx] == s[-1]:
    post += 1
    idx -= 1

  s = s[:idx + 1]

  required = 0
  count = 1

  for i in range(1, len(s)) :
    if s[i - 1] == s[i]:
      count += 1
    else:
      required += count // 2
      count = 1

  required += count // 2
  required *= k
  required += pre // 2
  required += post // 2

  if mode:
    required += ((pre + post) // 2) * (k - 1)
  else:
    required += (pre // 2 + post // 2) * (k - 1)

  print(required)


if __name__ == '__main__':
  main()


Measured memory_bytes: 38484
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int arr[5],k;
    cin>>arr[0]>>arr[1]>>arr[2]>>k;
sort(arr,arr+3);
    while(k--)
        arr[2]*=2;
  cout<<arr[0]+arr[1]+arr[2]<<endl;

    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main(){
    int data[200],n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&data[i]);
    }
    for(i=n-1;i>=1;i--){
        printf("%d ",data[i]);
    }
    printf("%d",data[0]);
    printf("\n");
    return 0;
}

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

int main() {
	int N, K, A = 1;
	cin >> N >> K;
	for (int i = 0;i < N;i ++) {
		if (A < K) A *= 2;
		else A += K;
	}
	cout << A;
	return 0;
}
// 値は次々に大きくなっていくので、なるべく小さい値を保つべき
// よって2倍とKを足すうち、小さい方を常に選び続ける
// これを貪欲法という

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

int main(){
	int N;
	long long Z,W;
	cin >> N >> Z >> W;
	vector<long long> a(N);
	for(auto &i:a)cin >> i;
	
	if(N==1){
		cout << abs(a[0]-W) << endl;
		return 0;
	}
	
	long long ans;
	ans=max(abs(a[N-1]-W),abs(a[N-2]-a[N-1]));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    d = collections.defaultdict(list)
    n = int(input().rstrip('\n'))
    d[n]
    for i in range(2, 10 ** 10):
        if n % 2 == 0:
            n //= 2
        else:
            n = 3 * n + 1
        if n in d:
            print(i)
            exit()
        else:
            d[n]


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>

#include <algorithm>
#include <cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>

using namespace std;
typedef long long LL;

int main() {


	int a, b,c;
	//----------------------
	LL n, X, Z,A,B,N,ans1,ans2,i,m;
	LL ans, count=0 ;
	bool f=true;
	string s;

	cin >> n;
	cin >> m;

	ans = (n-1)*(m-1);
	

	

	cout << ans << endl;

	
	//------------------------
	//cin >> Z;

	return 0;
}

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

int main(){
	int n;
	string s1,s2;
	int a=0,b=0;
	cin >> n;

	for(int i=0;i<n;i++){
		cin >> s1 >> s2;
		if(s1 > s2) a += 3;
		else if(s1 < s2) b += 3;
		else{
			a++; b++;
		}
	}

	cout << a << " " << b << endl;

	return 0;
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int sx, sy, tx, ty;
    cin>>sx>>sy>>tx>>ty;
    int x=tx-sx, y=ty-sy;
    cout<<string(y, 'U')+string(x, 'R')+string(y, 'D')+string(x, 'L')+"L"+string(y+1, 'U')+string(x+1, 'R')+"DR"+string(y+1,'D')+string(x+1, 'L')+"U";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
typedef unsigned long long ull;

int main() {

	string s; cin >> s;

	s[3] = '8';

	cout << s << endl;


	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [int(x) for x in input().split()]

    min = 1000000000
    for idx in range(0, len(a)):
        count = 0
        while(a[idx] % 2 == 0):
            a[idx] /= 2
            count += 1

        if count < min:
            min = count

    print(min)

if __name__ == "__main__":
    main()


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

int main(){
  int n, m;
  cin >> n >> m;
  ll ans;
  if(abs(n - m) > 1){
    cout << 0 << endl;
    return 0;
  }else{
    ll ans = 1;
    if(n == m) ans = 2;
    rep(i, n){
      ans = ans * (i + 1) % Mod;
    }
    rep(i, m){
      ans = ans * (i + 1) % Mod;
    }
    cout << ans << endl;
  }

}


Measured memory_bytes: 256
def round_up(x, y):
    res = x // y
    if x % y != 0:
        res += 1
    return res

n = int(input())
ta = []
for i in range(n):
    ta.append([int(i) for i in input().split()])

for i in range(1, n):
    if ta[i-1][0] > ta[i][0] or ta[i-1][1] > ta[i][1]:
        multi = max(
            round_up(ta[i-1][0], ta[i][0]),
            round_up(ta[i-1][1], ta[i][1])
        )
        ta[i][0] *= multi
        ta[i][1] *= multi

print(ta[-1][0] + ta[-1][1])


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b))cout<<"A"<<endl;
	else cout<<"B"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

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

	int r;
	cin >> r;
	cout << r * r << "\n";
}


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

int main(){
  while(1){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==-1 && b==-1 && c==-1) break;
    if(a>-1 && b>-1 && a+b>=30){
      if(a+b>=80){
	cout<<"A"<<endl;
      }
      else if(a+b>=65){
	cout<<"B"<<endl;
      }
      else if(a+b>=50){
	cout<<"C"<<endl;
      }
      else if(a+b>=30){
	if(c>=50){
	  cout<<"C"<<endl;
	}
	else{
	  cout<<"D"<<endl;
	}
      }
     
    }
    else{
      cout<<"F"<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll D, G;
    cin >> D >> G;
    ll po[D][2];
    for(ll i = 0; i < D; i++) cin >> po[i][0] >> po[i][1];
    ll ans = 1145148931919810;
    for(ll i = 0; i < (1 << D); i++){
        ll score = 0;
        ll tmp = 0;
        vector<ll> v;
        ll j = i;
        for(ll k = 0; k < D; k++){
            if(j % 2 == 0){
                v.push_back(k);
            }else{
                score += 100 * (k + 1) * po[k][0] + po[k][1];
                tmp += po[k][0];
            }
            j /= 2;
        }
        reverse(v.begin(), v.end());
        for(ll u : v){
            if(score >= G) break;
            ll res = max<ll>(0, (G - score) / (100 * (u + 1)) + !!((G - score) % (100 * (u + 1))));
            tmp += min(res, po[u][0] - 1);
            score += 100 * (u + 1) * min(res, po[u][0] - 1);
        }
        if(score >= G) ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 52
using namespace std;
typedef vector<vector<bool> > V;
typedef pair<int,int> P;
typedef pair<P,P> PP;
string mp[N];
vector<PP> A;
int h,w;

bool compare(PP &a,PP &b){
  int w1 = a.second.first - a.first.first+1;
  int h1 = a.second.second - a.first.second+1; 
  int w2 = b.second.first - b.first.first+1;
  int h2 = b.second.second -b.first.second+1;
  return h1*w1 < h2*w2;
}

V v[50][50];
void visit(int x,int y){
  V &D = v[y][x] = V(N,vector<bool>(N,0));
  D[y][x] = 1;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) {
      if(mp[i][j] == '#')continue;
      if(i)D[i][j] = D[i][j]|D[i-1][j];
      if(j)D[i][j] = D[i][j]|D[i][j-1];
    }
}

void pushA(int x,int y){
  V &D = v[y][x];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      if(!D[i][j]||islower(mp[i][j])||tolower(mp[i][j])!=mp[y][x])continue;
      A.push_back(PP(P(x,y),P(j,i)));
    }
}

void mkA(){
  A.clear();
  V &D = v[0][0];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(D[i][j]&&islower(mp[i][j]))pushA(j,i);
  
  sort(A.begin(),A.end(),compare);
}

bool check(PP a,PP b){
  int x1=a.first.first,y1=a.first.second;
  int X1=a.second.first,Y1=a.second.second;
  int x2=b.first.first,y2=b.first.second;
  int X2=b.second.first,Y2=b.second.second;
  if((a.first==b.first||a.second == b.second)||
     (x1>=0&&y1>=0&&!v[y1][x1][y2][x2])||
     (!v[Y2][X2][h-1][w-1])||
     (X1<w&&X2<h&&!v[Y2][X2][Y1][X1]))return 0;
  return x1<=x2&&X2<=X1&&y1<=y2&&Y2<=Y1;
}

map<PP,int> mem[1000];
int dfs(int idx,PP sta){  
  if(idx == -1) return 0;
  if(mem[idx].count(sta))return mem[idx][sta];
  int res = dfs(idx-1,sta);
  if(check(sta,A[idx])){
    int a = dfs(idx-1,PP(sta.first,A[idx].first));
    int b = dfs(idx-1,A[idx]);
    int c = dfs(idx-1,PP(A[idx].second,sta.second));
    res = max(res,a+b+c+1);
  }
  return mem[idx][sta] = res;
}

int main(){
  while(1){
    cin>>h>>w;
    if(!h&&!w)break;
    for(int i=0;i<h;i++)cin>>mp[i];
    for(int i=0;i<1000;i++)mem[i].clear();

    visit(0,0),visit(w-1,h-1);
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)if(isalpha(mp[i][j]))visit(j,i);
    
    mkA();
    if(!v[0][0][h-1][w-1]) cout<<-1<<endl;
    else cout<<dfs(A.size()-1,PP(P(-1,-1),P(w,h)))<<endl;
  }
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int a, b;
    cin >> a >> b;

    char ans[100][100];
    fill(ans[0], ans[50], '.');
    fill(ans[50], ans[100], '#');
    for(int i = 0 ; i < 100 && b > 1 ; i += 2){
        for(int j = 0 ; j < 100 && b > 1 ; j += 2){
            ans[i][j] = '#';
            --b;
        }
    }

    for(int i = 99 ; i > 0 && a > 1 ; i -= 2){
        for(int j = 0 ; j < 100 && a > 1 ; j += 2){
            ans[i][j] = '.';
            --a;
        }
    }

    cout << "100 100" << endl;
    rep(i, 100){
        rep(j, 100){
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}

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

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long

#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

int main()
{
	fastIO;
	ll n, q, i, j, k, left = 0, right = 0;
	string s;
	vector < pair < char , char > > query; 
	cin>>n>>q>>s;
	fo(i,q) {
		char ch1, ch2;
		cin>>ch1>>ch2;
		query.pb({ch1,ch2});
	}
	ll st = 0, ed = n-1, md;
	//left
	while(st<=ed) {
		//cout<<st<<" "<<ed<<endl;
		md = st + ( ed - st ) / 2;
		ll stat = 0;
		ll mdd = md;
		for(auto mov:query) {
			if(s[md]==mov.F) {
				if(mov.S=='L')md--;else md++;
			}
			if(md<0){stat=1;break;}
			if(md>=n)break;
		}
		md = mdd;
		if(stat==1) {
			left = md+1;
			st = md+1;
		}
		else ed = md - 1;
	}
	st = 0, ed = n-1, md;
	//right
	while(st<=ed) {
		md = st + ( ed - st ) / 2;
		ll stat = 0;
		ll mdd = md;
		for(auto mov:query) {
			if(s[md]==mov.F) {
				if(mov.S=='L')md--;else md++;
			}
			if(md>=n){stat=1;break;}
			if(md<0)break;
		}
		md = mdd;
		if(stat==1) {
			right = (n-md);
			ed = md - 1;
		}
		else st = md + 1;
	}
	cout<<max(0ll, n-(left+right));
}

	

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

long long d[10],v[10];

void compute(int n){
    for(int i = 2 ; i <= min(d[n],v[n]) ; i++){
        if(d[n]%i==0||v[n]%i==0){
            while(d[n]%i==0&&v[n]%i==0){
                d[n] /= i;
                v[n] /= i;
            }
        }
    }
}

int main(){
    int n;
    
    while(cin >>n,n){
        long long a,b;
        for(int i = 0 ; i < n ; i++){
            cin >> d[i] >> v[i];
            compute(i);
        }
        
        a = (d[0]*d[1])/__gcd(d[0],d[1]);
        b = __gcd(v[0],v[1]);
        
        for(int i = 2 ; i < n ; i++){
            a = (a*d[i])/__gcd(a,d[i]);
            b = __gcd(b,v[i]);
        }

        for(int i = 0 ; i < n ; i++){
            cout << a*v[i]/(b*d[i]) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
   int h,w;
   cin>>h>>w;
   string s[h];
   rep(i,h) cin>>s[i];
   rep(i,h){
       rep(j,w){
           if(s[i][j]=='#')  continue;
           int num=0;
           rep(k,8){ //８通り試してすべてのベクトルを試す//
               int yy=i+dy[k]; 
               int xx=j+dx[k];
               if(xx<0 || xx>=w) continue;
               if(yy<0 || yy>=h) continue;
               if(s[yy][xx]=='#') num++;
           }
           s[i][j]=(char)(num+'0');//** 数値を文字型の数字に変換する場合は'0'+数値==つまり、0の場所からどれだけ動くか？//　
                                   //そして表に当てはめる（キャストする）//
       }
   }
   rep(i,h) cout<<s[i]<<endl; 
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int Sum(const string&s){
  int n = (int)s.size();
  int sum = 0;
  for(int i = 0; i < n; ++i)sum += s[i] - '0';
  return sum;
}

int main(){
  int n; cin >> n;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    int l,r;  cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

int main(){
	int n; cin>>n;
	cout<<"ABC"<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    int a,b;
    cin>>a>>b;
    bool ok = 0;
    double ans;
    for(double i=1;i<=2000;i++){
        //if(i==25) cout<<(int)(i*0.08)<<" "<<(int)(i*0.10)<<endl;
        if((int)(i*0.08)==a && (int)(i*0.10)==b) ok = 1,ans = i;
        if(ok) break;
    }
    if(ok) cout<<ans<<endl;
    else cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n);
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	long long N,A,B;
	scanf("%lld%lld%lld",&N,&A,&B);
	
	if ((N==1) and (A==B)){
		PRINTD(1);
		return 0;
	}else if(N==1){
		PRINTD(0);
		return 0;
	}
	
	if (A>B) {
		PRINTD(0);
		return 0;
	}
	
	PRINTLLD((B-A)*(N-2)+1);
	return 0;
}








Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
//#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;


int main(void)
{
	string S; cin >> S;
	vector<lli> cnt;
	lli tmp = 0;
	rep(i, 0, S.size()) {
		if (S[i] == 'B')tmp++;
		else cnt.push_back(tmp);
	}
	lli ans = 0; rep(i, 0, cnt.size())ans += cnt[i];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2680
def main():
    x = int(input())
    if 400 <= x <= 599:
        return 8
    elif 600 <= x <= 799:
        return 7
    elif 800 <= x <= 999:
        return 6
    elif 1000 <= x <= 1199:
        return 5
    elif 1200 <= x <= 1399:
        return 4
    elif 1400 <= x <= 1599:
        return 3
    elif 1600 <= x <= 1799:
        return 2
    elif 1800 <= x <= 1999:
        return 1

print(main())
    

Measured memory_bytes: 9152
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define _v1 CONCAT(qyw1, __LINE__) // unique name in same line (otherwise use __COUNTER__)
#define _v2 CONCAT(qyw2, __LINE__)
#define forbits(i, m) for (int _v1 = m, i = __builtin_ctz(_v1); _v1 != 0; _v1 ^= _v1 & -_v1, i = __builtin_ctz(_v1))
#define forsubm(s, m) for (int s = m; s >= 0; s = !s ? -1 : m & (s - 1))
int __nextXZW(int v){int t=v|(v-1);int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));return w;}
#define ksets(i, n, k) for (int i = (1u << k) - 1, max = i << (n - k); i <= max; i = __nextXZW(i))
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <atcoder/fenwicktree> 
using namespace atcoder;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n, q; cin >> n >> q;
  fenwick_tree<ll> t(n);
  rep (i, n) {
    int x; cin >> x;
    t.add(i, x);
  } 
  while (q--) {
    int type, x, y; cin >> type >> x >> y;
    if (type == 0) {
      t.add(x, y);
    } else {
      cout << t.sum(x, y) << '\n';
    }
  }
  
  return 0;
}

Measured memory_bytes: 8260
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		int minMax = 0;
		int sum = 0;

		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			sum = sum + A[i];
		}

		quick_sort(A, 0, N-1);

		double s = A[N-M];
		double dsum = sum;

		if(s >= (dsum / (4 * M))) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

	static void quick_sort(int[] d, int left, int right) {
        if (left>=right) {
            return;
        }
        int p = d[(left+right)/2];
        int l = left, r = right, tmp;
        while(l<=r) {
            while(d[l] < p) { l++; }
            while(d[r] > p) { r--; }
            if (l<=r) {
                tmp = d[l]; d[l] = d[r]; d[r] = tmp;
                l++; r--;
            }
        }
        quick_sort(d, left, r);  // ピボットより左側をクイックソート
        quick_sort(d, l, right); // ピボットより右側をクイックソート
    }

}


Measured memory_bytes: 22868
#include<iostream>
#include<bits/stdc++.h>
#include<vector>

using namespace std;

int main()
{
    long long int a,b,c,d;
    long long int x,y;
    vector<long long int> darkus;
    long long int ans;

    cin>>a>>b>>c>>d;

    for(int i=0;i<4;i++)
    {
        darkus.push_back(0);        
    }
    darkus.at(0)=a*c;
    darkus.at(1)=a*d;
    darkus.at(2)=b*c;
    darkus.at(3)=b*d;

    sort(darkus.begin(),darkus.end());

    cout<<darkus.at(3)<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
const long long INF = 1LL << 60;

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 main()
{   
    int n,m; cin >> n >> m;
    vector<int> p(m),y(m);
    for(int i=0;i<m;i++) cin >> p[i] >> y[i];
    vector<vector<int> > vals(n);
    for(int i=0;i<m;i++) vals[p[i]-1].push_back(y[i]);

    //各国nでソート
    for(int i=0;i<n;i++)sort(vals[i].begin(),vals[i].end());

    for(int i=0;i<m;i++){
        //国コード
        printf("%06d",p[i]);

        int id = lower_bound(vals[p[i]-1].begin(),vals[p[i]-1].end(),y[i]) - vals[p[i]-1].begin();
        printf("%06d",id+1);
        cout << endl;
    }
}
    

Measured memory_bytes: 7808
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;

int main() {
	dd n, m, k;
	while (cin >> n >> m >> k) {
		dd sum = 0;
		dd p = n;
		while (n <= (k + 0.5)) {
			sum += m;
			n += p;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n, a, b; cin >> n;
    ll ans = 0;
    REP(i,n-1){
        cin >> a >> b;
        if (a<b){
            ans+=a*(n-b+1);
        }
        else{
            ans+=b*(n-a+1);
        }
    }
    ll x = 0;
    FOR(i,1,n) x+=((n*n+n)-(i*i-i)-((n-i)*(n-i+1)))/2;
    cout << x-ans << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

#define N 10
#define M 10

int n, m, k[M], s[M][N], p[M];

int search(int a, int *cnt, int *isSwitch){
  if(a==n){
    int isAllLight=1;
    for(int i=0; i<m; i++){
      int sumSwitchOn=0;
      for(int j=0; j<k[i]; j++){
        if(isSwitch[s[i][j]-1]==1){
          sumSwitchOn++;
        }
      }
      if((sumSwitchOn&1)!=p[i]){
        isAllLight=0;
        break;
      }
    }
    if(isAllLight==1){
      *cnt=*cnt+1;
    }
  }
  else{
    for(int b=0; b<=1; b++){
      isSwitch[a] = b;
      search(a+1, cnt, isSwitch);
    }
  }
  return 0;
}

int main(){
  int isSwitch[N], cnt=0;
  scanf("%d %d", &n, &m);
  for(int i=0; i<m; i++){
    scanf("%d", &k[i]);
    for(int j=0; j<k[i]; j++){
      scanf("%d", &s[i][j]);
    } 
  }
  for(int i=0; i<m; i++){
    scanf("%d", &p[i]);
  }
  
  search(0, &cnt, isSwitch);
  printf("%d",cnt);
  
  return 0;
}

Measured memory_bytes: 128
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input().rstrip()

    n = len(s)
    if s[: int((n - 1) / 2)] == s[int((n + 3) / 2) - 1 :]:
        print("Yes")
    else:
        print("No")
    pass


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True
        
def size(x):
    return -par[find(x)]
    
n,m = map(int,input().split())

l =[[] for _ in range(n)]
par = [-1]*n

for i in range(m):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)
    unite(a-1,b-1)
    
ans = 0    
for i in range(n):
    ans = max(ans,size(i))
    
print(ans)

Measured memory_bytes: 48780
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <cmath>
using namespace std;

double calcS(int a, int b, int d);
double calcL(int a, int b, int d);
double calcH(int b, int d);

int main(void)
{	
	int a, b, d;
	cin >> a >> b >> d;
	
	cout << fixed << calcS(a, b, d) << endl;
	cout << fixed << calcL(a, b, d) << endl;
	cout << fixed << calcH(b, d) << endl;
	
	return 0;
}

double calcS(int a, int b, int d)
{
	return a * b * sin(d / 180.0 * M_PI) / 2;
}

double calcL(int a, int b, int d)
{
	double c = sqrt(pow(a, 2) + pow(b, 2) - (2 * a * b * cos(d / 180.0 * M_PI)));
	return a + b + c;
}

double calcH(int b, int d)
{
	return b * sin(d / 180.0 * M_PI);
}

Measured memory_bytes: 3492
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
int n;
ld dp[301][301][301];
/*ld f(int p, int q,int r)
{
    if(p==0 && q==0 && r==0) return 0;
    ld x,val1=0,val2=0,val3=0;
    if(p>0)
    {
    x=(ld)(p)/(p+q+r);
    if(dp[p-1][q][r]==0) dp[p-1][q][r]=f(p-1,q,r);
    val1= (p==0?0:x*dp[p-1][q][r]);
    }
    if(q>0)
    {
    x=(ld)(q)/(p+q+r);
    if(dp[p+1][q-1][r]==0) dp[p+1][q-1][r]=f(p+1,q-1,r);
    val2= (q==0?0:x*dp[p+1][q-1][r]);
    }
    if(r>0)
    {
    x=(ld)(r)/(p+q+r);
     if(dp[p][q+1][r-1]==0) dp[p][q+1][r-1]=f(p,q+1,r-1);
    val3= (r==0?0:x*dp[p][q+1][r-1]);
    }
   // cout<<val1<<" "<<val2<<" "<<val3<<endl;
    ld ans=(ld)(n)/(p+q+r)+val1+val2+val3;
   // if(p==1) cout<<ans<<endl;
    return ans;
}*/
void solve()
{
  //code begins from here//
    cin>>n;
    int a[4]={0};
    lop (i,n)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    lop(k,a[3]+1)
    {
        lop(j,a[2]+1+a[3])
        {
            lop(i,a[1]+1+a[2]+a[3])
            {
                if(i+k+j > a[1]+a[2]+a[3]) continue;
                if(i==j && j==k && i==0) continue;
                dp[i][j][k]=(ld)(n)/(i+j+k);
                if(i) dp[i][j][k]+=((ld)(i)/(i+j+k))*dp[i-1][j][k];
                if(j) dp[i][j][k]+=((ld)(j)/(i+j+k))*dp[i+1][j-1][k];
                if(k) dp[i][j][k]+=((ld)(k)/(i+j+k))*dp[i][j+1][k-1];
            }
        }
    }
    cout<<fixed<<setprecision(10)<<dp[a[1]][a[2]][a[3]]<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 212792
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

#define INF 1e9

vector<int> dijk(int s, vector<vector<pair<int, int> > > adjlist){
  int n = adjlist.size();
  vector<int> result(n, INF);

  priority_queue<pair<int, int> > wait;
  wait.push(make_pair(0, s));
  result[s] = 0;
  while(!wait.empty()){
    int nowcost = -wait.top().first;
    int nowpoint = wait.top().second;
    wait.pop();
    if(nowcost > result[nowpoint]){ continue; }

    for(int i = 0; i < (int)adjlist[nowpoint].size(); i++){
      int nextcost = nowcost + adjlist[nowpoint][i].first;
      int nextpoint = adjlist[nowpoint][i].second;
      if(result[nextpoint] > nextcost){
        result[nextpoint] = nextcost;
        wait.push(make_pair(-nextcost, nextpoint));
      }
    }    
  }

  return result;
}


int main(void){
  while(true){
    int n, m;
    cin >> n >> m;
    if(n == 0 && m == 0){ break; }
    
    int a, b, cost, time;
    vector<vector<pair<int, int> > > adjlist_cost(m);
    vector<vector<pair<int, int> > > adjlist_time(m);
    for(int i = 0; i < n; i++){
      cin >> a >> b >> cost >> time;
      --a;
      --b;
      adjlist_cost[a].push_back(make_pair(cost, b));
      adjlist_cost[b].push_back(make_pair(cost, a));
      adjlist_time[a].push_back(make_pair(time, b));
      adjlist_time[b].push_back(make_pair(time, a));
    }

    int k;
    cin >> k;

    int p, q, r;
    vector<int> result;
    for(int i = 0; i < k; i++){
      cin >> p >> q >> r;
      --p;
      --q;
      result = (r == 0) ? dijk(p, adjlist_cost) : dijk(p, adjlist_time);
      cout << result[q] << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3220
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A=gets.to_i
B=gets.to_i
ans=[true,true,true]
ans[A-1]=false
ans[B-1]=false
res=0
3.times do|i|
    if ans[i]
        res=i
        break
    end
end
puts res+1

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

#define MAX_N 20

int n;
int p[MAX_N]; 

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 1; i <= n - 2; i++) {
        int tmp[] = {p[i - 1], p[i], p[i + 1]};
        sort(tmp, tmp + 3);
        if (tmp[1] == p[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
const ll m=13000;
bitset<m*2> dp[81][81];
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    ll a[h+1][w+1],b;
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++)cin>>a[i][j];
    for(int i=1;i<=h;i++)for(int j=1;j<=w;j++){
        cin>>b;
        a[i][j]-=b;
        a[i][j]=abs(a[i][j]);
    }
    dp[1][0][m]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            dp[i][j]|=(dp[i-1][j]<<a[i][j]);
            dp[i][j]|=(dp[i][j-1]<<a[i][j]);
            dp[i][j]|=(dp[i-1][j]>>a[i][j]);
            dp[i][j]|=(dp[i][j-1]>>a[i][j]);
        }
    }
    for(int i=0;;i++){
        if(dp[h][w][m-i]||dp[h][w][m+i]){
            cout << i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 20992
#include <cstdio>
#include <vector>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

const int NR = 1e5 + 10;

vector<int> e[NR];
int n, K, a[NR], ans;
int dfs(int x) {
	int d = 0;
	for (int v : e[x]) d = max(d, dfs(v));
	if (d == K - 1 && a[x] != 1) return ++ans, 0;
	else return d + 1;
}

int main() {
	scanf("%d%d", &n, &K);
	iter(i, n) {
		scanf("%d", &a[i]);
		if (i != 1) e[a[i]].push_back(i);
		else if (a[i] != 1) ++ans;
	}
	a[1] = 1;
	dfs(1);
	printf("%d\n", ans);
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    vector<int> b(n+1);
    for(int i = n; i > 0; --i){
        int sum = 0;
        for(int j = i; j <= n; j += i) sum += b[j];
        if(sum%2 != a[i]) b[i] = 1;
    }
    vector<int> ans;
    for(int i = 0; i < n; ++i){
        if(b[i+1]) ans.push_back(i+1);
    }
    cout << ans.size() << "\n";
    if(ans.size() > 0) cout << ans[0];
    for(int i = 1; i < ans.size(); ++i){
        cout << " " << ans[i];
    }
    return 0;
}

Measured memory_bytes: 3192
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();
    let t: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut map: HashMap<char, Vec<usize>> = HashMap::new();
    for i in 0..s.len() {
        map.entry(s[i]).or_insert(Vec::new()).push(i);
    }

    let mut prev: isize = -1;
    let mut offset: usize = 0;
    for i in 0..t.len() {
        if let Some(v) = map.get(&t[i]) {
            let mut ok: isize = v.len() as isize;
            let mut ng: isize = -1;
            while (ok - ng).abs() > 1 {
                let mid = (ok + ng) / 2;
                if (v[mid as usize] + offset) as isize > prev {
                    ok = mid;
                } else {
                    ng = mid;
                }
            }
            if ok == v.len() as isize {
                offset += s.len();
                prev = (v[0] + offset) as isize;
            } else {
                prev = (v[ok as usize] + offset) as isize;
            }
        } else {
            return "-1".to_string();
        }
    }
    (prev + 1).to_string()
}


Measured memory_bytes: 4136
# 高橋君は青と赤の 2 色のボールを持っており、これらを一列に並べようとしています。
# 初め、列にボールはありません。根気のある高橋君は、次の操作を 10^100 回繰り返します。
# 列の末尾に、A 個の青いボールを加える。その後、列の末尾に B 個の赤いボールを加える。
# こうしてできる列の先頭から N 個のボールのうち、青いボールの個数はいくつでしょうか。

input = gets.chomp.split
n = input[0].to_i
a = input[1].to_i
b = input[2].to_i

one_set = a + b
blue_count = (n / one_set) * a

if n % one_set > a
    blue_count += a
else
    blue_count += n % one_set
end

puts blue_count

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

int main(void) {
  string N;
  cin >> N;
  int cnt = 0;
  for (int i = 1; i < N.length(); i++) {
    if (N[i] == '9') cnt++;
  }

  if (cnt == N.length() - 1) {
    cout << (N[0] - '0') + (N.length() - 1) * 9 << endl;
  } else {
    cout << (N[0] - '0') - 1 + (N.length() - 1) * 9 << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const int N = 100006;
const int MOD = 1e9 + 7;
int occ[N];
int F[N], I[N];
ll pow1(ll n, ll p){
  ll c, r;
  c = n;
  r = 1;
  while(p){
    if(p & 1)
      (r *= c) %= MOD;
    p /= 2;
    (c *= c) %= MOD;
  }
  return r;
}
void init(){
  F[0] = I[0] = 1;
  for(int i = 1;i < N;i++){
    F[i] = 1ll * F[i - 1] * i % MOD;
    I[i] = pow1(F[i], MOD - 2);
  }
}
int C(int n, int k){
  if(k > n)
    return 0;
  return 1ll * F[n] * I[k] % MOD * I[n - k] % MOD;
}
signed main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  init();
  int n;
  cin >> n;
  n++;
  int a[n];
  for(int i = 0;i < n;i++)
    cin >> a[i];
  memset(occ, -1, sizeof(occ));
  int x, y;
  for(int i = 0;i < n;i++){
    if(occ[a[i]] != -1){
      x = occ[a[i]];
      y = i;
      break;
    }
    occ[a[i]] = i;
  }
  for(int k = 1;k <= n;k++){
    printf("%lld\n", 1ll * (1ll * C(n, k) - C(n - (y - x + 1), k - 1) + MOD) % MOD);
  }
}


Measured memory_bytes: 2816
#include <string>

#include <vector>
#include <iostream>

using namespace std;

int main() {

	char s[4];
	cin >> s;
	int ans = 0;

	for (auto i : s) {
		if (i == '+') {
			ans++;
		}
		else if (i == '-') {
			ans--;
		}
	}

	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define repi(i,a,b) for(int i = (a); i<= (b); i++)
#define repA(i,n) for(int i=n; i>=0; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())

typedef long long ll;
typedef long double ld;
const ll mod = (ll)(1e9+7);//998244353;
const int N = (int)(2e6+5);

void pre() {

}

void solve() {
	ll a;
  cin>>a;
  cout<<(a+a*a+a*a*a);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  #endif
  int t = 1;
  pre();
  //cin>>t;
  rep(i,t)  {
    //cout<<"\nCase #"<<(i+1)<<"\n";
    solve();
    cout<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,count=0,ans=0;
 string s;
 cin>>n;
 cin>>s;
 for(int i=0;i<n;i++)
 {
   if(s[i]=='I')
   count++;
   else 
   ans = max(ans,count),count--;
 }
 ans = max(count,ans);
 cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <stdio.h>
int main() {
  int a, b, c, d, e;
  int sum = 0;
  scanf("%d\n", &a);
  scanf("%d\n", &b);
  scanf("%d\n", &c);
  scanf("%d\n", &d);
  scanf("%d\n", &e);
  if(a >= 40) {
    sum = sum + a;
  } else {
    sum = sum + 40;
  }
  if(b >= 40) {
    sum = sum + b;
  } else {
    sum = sum + 40;
  }
  if(c >= 40) {
    sum = sum + c;
  } else {
    sum = sum + 40;
  }
  if(d >= 40) {
    sum = sum + d;
  } else {
    sum = sum + 40;
  }
  if(e >= 40) {
    sum = sum + e;
  } else {
    sum = sum + 40;
  }
  printf("%d\n", sum / 5);
  return 0;
}

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

const int N = 3e3 + 5;
int dp[N][N];
string s, t;
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> s >> t;
    for (int i = 1; i <= s.size(); i++) {
        for (int j = 1; j <= t.size(); j++) {
            if (s[i - 1] == t[j - 1])
                dp[i][j] = 1 + dp[i - 1][j - 1];
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    int i = s.size(), j = t.size();
    string out = "";
    while (i >= 1 && j >= 1) {
        if (s[i - 1] == t[j - 1]) {
            out += s[i - 1];
            i--;
            j--;
        }
        else {
            if (dp[i - 1][j] == dp[i][j])
                i--;
            else
                j--;
        }
    }
    reverse(out.begin(), out.end());
    cout << out;
    return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

ll F(ll l,ll r){
    if(l+r>=0){return (l+r)/2;}
    else if((-l-r)%2==1){return (l+r+1)/2-1;}
    else return (l+r)/2;
}

ll INF=1000000000000000003;

int main(){
    ll N;
    cin >> N;   
    ll K;
    cin >> K;
    vector<ll> A(N,0);
    ll Mcounter=0,Zcounter=0,Pcounter=0;
    for(ll i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0)Mcounter++;
        else if(A[i]==0)Zcounter++;
        else if(A[i]>0)Pcounter++;
    ;}
    sort(A.begin(), A.end());
    ll X=Mcounter,Z=Zcounter,Y=Pcounter;
    
    if(K<=X*Y+X*Z+Y*Z+Z*(Z-1)/2&&K>X*Y){cout<<0<<endl;}
    else if(K<=X*Y){
        ll L=-INF,R=INF;
        while(L+1<R){
            ll M=(L+R)/2;
            ll counter=0;
            for(ll i=0;i<X;i++){
                if(A[i]*A[N-1]>M){continue;}
                else if(A[i]*A[X+Z]<=M){counter+=Y;continue;}
                ll l=X+Z,r=N-1;
                while(l+1<r){
                    ll m=(l+r)/2;
                    if(A[i]*A[m]<=M){r=m;}
                    else l=m;
                }
                counter+=N-r;
            ;}
            if(counter>=K)R=M;
            else L=M;
        }
        cout<<R<<endl;
    }
    else{
        ll L=-INF,R=INF;
        while(L+1<R){
            ll M=F(L,R);
            ll counters=X*Y+(X+Y)*Z+Z*(Z-1)/2;
            ll counter=0;
            for(ll i=X+Z;i<N;i++){
                if(A[i]*A[N-1]<=M){counter+=Y-1;continue;}
                else if(A[i]*A[X+Z]>M){continue;}
                ll l=X+Z,r=N-1;
                while(l+1<r){
                    ll m=F(l,r);
                    if(A[i]*A[m]>M){r=m;}
                    else l=m;
                }
                counter+=l-X-Z+1;
                if(i<=l)counter--;
            ;}
            for(ll i=0;i<X;i++){
                if(A[i]*A[0]<=M){counter+=X-1;continue;}
                else if(A[i]*A[X-1]>M){continue;}
                ll l=0,r=X-1;
                while(l+1<r){
                    ll m=F(l,r);
                    if(A[i]*A[m]<=M){r=m;}
                    else l=m;
                }
                counter+=X-r;
                if(r<=i)counter--;
            ;}
            counter=counters+counter/2;
            if(counter>=K){
                R=M;
            }
            else L=M;

        }
        cout<<R<<endl;
    }


return 0;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int A[1000000];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int n;
    cin >> n;
    rep(i, n) { cin >> A[i]; }

    int q, k, sum = 0;
    cin >> q;
    while (q--) {
        cin >> k;
        // lower_bound は位置を、＊をつけることで実体を表示。
        // cout << k << " " << *lower_bound(A, A + n, k) << endl;

        if (*lower_bound(A, A + n, k) == k) sum++;
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3424