akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  
#define INF 2000000010
#define mod7 1000000007
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define INF_LL 9223372036854775
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double 
 
using namespace std;

LL N, X;

LL solve(LL a, LL b){
  if(b%a == 0)
    return (b/a)*2*a - a;
  else{
    return solve(b%a, a) + (b/a)*a*2;
  }
}

int main(){
  
  cin >> N >> X;
  
  cout << N + solve(min(X,N-X), max(X,N-X)) << endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    string s;cin >> s;

    int j=s.size()-1;
    int cnt=0;
    for(int i=0;i<(int)s.size();i++){
        while(s[i]=='R'){
            i++;
        }
        while(s[j]=='W'){
            j--;
        }
        if(j<0)break;
        if(i>j)break;
        swap(s[i],s[j]);
        cnt++;
        j--;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3740
import sys

mod = 10**9 + 7
N = int(sys.stdin.readline())

stones = []
for _ in range(N):
    stones.append(int(sys.stdin.readline()))

left = [-1 for _ in range(2*10**5+1)]
dp = [0 for _ in range(N+5)]
dp[0] = 1
for i in range(N):
    dp[i+1] = dp[i]
    # 同じ色が前回出現した位置
    c = stones[i]
    if 0 <= left[c] < i - 1:
        dp[i+1] += dp[left[c] + 1]
    
    dp[i+1] %= mod
    left[c] = i

print(dp[N])

Measured memory_bytes: 123736
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;

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




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



int n;
cin>>n;
vector<int>g[n+1];
map<pii,int>mp;

for(int i=1;i<n;i++)
{
  int x,y,c;
  cin>>x>>y>>c;  
  g[x].push_back(y);
  g[y].push_back(x);
  mp[{min(x,y),max(x,y)}]=c;
}
vector<int>dis(n+1,-1);
queue<int>q;
q.push(1);
dis[1]=0;

while(q.size())
{
  int x=q.front();
  q.pop();

  for(auto i : g[x])
  {
   
    if(dis[i]==-1)
    {
      dis[i]=dis[x]+mp[{min(x,i),max(x,i)}];  
      q.push(i);
    }
  }
}

for(int i=1;i<=n;i++)
{
 cout<<(dis[i]&1)<<"\n";
}





  
}



Measured memory_bytes: 13440
def solve():
    N, A, B = map(int, input().split())
    
    if (B - A) % 2 == 0:
        print((B - A) // 2)
    else:
        ans = min(A - 1, N - B) + 1 + (B - A - 1) // 2
        print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC060Sentou
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, T;
            string[] vals = Console.ReadLine().Split(' ');
            N = int.Parse(vals[0]);
            T = int.Parse(vals[1]);
            int[] t = new int[N];
            vals = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
                t[i] = int.Parse(vals[i]);

            long sum = 0;
            for(int i=1; i < N; i++)
            {
                if(t[i] - t[i-1] > T)
                {
                    sum += T;
                }
                else
                {
                    sum += t[i] - t[i - 1];
                }
            }

            sum += T;

            Console.WriteLine(sum);
        }
    }
}


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

int main(){
  int64_t X;
  cin>>X;
  bool flag=false;
  for(int64_t A=0;A<=200;++A){
    for(int64_t B=-200;B<=A;++B){
      int64_t a=pow(A,5);
      int64_t b=pow(B,5);
      if(a-b==X){
        cout<<A<<" "<<B<<endl;
        flag=true;
      }
      if(flag) break;
    }
    if(flag) break;
  }

}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    forn(n) {
        cin >> v[i];
    }
    bool ok = true;
    forn(n){
        if((v[i]&1) == 0){
            if(v[i]%3 != 0 and v[i]%5 != 0){
                ok = false;
            }
        }
    }
    if(ok){
        cout << "APPROVED\n";
    }
    else{
        cout << "DENIED\n";
    }
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define pii pair<int,int>
#define prec(n) fixed<<setprecision(n)
#define MOD 1000000007
#define eps 1e-8
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int nCrdp[2001][2001];

void nCr(){
    for(int i=0;i<=2000;i++)nCrdp[i][i]=1,nCrdp[i][0]=1;
    for(int i=1;i<=2000;i++){
        for(int j=i+1;j<=2000;j++){//j>i
            nCrdp[j][i]=(nCrdp[j-1][i-1]+nCrdp[j-1][i])%MOD;
        }
    }
}

signed main(){
    FASTER;
    nCr();
    int n,k;cin>>n>>k;
    int b,r;b=k,r=n-k;
    for(int i=1;i<=k;i++)
    cout<<(nCrdp[b-1][i-1]*nCrdp[r+1][i])%MOD<<"\n";
}


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

#define deb(x)        cerr << #x << " = " << x << "\n";
#define deb2(x, y)    cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";

#define pb push_back
#define mp make_pair
#define F  first
#define S  second

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

typedef long long ll;  

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a*c, a*d, b*c, b*d});
}

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

    ll tc = 1;
    //cin >> tc;

    while(tc--) {
        solve();
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>


int main()
{

	int N;

	std::cin >> N;

	if (N == 1)
		std::cout << "Hello World" << std::endl;
	else
	{
		int A, B;

		std::cin >> A >> B;

		std::cout << A + B << std::endl;
	}
	

	return 0;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    lli w, h, n;
    cin >> w >> h >> n;
    lli sum = 0;
    lli rec[4] = {0, w, 0, h};

    for(int i=0; i<n; i++){
        lli x, y, a;
        cin >> x >> y >> a;
        if(a==1){
            if(x>rec[0])
                rec[0] = x;
        }
        else if(a==2){
            if(x<=rec[1])
                rec[1] = x;
        }
        else if(a==3){
            if(y>=rec[2])
                rec[2] = y;
        }
        else if(a==4){
            if(y<=rec[3])
                rec[3] = y;
        }
    }
    if(rec[0]<rec[1] && rec[2]<rec[3])
        sum = (rec[1]-rec[0])*(rec[3]-rec[2]);
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS

int main(void) {
	int N, M;
	scanf("%d%d", &N, &M);
	printf("%d", ((N * (N - 1)) / 2) + ((M * (M - 1)) / 2));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<bits/extc++.h>
const int maxn = 200200;
typedef long long ll;
int fa[maxn],p[maxn],n;
int a0[maxn],a1[maxn],ok[maxn]; 
struct cmp{
	inline bool operator () (const int & x,const int & y) const {
		return (ll) a0[x] * a1[y] < (ll) a1[x] * a0[y];
	}
};
typedef __gnu_pbds::priority_queue<int,cmp> heap;
typedef heap::point_iterator iter;
ll ans = 0;
heap q; iter it[maxn];
inline int find(int x){ return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main(){
	std::ios::sync_with_stdio(false),std::cin.tie(0);
	std::cin >> n;
	for(int i = 2;i <= n;++i) std::cin >> p[i];
	for(int i = 1,x;i <= n;++i) std::cin >> x,++i[x ? a1 : a0], fa[i] = i;
	for(int i = 2;i <= n;++i)
	it[i] = q.push(i); 
	for(;!q.empty();){
		int t = q.top(); q.pop();
		int f = find(p[t]);
		ans += (ll) a0[t] * a1[f];
		a0[f] += a0[t], a1[f] += a1[t];
		fa[t] = f;
		if(f != 1) q.modify(it[f],f);
	}
	std::cout << ans << '\n';
}


Measured memory_bytes: 14592
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n;
	cin >> n;

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

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

	deque<int> arrangement;
	arrangement.push_back(a.front());
	a.pop_front();
	while (a.size()) {
		if (abs(arrangement.front() - a.front()) >= abs(arrangement.front() - a.back()) && 
			abs(arrangement.front() - a.front()) >= abs(arrangement.back() - a.front()) &&
			abs(arrangement.front() - a.front()) >= abs(arrangement.back() - a.back())) {
			arrangement.push_front(a.front());
			a.pop_front();
		} 
		else if (abs(arrangement.front() - a.back()) >= abs(arrangement.front() - a.front()) && 
				 abs(arrangement.front() - a.back()) >= abs(arrangement.back() - a.front()) &&
				 abs(arrangement.front() - a.back()) >= abs(arrangement.back() - a.back())) {
			arrangement.push_front(a.back());
			a.pop_back();
		}
		else if (abs(arrangement.back() - a.front()) >= abs(arrangement.front() - a.back()) && 
				 abs(arrangement.back() - a.front()) >= abs(arrangement.front() - a.front()) &&
				 abs(arrangement.back() - a.front()) >= abs(arrangement.back() - a.back())) {
			arrangement.push_back(a.front());
			a.pop_front();
		} else {
			arrangement.push_back(a.back());
			a.pop_back();
		}
	}

	long long sum = 0;
	for (int i = 1; i < n; ++i) {
		sum += abs(arrangement[i] - arrangement[i - 1]);
	}

	cout << sum << "\n";

	return 0;

}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <cstdlib>
using namespace std;
const int INF=1e9+5;
int main()
{
    int n;
    cin>>n;
    vector<int> dp(3);
    for(int day=0;day<n;day++)
    {
        vector<int> new_dp(3,0 );
        vector<int> c(3);
        for(int i=0;i<3;i++)
        {
            cin>>c[i];
        }

        for(int i=0;i<3;++i)
        {
            for(int j=0;j<3;j++)
            { 
                if(i!=j)
                {
                    new_dp[j]=max(new_dp[j],dp[i]+c[j]);
                }
            }
        }
        dp=new_dp;
    }
    cout<<max({dp[0],dp[1],dp[2]}) ;
	return 0;
}

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

void chmin(int &a, int b){
  if (a > b){
    a = b;
  }
}

int INF = 1000000000;
int N;
vector<int> dp(100010), h(100010);

int rec(int i){
  if(dp.at(i) < INF){
    return dp.at(i);
  }
  if(i == 0){
    return 0;
  }
  int res = INF;
  chmin(res, rec(i - 1) + abs(h.at(i - 1) - h.at(i)));
  if(i > 1){
    chmin(res, rec(i - 2) + abs(h.at(i - 2) - h.at(i)));
  }
  return dp.at(i) = res;
}

int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> h.at(i);
    dp.at(i) = INF;
  }
  cout << rec(N - 1) << endl;
}

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

using namespace std;

int h, w, k;
int cnt, ans;

int main() {

    scanf("%d %d %d", &h, &w, &k);
    vector<vector<char>> map(h, vector<char>(w, 0));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            scanf(" %c", &map[i][j]);
        }
    }

    for (int mask_h = 0; mask_h < (1 << h); ++mask_h) {
        for (int mask_w = 0; mask_w < (1 << w); ++mask_w) {
            cnt = 0;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if ((mask_h >> i & 1) == 0 && (mask_w >> j & 1) == 0 && map[i][j] == '#') {
                        cnt++;
                    }
                }
            }
            if (cnt == k) {
                ans++;
            }
        }
    }

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


Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int fw(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}
int bw(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
}
//qsort(vector, n, sizeof(int), fw);
int main() {
	long long int x, y, xx, yy;
	int i, j;
	scanf("%lld %lld", &x, &y);
	xx = x; yy = y;
	for (i = 0; xx != 0; i++)
	{
		xx = xx >> 1;
	}
	for (j = 0; yy != 0; j++)
	{
		yy = yy >> 1;
	}
	x = x << (j - i);
	if (x <= y) j++;
	printf("%d", j-i);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	long long int i,j,k,l,m,n;
	cin>>n;
	long long int a;
	map<long long int,long long int>mp;
	for(i=0;i<n;i++)
	{
		cin>>a;
		if(mp[a]!=0)
		{
			cout<<"NO";
			return 0;
		}
		mp[a]++;
	}
	cout<<"YES";
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int  main()
{
	int n; cin >> n;
	vector<int> a(n);
	priority_queue<pair<int, int > > q;
	rep(i, n) 
	{
		cin >> a[i];
		pair<int, int > p = make_pair(a[i], i);
		q.push(p);
	}
	int top = q.top().second;
	q.pop();
	int sec = q.top().second;
	for (int i = 0; i < n; i++)
	{
		if (i == top)
			cout << a[sec] << endl;
		else
			cout << a[top] << endl;
	}
	return (0);
}


Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll a[200100];

int main()
{
    ll k , n;  cin >> k >> n;
    for(int i = 0;i<n;i++)  cin >> a[i];
    ll Ans = INT_MAX;
    for(int i = 0;i<n;i++)
        Ans = min(Ans , (i - 1 >= 0 ? i + 1 < n ? a[i] : a[i] - a[0] : a[i]) + (i + 1 < n ? k - a[i + 1] : 0));
    if(n == 1)  Ans = 0;
    cout << Ans;
    return 0;
}


Measured memory_bytes: 1792
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
t = []
kankaku = [0 for i in range(27)]
last = [0 for i in range(27)]
man = 0
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))
for i in range(D):
    t.append(int(input())-1)
for i in range(D):
    man += s[i][t[i]]
    last[t[i]] = i + 1
    for i2 in range(26):
        man -= (i + 1 - last[i2]) * c[i2]
    print(man)

Measured memory_bytes: 9376
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <list>
#include <string.h>
using namespace std;
#define fo(i,l,r) for(int i=l;i<=r;++i)
#define fi(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define po pop_back
#define INF 1e9+9
void input(vector<int>& arr,int n){
  fo(i,0,n-1){
    cin>>arr[i];
  }
}
void solve(){
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.length()<=k){
    cout<<s<<endl;
  }else{
    s = s.substr(0,k);
    s.append("...");
    cout<<s<<endl;
  }
  //cout<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3128
/* 
   AOJ 2252
   koukyoukoukokukikou
   2015.4.26
 */

#include<stdio.h>

int count_turnover(char input_str[])
{
  int i, prev_key = 0, left_key = -1, right_key = 1, count = 0;
  for(i = 0; input_str[i] != '\0'; i++)
    {
      switch(input_str[i])
	{
	case 'q':
	case 'w':
	case 'e':
	case 'r':
	case 't':
	case 'a':
	case 's':
	case 'd':
	case 'f':
	case 'g':
	case 'z':
	case 'x':
	case 'c':
	case 'v':
	case 'b':
	  if(prev_key == right_key)
	    {
	      count++;
	    }
	  prev_key = left_key;
	  break;
	default:
	  if(prev_key == left_key)
	    {
	      count++;
	    }
	  prev_key = right_key;
	}
    }
  return count;
}

int main(void)
{
  char input_str[33], count = 0;
  while(1)
    {
      scanf("%s", input_str);
      if(input_str[0] == '#')
	{
	  break;
	}

      count = count_turnover(input_str);
      printf("%d\n", count);
    }
  return 0;
}

Measured memory_bytes: 540
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int D;
ll G;
vector<ll> p,c;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> D >> G;
  p.resize(D);
  c.resize(D);
  rep(i,D){
    cin >> p[i] >> c[i];
  }

  ll ret = 1 << 29;
  for(int bit = 0 ; bit < (1 << D) ; bit++){
    ll sum = 0;
    ll num = 0;
    rep(i,D){
      if(bit & (1 << i)){
        sum += c[i] + p[i] * 100 * (i+1);
        num += p[i];
      }
    }
    if(sum >= G){
      ret = min(ret,num);
    }
    else{
      for(int i = D-1; i>= 0; i--){
        if(bit & (1 << i)){
          continue;
        }
        for(int j = 0 ; j < p[i]; j++){
          if(sum >= G){
            break;
          }
          sum += 100 * (i+1);
          num++;
        }
      }
      ret = min(ret,num);
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

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

    ll n, x = 0, ans = 0;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'I')
            x++;
        else
            x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C = map(int, input().split())
modlist = []
now = A
flag = True
while flag:
	if now%B == C:
		break
	if now%B in modlist:
		flag = False
	else:
		modlist.append(now%B)
	now += A
if flag: print('YES')
else: print('NO')

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n;
    scanf("%d", &n);
    if (n / 10 == 9 || n % 10 == 9)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

void debug(vector<ll> v, ll n) {
  REP(i, n) {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main() {
  ll input(n, k);
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  REP(j, k) {
    vector<ll> table(n + 1, 0);

    REP(i, n) {
      table[max(0ll, i - a[i])] += 1;
      table[min(n, i + a[i] + 1)] -= 1;
    }

    vector<ll> cumsum(n + 1, 0);
    partial_sum(table.begin(), table.end(), cumsum.begin());

    // debug(table, n);
    // debug(cumsum, n);

    REP(i, n) a[i] = cumsum[i];

    ll sum = accumulate(a.begin(), a.end(), 0ll);
    if (sum == n * n) {
      break;
    }
  }
  REP(i, n - 1) {
    cout << a[i] << " ";
  }
  cout << a[n - 1] << endl;
}


Measured memory_bytes: 8008
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
 
using namespace std;
  
int main(){
  string S;
  cin >> S;
  
  string ans = "No";
  if((S[2] == S[3]) && (S[4] == S[5])) ans = "Yes";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
#define vsort(v) sort(v.begin(), v.end())
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = 0;
	int tmp = 0;
	bool flag = false;
	for(int i = 0; i < s.size(); i++) {
		if(s[i] == 'A') flag = true;
		if(flag) tmp++;
		if(s[i] == 'Z' && flag) ans = tmp;
	}
	cout << ans << endl;

}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    string S;
    cin >> S;
    int N=S.length();
    if(N!=26){
        bool b[26]={};
        rep(i,N){
            b[S[i]-'a']=true;
        }
        cout << S;
        rep(i,26){
            if(!b[i]){
                char c='a'+i;
                cout << c;
                break;
            }
        }
    }
    else{
        if(S=="zyxwvutsrqponmlkjihgfedcba")cout << -1;
        else{
            int m;
            bool b[26]={};
            for(int i=N-1;i>=0;i--){
                b[S[i]-'a']=true;
                if(S[i]>S[i-1]){
                  m=i-1;
                  break;
                }
            }
            rep(i,m){
                cout << S[i];
            }
            char c='z';
            for(int i=m;i<26;i++){
                if(S[i]>S[m] && S[i]<c)c=S[i];
            }
            cout << c;
          	cerr << m;
        }
    }

}

/*



 */




Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ARC064D
    {
        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }

        static public void Main(string[] args)
        {
            var S = Console_.NextString().ToArray();
            if (S[0] == S[S.Length - 1])
            {
                Console.WriteLine(S.Length % 2 == 0 ? "First" : "Second");
                return;
            }
            else
            {
                var oddChara = false;
                for (int i = 1; i < S.Length - 1; ++i)
                {
                    if (S[i] != S[0] && S[i] != S[S.Length - 1])
                    {
                        oddChara = true;
                        break;
                    }
                }
                if (oddChara)
                {
                    Console.WriteLine(S.Length % 2 == 1 ? "First" : "Second");
                    return;
                }
                else
                {
                    Console.WriteLine("Second");
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 14688
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

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

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

    return arr
  
A, B = input().split()
 
A = int(A)
B = int(B)

gcd_num =gcd(A,B)

gcd_list = factorization(gcd_num)

t = len(gcd_list)
if gcd_list == [[1, 1]]:
  print(t)
else:
  print(t+1)

Measured memory_bytes: 38592
using System;
using System.Linq;

namespace atPra98B
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int ret = 0;
            for (int i = 1; i < n; i++)//iで分割する
            {
                string s1 = s.Substring(0, i);
                string s2 = s.Substring(i, n - i);

                int count = 0;
                for (char j = 'a'; j <= 'z'; j++)
                {
                    if(s1.Contains(j) && s2.Contains(j)) count++;
                }
                ret = Math.Max(ret, count);
            }
            Console.WriteLine(ret);
        }
    }
}




Measured memory_bytes: 13268
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}

int main() {
  string S;
  cin >> S;
  ll s = S.size();
  bool ans = true;
  bool c = false;
  if(S[0] != 'A')ans = false;
  if(isupper(S[1]))ans = false;
  if(isupper(S[s - 1 ]))ans = false;
  for(int i = 2;i<s - 1;i++){
  if(c == false && S[i] == 'C')c = true;
    else if(c == true && isupper(S[i]))ans = false;
  }
  if(c && ans)cout << "AC" << endl;
  else cout << "WA" << endl;
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define endl '\n'

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int maxn = 85;
const int INF = 1e9+10;

ii g[maxn][maxn];
int dp[maxn][maxn][3*maxn*maxn];
int w,h;

int get_ans(int i,int j,int somaa,int somab,int diff){
	if(i>h || j>w)
		return INF;
	if(dp[i][j][diff]!=-1)
		return dp[i][j][diff];
	if(i==h && j==w){
		int s1 = (somaa+g[i][j].ff);
		int s2 = (somaa+g[i][j].ss);
		int s3 = (somab+g[i][j].ff);
		int s4 = (somab+g[i][j].ss);
		return min(abs(s1-s4),abs(s2-s3));
	}
	int ans1 = get_ans(i+1,j,somaa+g[i][j].ff,somab+g[i][j].ss,abs((somaa+g[i][j].ff)-(somab+g[i][j].ss)) );
	int ans2 = get_ans(i+1,j,somaa+g[i][j].ss,somab+g[i][j].ff,abs((somaa+g[i][j].ss)-(somab+g[i][j].ff)) );
	int ans3 = get_ans(i,j+1,somaa+g[i][j].ff,somab+g[i][j].ss,abs((somaa+g[i][j].ff)-(somab+g[i][j].ss)) );
	int ans4 = get_ans(i,j+1,somaa+g[i][j].ss,somab+g[i][j].ff,abs((somaa+g[i][j].ss)-(somab+g[i][j].ff)) );

	return dp[i][j][diff]=min({ans1,ans2,ans3,ans4});
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	cin>>h>>w;
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>g[i][j].ff;
		}
	}
	for(int i=1;i<=h;++i){
		for(int j=1;j<=w;++j){
			cin>>g[i][j].ss;
		}
	}
	memset(dp,-1,sizeof dp);
	cout<<get_ans(1,1,0,0,0)<<endl;
	return 0;
}

Measured memory_bytes: 612096
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

ll func(ll h) {
	if (h == 1) return 1;
	return 2 * func(h / 2) + 1;
}

int main() {
	ll h; cin >> h;
	cout << func(h) << endl;
	return 0;
}


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

int main(){
	int x;
  	cin>>x;
  	if(x>=400 && x<600)
      cout<<8<<endl;
  if(x>=600 && x<800)
      cout<<7<<endl;
  if(x>=800 && x<1000)
      cout<<6<<endl;
  if(x>=1000 && x<1200)
      cout<<5<<endl;
  if(x>=1200 && x<1400)
      cout<<4<<endl;
  if(x>=1400 && x<1600)
      cout<<3<<endl;
  if(x>=1600 && x<1800)
      cout<<2<<endl;
  if(x>=1800 && x<2000)
      cout<<1<<endl;
}

Measured memory_bytes: 3588
import heapq

n = int(input())
v = list(map(float,input().split()))

heapq.heapify(v)
for i in range(n-1):
    v1 = heapq.heappop(v)
    v2 = heapq.heappop(v)
    heapq.heappush(v,(v1+v2)/2)
ans = heapq.heappop(v)
print(ans)


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

#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
// #define m ((l + r) >> 1)

using namespace std;

void setIO(string name) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
}

// using namespace __gnu_pbds;
// using mii = gp_hash_table<int, int>;
// typedef tree<pii, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MN = 1 * 1e3 + 5, LN = 17, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    vector<int> a(3); cin >> a[0] >> a[1] >> a[2];
    sort(all(a));
    if (a[0] == a[1] && a[1] != a[2]) cout << "Yes\n";
    else if (a[1] == a[2] && a[1] != a[0]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc109/tasks/abc109_c

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    long n, x;
    vector<bool> v1;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    int pos[n];

    for (int i = 0; i < n; i++) {
        cin >> pos[i];
    }
    sort(pos, pos + n);

    int ans = abs(x - pos[0]);
    // 開始時点からの差分
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, abs(x - pos[i]));
    }
    cout << ans << endl;

    return 0;
}


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

int i;
int main(){
vector<int>a(5);
for (i=0;i<5;i++){
  cin >> a[i];
}
if (a[2]+a[4]<=a[0] && a[2]-a[4]>=0 && a[3]+a[4]<=a[1] && a[3]-a[4]>=0){
  cout << "Yes" << endl;
} else {
  cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 D, T, S;
  cin >> D >> T >> S;
  if (T * S < D)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3628
N, M = map(int, input().split())
X = list(map(int, input().split()))

# ソートして、差が大きい区間をサボるようにコマを配置すればよい
Y = sorted(X)
ans = sum(
    sorted(
        (
            a - b
            for a, b in zip(Y[1:], Y)
        ),
        reverse=True
    )[(N - 1):]
)

print(ans)


Measured memory_bytes: 13960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    ll ans=0;
    ans+=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    ans-=min(c,k);
    cout << ans;


    
}

Measured memory_bytes: 3632
var
	h,w,k,i,j:Longint;
	m:int64=1000000007;
	dp:array[1..101,1..8]of int64;
	p:array[0..7]of Longint=(1,1,2,3,5,8,13,21);
begin
	read(h,w,k);
	dp[1,1]:=1;
	for i:=1 to h do for j:=1 to w do begin
		if j>1 then dp[i+1,j-1]:=(dp[i+1,j-1]+dp[i,j]*p[j-2]*p[w-j])mod m;
		dp[i+1,j]:=(dp[i+1,j]+dp[i,j]*p[j-1]*p[w-j])mod m;
		if j<w then dp[i+1,j+1]:=(dp[i+1,j+1]+dp[i,j]*p[j-1]*p[w-j-1])mod m;
	end;
	writeln(dp[h+1,k]);
end.

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

typedef long long ll;

using namespace std;

int main(){
	
	double N;
	int K;
	scanf("%lf",&N);
	scanf("%d",&K);
	double sum = 0;
	vector<int> powers;
	for(int i = 0; i <= 32; i++){
		powers.push_back(pow(2, i));
	}
	
	for(auto i = 1; i <= N; i++){
		int x = (K/i);
		if(K % i != 0){ x++; }
		int pos = lower_bound(powers.begin(), powers.end(), x) - powers.begin();
		sum +=  pow((0.500000), pos);
	}
	sum *= (1/N);
	printf("%.17g \n", sum);
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	static ArrayList<String> plist = new ArrayList<String>();
    public static void main(String[] args){
    	Scanner input = new Scanner(System.in);
    	permutation("",0);
    	while(true){
    		int[] n = new int[4];
    		n[0] = input.nextInt();
    		n[1] = input.nextInt();
    		n[2] = input.nextInt();
    		n[3] = input.nextInt();
    		if(n[0] == 0 && n[1] == 0 && n[2] == 0 && n[3] == 0)break;
    		System.out.println(num(n));
    	}
    }
    
    public static String num(int[] n){
    	for(int i = 0 ; i < plist.size() ; i++){
			int[] p = new int[4];
			String pr = plist.get(i);
			p[0] = pr.charAt(0)-48;
			p[1] = pr.charAt(1)-48;
			p[2] = pr.charAt(2)-48;
			p[3] = pr.charAt(3)-48;
    		for(int j = 0 ; j < 3 ; j++){
    			for(int k = 0 ; k < 3 ; k++){
    				for(int l = 0 ; l < 3 ; l++){
    					
    					int a1 = calculate(n[p[0]],n[p[1]],j);
    					int a2 = calculate(a1,n[p[2]],k);
    					int a3 = calculate(a2,n[p[3]],l);
    					if(a3 == 10)return "((("+n[p[0]]+" "+calname(j)+" "+n[p[1]]+")"+" "+calname(k)+" "+n[p[2]]+") "+calname(l)+" "+n[p[3]]+")";
    					
    					a1 = calculate(n[p[0]],n[p[1]],j);
    					a2 = calculate(n[p[2]],n[p[3]],l);
    					a3 = calculate(a1,a2,k);
    					if(a3 == 10)return "(("+n[p[0]]+" "+calname(j)+" "+n[p[1]]+")"+" "+calname(k)+" ("+n[p[2]]+" "+calname(l)+" "+n[p[3]]+"))";
    					
    					a1 = calculate(n[p[1]],n[p[2]],k);
    					a2 = calculate(n[p[0]],a1,j);
    					a3 = calculate(a2,n[p[3]],l);
    					if(a3 == 10)return "(("+n[p[0]]+" "+calname(j)+" ("+n[p[1]]+""+" "+calname(k)+" "+n[p[2]]+")) "+calname(l)+" "+n[p[3]]+")";
    					
    					a1 = calculate(n[p[1]],n[p[2]],k);
    					a2 = calculate(a1,n[p[3]],l);
    					a3 = calculate(n[p[0]],a2,j);
    					if(a3 == 10)return "("+n[p[0]]+" "+calname(j)+" (("+n[p[1]]+""+" "+calname(k)+" "+n[p[2]]+") "+calname(l)+" "+n[p[3]]+"))";
    					
    					a1 = calculate(n[p[2]],n[p[3]],l);
    					a2 = calculate(n[p[1]],a1,k);
    					a3 = calculate(n[p[0]],a2,j);
    					if(a3 == 10)return "("+n[p[0]]+" "+calname(j)+" ("+n[p[1]]+""+" "+calname(k)+" ("+n[p[2]]+" "+calname(l)+" "+n[p[3]]+")))";
    				}
    			}
    		}
    	}
    	return "0";
    }
    
    public static void permutation(String s,int i){
    	if(s.length() == 4){
    		plist.add(s);
    	}else{
    		permutation(i+s,i+1);
    		StringBuilder sb = new StringBuilder(s);
    		for(int j = 1 ; j <= s.length(); j++){
    			permutation(sb.substring(0,j)+i+sb.substring(j,s.length()),i+1);
    		}
    	}
    }
    
    public static int calculate(int a,int b,int c){
    	if(c == 0){
    		return a+b;
    	}else if(c == 1){
    		return a-b;
    	}else if(c == 2){
    		return a*b;
    	}
    	return 0;
    }
    
    public static String calname(int c){
    	if(c == 0){
    		return "+";
    	}else if(c == 1){
    		return "-";
    	}else if(c == 2){
    		return "*";
    	}
    	return "0";
    }
}

Measured memory_bytes: 20464
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> A(N);
	rep(i,N)cin>>A[i];
	int ans = 0;
	int nt = 10000;
	rep(i,N-1){
		if(A[i] == A[i+1]){
			++ans;
			A[i+1] = nt;
			--nt;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    int ans=0;
    for(int i=0;i<N;++i){
        cin >> S[i];
        for(int j=0;j<S[i].size()-1;++j){
            if(S[i][j] == 'A' && S[i][j+1] == 'B') ++ans;
        }
    }

    int ba=0, a=0, b=0;
    for(int i=0;i<N;++i){
        if(S[i].back() == 'A' && S[i][0] == 'B') ++ba;
        else if(S[i].back() == 'A') ++a;
        else if(S[i][0] == 'B') ++b;
    }
    ans += ba > 0 ? ba - 1 : 0;
    if(ba > 0 && a > 0){
        ans += 1;
        --a;
    }
    if(ba > 0 && b > 0){
        ans += 1;
        --b;
    }
    ans += min(a, b);
    cout << ans << endl;
}


Measured memory_bytes: 768
def fee(x,y,b,p)
  x*b+y*p
end
N=gets.to_i
N.times do
  x,y,b,p=gets.split.map &:to_i
  puts [fee(x,y,b,p),fee(x,y,[5,b].max,[2,p].max)*4/5].min
end

Measured memory_bytes: 6112
N, M = [int(i) for i in input().split()]
cards = [0] * (N + 1)

for _ in range(M):
  l, r = [int(i) for i in input().split()]
  cards[l - 1] += 1 
  cards[r] += -1

for i in range(N):
  cards[i + 1] += cards[i] 

print(len([i for i in cards if i == M]))


Measured memory_bytes: 7856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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; }

int N;
vector<pair<ll,ll>> v;

bool cmp(pair<ll,ll> a,pair<ll,ll> b){
    return a.second<b.second;
}

int main(void){
    cin>>N;
    v.resize(N);
    for(int i=0;i<N;i++) cin>>v[i].first>>v[i].second;
    sort(v.begin(),v.end(),cmp);
    
    bool ok=true;
    ll sum=0;
    for(int i=0;i<N;i++){
        sum+=v[i].first;
        if(sum>v[i].second) ok=false;
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3456
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	char a[3];
	int ans = 0;
	scanf("%c%c%c",&a[0],&a[1],&a[2]);
	for(int i = 0; i < 3; i++) {
		if(a[i] == 'o') ans++;
	}
	printf("%d\n", 700 + ans*100);
}


Measured memory_bytes: 128
import java.nio.CharBuffer;
import java.util.Scanner;

class Solver {

    private final String S;
    private final int K;

    Solver(Scanner in){
        S = in.next();
        K = in.nextInt();
    }

    void solve() {
        char[] chars = S.toCharArray();
        int remaining = K;
        for (int i = 0; i < chars.length; i++) {
            if ('z' - chars[i] + 1 <= Math.min(25, remaining)) {
                remaining -= 'z' - chars[i] + 1;
                chars[i] = 'a';
            }
        }
        chars[chars.length - 1] += remaining % 26;
        System.out.println(CharBuffer.wrap(chars));
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 26392
import itertools
S = input()[::-1]
mod = 10**9 + 7
A = [0] * 13
N = 0
for i, v in enumerate(S):
    p = pow(10, i, 13)
    if v == '?':
        A[p] += 1
    else:
        N += int(v) * p
        N %= 13
dp = [0] * 13
dp[N] = 1
for i, v in enumerate(A):
    for _ in range(v):
        dp_old = dp[:]
        for j, k in itertools.product(range(1, 10), range(13)):
            x = (j * i + k) % 13
            dp[x] += dp_old[k]
            dp[x] %= mod
print(dp[5])


Measured memory_bytes: 42092
L2, R2= map(int, input().split())

L=L2%2019
R=R2%2019

hasamu=R2-L2
kotae=10000
if hasamu>2017:
  kotae=0
if L>R:
  kotae=0
else:
  for i in range(L,R):
    for j in range(i+1,R+1):
      seki=i*j
      amari=seki%2019
      if amari<kotae:
        kotae=amari
print(kotae)
  


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

struct vert{
    vector<ll> needed = vector<ll>(26);
    vector<ll> have = vector<ll>(26);
    vi nchar = vi(26,-1);
    ll ans = 0;
    ll contain = 0;
};

vector<vert> trie(1);

int ptr = 1;

void updvert(int vnum){
    FOR(i,26){
        if(trie[vnum].nchar[i] == -1) continue;
        vert &child = trie[trie[vnum].nchar[i]];
        trie[vnum].contain += child.contain;
        trie[vnum].ans += child.ans;
        FOR(j,26){
            if(i == j) trie[vnum].have[j] += child.contain;
            else trie[vnum].have[j] += child.have[j];
        }
    }
    FOR(i,26){
        trie[vnum].ans += trie[vnum].needed[i]*(trie[vnum].have[i]-1LL);
    }
//    cerr << vnum << " " << trie[vnum].ans << "\n";
}

void addstring(string a){
    int n = a.length();
    int cpos = 0;
    for(int i = n; i >= 1; i--){
        int ne = a[i-1]-'a';
        if(i == 1){
            trie[cpos].contain++;
            trie[cpos].needed[ne]++;
            trie[cpos].have[ne]++;
            continue;
        }
        if(trie[cpos].nchar[ne] == -1){
            trie.emplace_back();
            trie[cpos].nchar[ne] = ptr++;
//            cerr << ptr-1 << ": " << ne << "\n";
        }
        cpos = trie[cpos].nchar[ne];
    }
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    FOR(i,n){
        string a; cin >> a;
        addstring(a);
    }
    for(int i = ptr-1; i >= 0; i--) updvert(i);
    cout << trie[0].ans << "\n";
    return 0;
}


Measured memory_bytes: 634760
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int N=s.nextInt(), D=s.nextInt(), c = 0;
		for(int i=0;i<N;i++) {
			long X=s.nextInt(), Y=s.nextInt();
			if(D>=Math.sqrt(X*X+Y*Y))c++;
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 59316
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
#include<stack>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
	int n;
	cin >> n;
	bool flag = false;
	rep(i, n) {
		char c;
		cin >> c;
		if (c == 'Y') flag = true;
	}
	if (flag) cout << "Four" << endl;
	else cout << "Three" << endl;
}

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

int main()
{
  int n, d;
  cin >> n >> d;
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    int a, b;
    cin >> a >> b;
    if (sqrt(pow(a, 2) + pow(b, 2)) <= d)
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3652