akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

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

    if(n < 1000)cout << "ABC";
    else cout << "ABD";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int ans = 0;
	string s;
	cin >> s;
	int si = s.length();
	int ranj = 0; int rano = 0; int rani = 0;
	char j = 'J';
	char i = 'I';
	char o = 'O';
	char ba = s[0];
	if (ba == j) {
		ranj++;
	}
	for (int in = 1; in < si; in++) {
		if (s[in] == j) {
			if (ba == j) {
				ranj++;
			}
			else {
				ranj = 1; rano = 0; rani = 0;
			}
		}
		if (s[in] == o) {
			if (ba != i) {
				rano++;
			}
			else {
				ranj = -1;
			}
		}
		if (s[in] == i) {
			if (ba != j) {
				rani++;
				if (ranj >= rano and rano == rani) {
					ans = max(ans, rano);
				}
			}
			else {
				ranj = -1;
			}
		}
		ba = s[in];
	}
	cout << ans << endl;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
int n, k;
int arr[100100], pos;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i ++)
        cin >> arr[i];
    pos = n;
    for(int i = 0; i < n; i ++)
        if(arr[i] >= 0)
        {
            pos = i;
            break;
        }
    int Ans = INT_MAX;
    if(n - pos >= k)
        Ans = min(Ans, arr[pos + k - 1]);
    if(pos >= k)
        Ans = min(Ans, -arr[pos - k]);
    for(int i = max(1, k - (n - pos)); i <= min(k - 1, pos); i ++)
        Ans = min(Ans, -arr[pos - i] + arr[pos + k - i - 1] + min(-arr[pos - i], arr[pos + k - i - 1]));
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
int n=Integer.parseInt(input.readLine());
if(n==0)break;
int sum=0;
for(int i=0;i<n/4;i++)
{
int x=Integer.parseInt(input.readLine());
sum+=x;
}
System.out.println(sum);
}
}
}

Measured memory_bytes: 16884
#include<iostream>
using namespace std;
int main(void){
  string s;
  cin>>s;
  int ans=700;
  if(s[0]=='o'){
    ans+=100;
  }
  if(s[1]=='o'){
    ans+=100;
  }
  if(s[2]=='o'){
    ans+=100;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
using System;
class aoj
{
    static void Main()
    {
        string[] k = new string[50];
        int l = 0;
        while (true)
        {
            string c;
            string a = Console.ReadLine();
            if (String.IsNullOrEmpty(a)) break;
            string[] b = a.Split(',');
            int[] d = new int[5];
            for (int i = 0; i < 5; i++)
            {
                d[i] = int.Parse(b[i]);
            }
            Array.Sort(d);
            if ((d[0] == d[1] && d[0] == d[2] && d[0] == d[3]) || (d[1] == d[2] && d[1] == d[3] && d[1] == d[4]))
            {
                c = "four card";
                goto stop;
            }
            if ((d[0] == d[1] && d[1] == d[2] && d[3] == d[4]) || (d[0] == d[1] && d[2] == d[3] && d[3] == d[4]))
            {
                c = "full house";
                goto stop;
            }
            bool g = true;
            for(int i = 1; i < 5; i++)
            {
               
                if (d[i] - d[i - 1] == 1)
                {
                }
                else
                {
                    g = false;
                }
            } 
            if (d[0] == 1 && d[1] == 10 && d[2] == 11 && d[3] == 12 && d[4] == 13)
            {
                g = true;
            }
            if (g)
            {
                    c = "straight";
                    goto stop;
            }
            for (int i = 0; i < 3; i++)
            {
                if (d[i] == d[i + 1] && d[i] == d[i + 2])
                {
                    c = "three card";
                    goto stop;
                }
            }
            for(int i = 0; i < 4; i++)
            {
                for(int j = i+1;  j < 4; j++)
                {
                    if (d[i] == d[i + 1] && d[j] == d[j + 1])
                    {
                        c = "two pair";
                        goto stop;
                    }
                }
            }
            for(int i = 0; i < 4; i++)
            {
                if (d[i] == d[i+1])
                {
                    c = "one pair";
                    goto stop;
                }
            }
            c = "null";
            stop:;
            k[l] = c;
            l++;
        }
        for(int i = 0; i < l; i++)
        {
            Console.WriteLine(k[i]);
        }
    }
}

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

int main()
{
	int a,b,i,flag;
	cin>>a>>b;
	flag = 2;
	while(b!=0){
		if(flag!=2)
			cout<<"\n";
		for(i=a;i<=b;i++){
			if(i%400==0){
				cout<<i<<"\n";
				flag=1;
			}
			else if(i%4==0 && i%100!=0){
				cout<<i<<"\n";
				flag = 1;
			}
		}
	     if(flag !=1)
			 cout<<"NA\n";
		cin>>a>>b;
		flag = 0;
	}

	return 0;
}

Measured memory_bytes: 0
n = int(input())
opinion = [{} for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        opinion[i][x-1] = y
ans = 0
for i in range(2**n):
    honest = [0]*n
    j = 0
    while i > 0:
        honest[j] = i&1
        j += 1
        i = i >> 1
    flag = 1
    for j in range(n):
        if honest[j]:
            for x,y in opinion[j].items():
                if honest[x] != y:
                    flag = 0
    if flag:
        ans = max(ans, honest.count(1))
print(ans)


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

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

    int ans = INT_MAX;

    for(int i = 0; i < N; i++){
        int cost, timev;

        cin >> cost >> timev;

        if(timev <= T)
        {
            ans = min(ans, cost);
        }
    }

    if(ans < INT_MAX)
    {
        cout << ans << endl;
    }else{   
        cout << "TLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int s,i,x[3];
  int ans=0;
      scanf("%d",&s);
  for(i=0;i<3;i++)
    {
      x[i]=s%10;
      if(x[i])
	{
	  ans++;
	}
      s=s/10;
    }
  printf("%d",ans);
  return 0;
}

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

stack<int> divisors(int a) {
  stack<int> head, tail;
  for (int i = 1; i * i <= a; i++) {
    if (a % i != 0) {
      continue;
    }
    head.push(i);
    if (i * i != a) {
      tail.push(a / i);
    }
  }
  while (!tail.empty()) {
    head.push(tail.top());
    tail.pop();
  }
  return head;
}

int meet(int myidx, vector<int> a, int n, stack<int> cands) {
  int cand;
  while (!cands.empty()) {
    cand = cands.top();
    cands.pop();
    bool reach = false;
    for (int i = 0; i < n; i++) {
      if (i == myidx) {
        continue;
      }
      if (a.at(i) % cand != 0) {
        if (reach) {
          goto nextloop;
        } else {
          reach = true;
        }
      }
    }
    break;
  nextloop:
    continue;
  }
  return cand;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  auto d0 = divisors(a.at(0));
  auto d1 = divisors(a.at(1));
  auto c0 = meet(0, a, n, d0);
  auto c1 = meet(1, a, n, d1);
  cout << max(c0, c1) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

long long int X, Y, Z;

int main() {
	cin >> X >> Y >> Z;
	if (X - (Y + Z)*(X / (Y + Z)) < Z) {
		cout << X / (Y + Z) - 1 << endl;
	}
	else {
		cout << X / (Y + Z) << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    
    string s;
    cin >> s;
    ll cnt[26] = {};
    rep(i,0,s.size()){
        cnt[s[i] - 'a']++;
    }

    rep(i,0,26){
        if(cnt[i] > ceil(s.size()/3.0)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n, a[100001];

signed main()
{

 	FLASH

	cin>>n;

	fr(i, 1, n + 1) cin>>a[i];

	sort(a + 1, a + n + 1);
	int t = (a[n] + 1)/2;

	int ans = 0, mn = mod;

	fr(i, 1, n){
		if(abs(t - a[i]) < mn){
			mn = abs(t - a[i]);
			ans = a[i];
		}
	}

	cout<<a[n]<<" "<<ans;

}

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

string a, b;

int main() {
    cin >> a >> b;
    
    int x = stoi(a + b);
    int root_x = (int)sqrt(x);
    if (root_x * root_x == x) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S string
	fmt.Scanf("%s", &S)
	s := strings.Split(S, "W")
	ans := 0
	t := 0
	for i := 0; i < len(s); i++ {
		v := len(s[i])
		ans += t
		if v != 0 {
			t += v
		}
	}
	fmt.Println(ans)

}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}


int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;

	int cnt[n + 1] = {};
	cnt[0] = 3;
	int res = 1;
	vector<int> a(n);
	for(auto &x : a){
		cin >> x;
		x++;
		mul(res, cnt[x - 1] - cnt[x]);
		cnt[x]++;
	}
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner *bufio.Scanner

func printIt() {
	sentence := nextString()
	var ans []byte
	for _, ch := range []byte(sentence) {
		if ch >= 'a' && ch <= 'z' {
			ans = append(ans, ch+'A'-'a')
		} else if ch >= 'A' && ch <= 'Z' {
			ans = append(ans, ch-'A'+'a')
		} else {
			ans = append(ans, ch)
		}
	}
	fmt.Println(string(ans))
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	printIt()
}



Measured memory_bytes: 1084
#include <iostream>
#include <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

const double EPS = 1e-7;
typedef complex<double> P; /* _ */
struct L {                 /* üª */
	P p, q;
	L(P p, P q) : p(p), q(q) {}
};

// OÏ
double cross(P a, P b) { return imag(conj(a)*b); }

// ¼üaÆ¼übÌð_ðvZ·éDæÉð·»èªK{D
P crossPointLL(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

// _pÆ_qÌ¼ñªüðÔ·
L pointBisector(P p, P q) {
	P cen = (p+q)*0.5;
	return L(cen, cen+(q-p)*P(0,1));
}

int main(){
	int n;
	cin>>n;
	double x1, y1, x2, y2, x3, y3;
	while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
		// Cuè@
		P p1 = P(x1, y1);
		P p2 = P(x2, y2);
		P p3 = P(x3, y3);
		L l1 = pointBisector(p1, p2);
		L l2 = pointBisector(p2, p3);
		P cen = crossPointLL(l1, l2);
		double r = abs(p1-cen);

		// ö®ðp¢½è@
		double a1 = 2*(x2-x1);
		double b1 = 2*(y2-y1);
		double c1 = x1*x1-x2*x2+y1*y1-y2*y2;
		double a2 = 2*(x3-x1);
		double b2 = 2*(y3-y1);
		double c2 = x1*x1-x3*x3+y1*y1-y3*y3;
		double cx = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		double cy = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		P cen2 = P(cx, cy);
		double r2 = abs(p1-cen2);

		printf("%.3f %.3f %.3f", cen.real(), cen.imag(), r);
		cout<<endl;

		// ÜÆß
		//int x1000 = cen2.real() >= 0 ? 1000*cen2.real()+0.5 : 1000*cen2.real()-0.5;
		//int y1000 = cen2.imag() >= 0 ? 1000*cen2.real()+0.5 : 1000*cen2.real()-0.5;
		//int r1000 = r2          >= 0 ? 1000*r2         +0.5 : 1000*r2         -0.5;
		//printf("%.3f %.3f %.3f", 1.0*x1000/1000, 1.0*y1000/1000, 1.0*r1000/1000);
		//cout<<endl;

	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
x,n = map(int,input().split())
p = list(map(int,input().split()))
q = []
for i in range(-101,102):
    q.append(i)
for i in range(n):
    q.remove(p[i-1])

def getNearestValue(list, num):

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


print(getNearestValue(q, x))

Measured memory_bytes: 27160
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
const int MAX=1000001;

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

    int count8=0;
    for(int i=1;2*i-1<=n;i++){
        int count=0;
        for(int j=1;2*j-1<=2*i-1;j++){
            if((2*i-1)%(2*j-1)==0) count++;
        }
        if(count==8) count8++;
    }

    cout<<count8<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  vector<ll>v(n,0);
  multiset<ll>s;
  multiset<ll>t;
  ll f=0;
  ll suma=0;
  ll sumb=0;
  for(ll i=0;i<n;i++){
    cin>>v[i];
    if(v[i]>0){
      s.insert(v[i]);
      suma+=v[i];
    }
    if(v[i]<0){
      t.insert(v[i]);
      sumb+=v[i];
    }
    if(v[i]==0)f=1;
  }
  ans=suma-sumb;
  if(((t.size()&1)==0)||f==1){
  }
  else{
    ll tmp=100000000000000000;
    if(s.size()!=0){
      tmp=min(tmp,*s.begin());
    }
    if(t.size()!=0){
      auto itr=t.end();
      itr--;
      tmp=min(tmp,-*itr);
    }
    ans-=2*tmp;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5760
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  l=pM(split(readline()))
  ans=0
  for i in l
    while i%2==0;ans+=1;i/=2;end
  end
  print(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


Measured memory_bytes: 168672
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)  for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i > (b); --i)
#define rep(i, n)	  for(int i = 0; i < (n); ++i)
#define all(c)		  begin(c), end(c)
#define rall(c)		  rbegin(c), rend(c)
#define SZ(a)		  ((ll) a.size())

typedef long long		   ll;
typedef unsigned long long ull;

int main() {
	ll N;
	scanf("%lld", &N);
	vector <ll> A(N);
	for(int i = 0; i <= N - 1; i++) {
		scanf("%lld", &A[i]);
	}
	ll sum = 1;
	rep(i, N) {
		if(A[i] % 2 == 0) sum *= 2;
	}
	cout << pow(3, N) - sum;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 1e5+10;
long long save[maxn];
int init(){
    int i = 0;
    long long now = 100;
    while(now <= 1e18+10){
        save[i] = now;
        now *= 1.01;
        i++;
    }
    return i;
}
int main(){
    int maxx = init();
    long long x;
    cin>>x;
    int i;
    for(i=0; i<maxx; i++){
        if(x<=save[i]){
            break;
        }
    }
    cout<<i<<endl;
    return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n), b(n);
	ll suma = 0, sumb = 0;
	REP(i, n) {
		cin >> a[i]; suma += a[i];
	}
	REP(i, n) {
		cin >> b[i];
		sumb += b[i];
	}
	ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
	REP(i, n) {
		if (a[i] < b[i]) {
			cnt1 += (b[i] - a[i]) / 2;
			cnt2 += (b[i] - a[i]) % 2;
		}
		else {
			cnt3 += a[i] - b[i];
		}
	}
	
	if (cnt1 < cnt3)cout << "No" << endl;
	else {
		cnt2 += 2*cnt1 - cnt3;
		if(cnt2==sumb-suma)	cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


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

int main() {
  int n;
  string s[10005];
  cin>>n;
  int le=0,bo=0,ri=0;
  int ans=0;
  for (int i=0; i<n; i++) {
    cin>>s[i];
    int si=s[i].size();
    if (s[i][0]=='B'&&s[i][si-1]=='A') bo++;
    else if (s[i][0]=='B') ri++;
    else if (s[i][si-1]=='A') le++;
    for (int j=0; j<si-1; j++) {
      if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
    }
  }

  if (bo) {ans+=bo-1;
    if (ri) {
      ans++;
      ri--;
    }
    if (le) {
      ans++;
      le--;
    }
  }
  ans+=min(le,ri);
  
  cout <<ans<< endl;
  return 0;
}



Measured memory_bytes: 768
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    auto count = [&](int n, int m, int r) {
        return (n + (m - r) % m) / m;
    };

    long long cnt0 = count(n, k, 0);
    long long res = 0;
    res = cnt0 * cnt0 * cnt0;
    if (k % 2 == 0) {
        int hk = k / 2;
        long long cnt = count(n, k, hk);
        res += cnt * cnt * cnt;
    }

    cout << res << '\n';

    return 0;
}

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

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

	int N;
	cin >> N;

	ll s = 0;
	for (int i = 1; i <= N; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			s += i;
		}
	}
	cout << s << endl;

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int h, w;
  cin >> h >> w;
  char board[50][50];
  bool check[50][50];
  int ans = h*w;
  for(int i = 0; i < 50; i++) fill(check[i], check[i]+50,false);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> board[i][j];
      if(board[i][j] == '#'){
        check[i][j] = true;
        ans--;
      }
    }
  }
  queue<P> que;
  que.push(P(0,0));
  int d[50][50];
  for(int i = 0; i < 50; i++) fill(d[i], d[i] + 50, -1);
  d[0][0] = 0;
  int dx[4] = {-1,0,1,0}, dy[4] = {0,1,0,-1};
  check[0][0] = true;
  //BFS
  while(!que.empty()){
    int y = que.front().first, x = que.front().second;
    que.pop();
    for(int i = 0; i < 4; i++){
      int nx = x + dx[i], ny = y + dy[i];
      if(!check[ny][nx] && nx >= 0 && ny >= 0 && nx < w && ny < h){
        que.push(P(ny, nx));
        d[ny][nx] = d[y][x]+1;
        check[ny][nx] = true;
      }
    }
  }
  if(d[h-1][w-1]==-1) ans = -1;
  else ans -= d[h-1][w-1] + 1;
  cout << ans <<endl;
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;

struct edge {int to,next;}e[maxn];
int n,tot,head[maxn],dp[maxn];
char C;

inline void read(int& x)
{
	x=0,C=getchar();
	while(C<'0'||C>'9')C=getchar();
	while(C>='0'&&C<='9')x=x*10+C-'0',C=getchar();
}
inline void add(int u,int v){e[++tot]=(edge){v,head[u]},head[u]=tot;}
inline void dfs(int u)
{
	bool lvs=1;
	vector<int> q;q.clear();
	for(int i=head[u];i;i=e[i].next)
	{
		lvs=0,dfs(e[i].to);
		q.push_back(dp[e[i].to]);
	}
	if(lvs)return;
	sort(q.begin(),q.end(),greater<int>());
	for(int i=0;i<q.size();i++)dp[u]=max(dp[u],q[i]+i+1);
}

int main()
{
	read(n);
	for(int i=2,b;i<=n;i++)read(b),add(b,i);
	dfs(1);
	printf("%d",dp[1]);
	return 0;
}

Measured memory_bytes: 7680
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}
int N;
vl A;
ll dp[401][401];
bool seen[401][401];
ll sum[401];

ll ans(int l,int r){
    if(seen[l][r]){
        return dp[l][r];
    }
    seen[l][r]=true;
    if(l==r){
        return dp[l][r]=0;
    }
    ll res=INF;
    FOR(m,l,r){
        chmin(res,ans(l,m)+ans(m+1,r));
    }
    return dp[l][r]=res+(sum[r+1]-sum[l]);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    A.resize(N);
    sum[0]=0;
    rep(i,N){
        cin >> A[i];
        sum[i+1]=sum[i]+A[i];
    }
    rep(i,401){
        rep(j,401){
            seen[i][j]=false;
        }
    }
    cout << ans(0,N-1) << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 5084
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  int A[200];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int count = 0;
  while (1) {
    for (int i = 0; i < N; i++) {
      if (A[i] % 2 != 0) {
        goto end;
      }
      A[i] /= 2;
    }
    count++;
  }
end:
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main()
{
  lint n;
  cin >> n;
  std::vector<lint> a(n);
  REP(i,n) cin >> a[i];

  lint now_x = 0;
  lint cost_sum = 0;
  std::vector<lint> cost_from_1(n);
  std::vector<lint> cost_from_n(n);
  REP(i,n){
    cost_sum += abs(a[i]-now_x);
    cost_from_1[i] = cost_sum;
    now_x = a[i];
  }
  cost_sum += abs(a[n-1]);
  cost_from_1[n-1] = cost_sum;

  now_x = 0;
  cost_sum = 0;
  IREP(i,n){
    cost_sum += abs(a[i]-now_x);
    cost_from_n[i] = cost_sum;
    now_x = a[i];
  }
  cost_sum += abs(a[0]);
  cost_from_n[0] = cost_sum;

  REP(i,n){
    lint result = 0;
    if(i != 0 && i != n-1){
      result += cost_from_1[i-1];
      result += cost_from_n[i+1];
      result += abs(a[i-1]-a[i+1]);
    }else if(i == 0){
      result += cost_from_n[1];
      result += abs(a[1]);
    }else if(i == n-1){
      result += cost_from_1[n-2];
      result += abs(a[n-2]);
    }
    cout << result << endl;
  }
  return 0;
}


Measured memory_bytes: 3584
from itertools import groupby

N, M = map(int, input().split())
mod = 10 ** 9 + 7


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


def make_table(n, mod=10 ** 9 + 7):
    N = n
    # 元テーブル
    g1 = [0] * (N + 1)
    g1[0] = 1
    g1[1] = 1

    # 逆元テーブル
    g2 = [0] * (N + 1)
    g2[0] = 1
    g2[1] = 1

    # 逆元テーブル計算用テーブル
    inverse = [0] * (N + 1)
    inverse[0] = 0
    inverse[1] = 1

    for i in range(2, N + 1):
        g1[i] = (g1[i - 1] * i) % mod
        inverse[i] = (-inverse[mod % i] * (mod // i)) % mod
        g2[i] = (g2[i - 1] * inverse[i]) % mod

    return g1, g2


def main():
    def cmb(n, r, mod):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return g1[n] * g2[r] * g2[n - r] % mod

    p = [len(list(j)) for i, j in groupby(prime_factorize(M))]
    g1, g2 = make_table(10 ** 6, mod)
    answer = 1
    for i in p:
        answer *= cmb(i + N - 1, N - 1, mod)
        answer %= mod

    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 121844
#include<cstdio>
int main()
{
    int n,k;
    char a[62];
    scanf("%d%d",&n,&k);
    scanf("%s",a);
    for(int i=0;i<n;i++)
    {
        if(i==k-1)
            printf("%c",a[i]+32);
        else
            printf("%c",a[i]);
    }
    return 0;
}


Measured memory_bytes: 128
N, Y = list(map(int, input().split()))
flag=0
try:
  for x in range(N+1):
    for y in range(N+1-x):
      z = N - x- y
      if x*10000 + y*5000 + z*1000 == Y:
        print(x, y, z)
        flag = 1
        raise Exception
except Exception:
  pass
if flag == 0:
  print('-1 -1 -1')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int NUM = 2e5 + 5;

int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        int n; cin>>n;
        vector<ll> a(n+1),b(n);
        for(auto &x:a) cin>>x;
        for(auto &x:b) cin>>x;
        ll kills = 0;
        for(int i=0;i<n;i++){
            ll cnt = min(a[i],b[i]);
            b[i]-=cnt;
            ll cnt2 = min(a[i+1],b[i]);
            a[i+1]-=cnt2;
            kills+=cnt+cnt2;
        }
        cout<<kills;
    }   
}


Measured memory_bytes: 1792
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;

ll INF = 1000000000000000;

int main(){
    ll N, M; cin >> N >> M;
    vll L(M), R(M), C(M);
    rep(i, 0, M){
        cin >> L[i] >> R[i] >> C[i];
    }
    vector<vector<P>> e(N, vector<P>(0));
    rep(i, 0, M){
        P v = mp(R[i]-1,C[i]);
        e[L[i]-1].emplace_back(v);
    }
    rrep(i, N-1, 0){
        P v = mp(i-1, 0);
        e[i].emplace_back(v);
    }
    //ダイクストラ法
    //vvl GにP(to,cost)って感じで隣接リストにしておく
    //計算量|E|log|V|
    //頂点数N
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<ll> d(N,INF);
    d[0]=0;
    pq.emplace(P(0,0));
    while(!pq.empty()){
        P x=pq.top();
        pq.pop();
        ll &y=x.first;
        ll &z=x.second;
        if(y>d[z])continue;
        for(auto p: e[z]){
            if(d[p.first]>d[z]+p.second){
                d[p.first]=d[z]+p.second;
                pq.emplace(P(d[p.first],p.first));
            }
        }
    }
    if(d[N-1]==INF){prt(-1);}
    else{prt(d[N-1]);}
}

Measured memory_bytes: 11640
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
string s;
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	ll ans = 0, cnt = 0;
	for(int i = sz(s) - 1; i >= 0; i--)
	{
		if(s[i] == 'C')
		{
			if(i != 0 && s[i - 1] == 'B')
			{
				++cnt;
				--i;
			}
			else
				cnt = 0;
		}
		else if(s[i] == 'B')
			cnt = 0;
		else
			ans += cnt;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	std::string s, t; std::cin >> s >> t;
	std::vector<std::vector<int>> memo(s.size() + 1, std::vector<int>(t.size() + 1, 0));
	for (auto i = 0; i < s.size(); ++i) {
		for (auto j = 0; j < t.size(); ++j) {
			if (s[i] == t[j]) {
				memo[i + 1][j + 1] = std::max({ memo[i + 1][j], memo[i][j + 1], memo[i][j] + 1 });
			}
			else {
				memo[i + 1][j + 1] = std::max(memo[i + 1][j], memo[i][j + 1]);
			}
		}
	}
	std::string result;
	int i = s.size(), j = t.size();
	while (i != 0 && j != 0) {
		if (s[i - 1] == t[j - 1]) {
			result.push_back(s[i - 1]);
			--i; --j;
		}
		else if (memo[i][j] == memo[i - 1][j]) {
			--i;
		}
		else {
			--j;
		}
	}
	std::reverse(result.begin(), result.end());
	std::cout << result << std::endl;
}

Measured memory_bytes: 35584
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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


int main() {

	int n;
	long long ans=0,p=0;
	cin >> n;
	map<string, int> s;
	string str;
	rep(i, n) {
		cin >> str;
		sort(str.begin(), str.end());
		s[str]++;
	}
	for (auto i : s) {
		if (i.second > 1) {
			p = 0;
			for (int j = 1; j < i.second; j++) {
				p += j;
			}
			ans+=p;
		}
	} 
	cout << ans;

}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#define N 105
#define M 15
using namespace std;

int n, m = 10, mx = -2e9, a[N][M], b[N][M], t[M];

void g() {
	int i, j, c, s = 0;
	for (i = 0; i < m; i++) if (t[i]) break;
	if (i == m) return;
	if (t[0] && t[1] && t[3] && t[7] && t[9]) {
		i = 0;
	}
	for (i = 0; i < n; i++) {
		c = 0;
		for (j = 0; j < m; j++) c += a[i][j] & t[j];
		s += b[i][c];
	}
	mx = max(mx, s);
}

void f(int p) {
	if (p == m) {g(); return;}
	t[p] = 0; f(p + 1);
	t[p] = 1; f(p + 1);
}

int main()
{
	int i, j;
	cin >> n;
	for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	for (i = 0; i < n; i++) for (j = 0; j <= m; j++) scanf("%d", &b[i][j]);
	f(0);
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int N; cin >> N;
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 15; j++) {
      if (i*4 + j*7 == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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


#define ll long long


//gcdやり直す

void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}




/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}






/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int h,w,k;
  scanf("%d%d%d",&h,&w,&k);
  char s[h+10][w+10];
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
  }

  int ans=0;
  for(int bit1=0;bit1<(1<<h);bit1++){
    for(int bit2=0;bit2<(1<<w);bit2++){

      int count=0;

      for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
          if(bit1 & (1<<i)){
            continue;
          }
          if(bit2 & (1<<j)){
            continue;
          }

          if(s[i][j]=='#'){
            count++;
          }
        }
      }
      if(count==k){
        ans++;
      }
    }
  }

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

Measured memory_bytes: 1728
# coding: utf-8

class Dice(object):
    def __init__(self, num_list):
        self.num = num_list

    def west(self):
        num = list(self.num)
        before = [5, 2, 0, 3]
        after = [2, 0, 3, 5]
        for i in range(4):
            self.num[after[i]] = num[before[i]]
        return self.num[5]

    def east(self):
        num = list(self.num)
        before = [5, 2, 0, 3]
        after = [3, 5, 2, 0]
        for i in range(4):
            self.num[after[i]] = num[before[i]]
        return self.num[5]

    def north(self):
        num = list(self.num)
        before = [0, 1, 5, 4]
        after = [4, 0, 1, 5]
        for i in range(4):
            self.num[after[i]] = num[before[i]]
        return self.num[5]

    def south(self):
        num = list(self.num)
        before = [0, 1, 5, 4]
        after = [1, 5, 4, 0]
        for i in range(4):
            self.num[after[i]] = num[before[i]]
        return self.num[5]

if __name__ == "__main__":
    num_list = [int(i) for i in raw_input().split()]
    dice = Dice(num_list)
    for order in raw_input():
        if order == "E": dice.east()
        elif order == "W": dice.west()
        elif order == "S": dice.south()
        elif order == "N": dice.north()
    print dice.num[0]

Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int prime[100100];


int main()
{

    int n,x;
    cin >> n >> x;
    vector<int>vec;
    int sum = 0,cnt = 0;
    int mn = INT_MAX;
    for(int i=1; i<=n; i++)
    {
        int b;cin >> b;
        sum+=b;cnt++;
        //vec.push_back(b);
         mn = min(mn,b);
    }

    int rest = x - sum;
    cnt += rest/mn;
    cout << cnt << endl;






}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;

namespace Printer{
    void print(vector<int> v){
        rep(i, v.size()){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    void print(vector<vector<int> > vv){
        rep(i, vv.size()){
            rep(j, vv[i].size()){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }
};

//--global--//



//----------//

ll solve(ll s, ll profit, ll cnt, ll G, ll D, ll p[], ll c[]){

    if(G <= profit){
        return cnt;
    }

    ll res = LLINF;

    ll tmps = s;
    for(ll i=0; i<D; i++){
        if(!(tmps & 1)){
            ll u = 1 << i;
            //cout << u << ",," << endl;
            if(G <= profit + (p[i]-1) * ((i + 1) * 100)){
                res = min(res, ll(cnt) + ll(G - profit + (((i + 1) * 100) - 1)) / ((i + 1) * 100));
                //cout << res << endl;
            }
        }
        tmps >>= 1;
    }



    tmps = s;
    for(ll i=0; i<D; i++){
        if(!(tmps & 1)){
            ll u = 1 << i;
            res = min(res, solve(s + u, profit + c[i] + ((i+1) * 100) * p[i], cnt + p[i], G, D, p, c));
        }
        tmps >>= 1;
    }

    return res;
}

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//

    ll D, G;
    cin >> D >> G;
    ll p[11], c[11];
    rep(i, D){
        cin >> p[i] >> c[i];
    }
    //cout << D << ", " << G << endl;

    cout << solve(0, 0, 0, G, D, p, c) << endl;


    return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

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

    int N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];

    set<int> st;
    REP(i, N) {
        if (st.count(a[i]) > 0) st.erase(a[i]);
        else st.insert(a[i]);
    }

    int ans = st.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>

int main(void) {
  int a, b, cnt = 0;
  scanf("%d %d", &a, &b);

  for (int i = a; i <= b; i++) {
    if (i / 10000%10 == i / 1%10 && i / 1000%10 == i / 10%10)
    cnt++;
  }

  printf("%d", cnt);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef long double ld;
typedef pair<int,int> P;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1e9+7;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***---
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

int ans=-1,a=-1,b=-1;

signed main(){
  int N,tmp;cin>>N;
  map<int,int> mp;
  
  REP(i,0,N){
    cin>>tmp;
    mp[tmp]++;
  }
  map<int,int>::const_iterator it=mp.end(),s=mp.begin();
  it--;
  for(;;--it){
    //debug((*it).first)
    if(a==-1){
      if((*it).second>=2){
        a=(*it).first;
        //debug(a)
      }
    }
    if(b==-1){
      if((a==(*it).first&&(*it).second>=4)||((a!=(*it).first)&&(*it).second>=2)){
        b=(*it).first;
      }
    }
    if(a!=-1&&b!=-1){
      ans=a*b;
      break;
    }
    if(it==s)break;
  }
  ans=(ans>0?ans:0);
  print(ans)

}


Measured memory_bytes: 6528
#include <stdio.h>

int main()
{
	int r;					//行数
	int c;					//列数
	int sheet[101][101];	//表
	int n;
	int sum;
	int i;
	int j;

	//
	for (i = 0; i < 101; i++)
		for (j = 0; j < 101; j++)
			sheet[i][j] = 0;

	//行数と列数を入力する
	scanf("%d%d", &r, &c);

	for (i = 0; i < r; i++)
	{
		for (j = 0; j < c; j++)
		{
			scanf("%d", &n);
			sheet[i][j] = n;
		}
	}

	//行ごとの合計を出す
	for (i = 0; i < r; i++)
	{
		sum = 0;
		for (j = 0; j < c; j++)
		{
			sum += sheet[i][j];
		}
		sheet[i][j] = sum;
	}

	//列ごとの合計を出す
	for (i = 0; i <= c; i++)
	{
		sum = 0;
		for (j = 0; j < r; j++)
		{
			sum += sheet[j][i];
		}
		sheet[j][i] = sum;
	}

	//結果を出力する
	for (i = 0; i <= r; i++)
	{
		for (j = 0; j <= c; j++)
		{
			printf("%d", sheet[i][j]);
			if (j < c)
				printf(" ");
		}
		printf("\n");
	}

    return 0;
}




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

int main(){ 
    lint N;
    cin >> N;
    vector<lint> A(N);
    rep( i, N ) cin >> A[i];

    vector<lint> ans(N);
    rep( i, N ) ans[0] = A[i] - ans[0];

    for( int i=1; i<N; ++i ) {
        ans[i] = 2 * A[i-1] - ans[i-1];
    }

    rep( i, N-1 ) cout << ans[i] << "\n";
    cout << ans[N-1] << "\n";
}


Measured memory_bytes: 2944
#include<iostream>
#include <stdio.h>
#include <math.h>
#include <map>
#include <queue>
#include <string.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll maxn = 99;
ll a,b;
int main()
{
    cin >> a >> b;
    cout << a*b;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define li long long int
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define inp(t) li t;cin>>t; while(t--)
using namespace std;

void solve()
{
  li n,k;
  cin>>n>>k;

  vector<li> v(n);
  rep(i,0,n)
  cin>>v[i];

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

  li sum = 0;
  rep(i,0,k)
  sum+=v[i];

  cout<<sum<<endl;
}
int main()
{
    IOS;

    solve();
    return 0;
}

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


int main() {
	// your code goes here
	long n,cnt=0;
	cin>>n;
	for(long i=1;i<=n;++i)
	{
	    string a=to_string(i);
	    if(a.size() & 1)cnt++;
	}
	cout<<cnt;
}


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

int compare_unsigned_int(const void *a, const void *b)
{
	return *(unsigned int*)b - *(unsigned int*)a;
}


int main() {

	int n;	
	int k;	

	scanf("%d %d", &n, &k);

	unsigned int h[n];
	int i;
	double attack_sum = 0.0;

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

	qsort(h, n, sizeof(unsigned int), compare_unsigned_int);
	for(i = k; i < n; i++) {
		attack_sum += h[i];
	}
	printf("%.0f\n", attack_sum);

	return 0;
}


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

bool sr(std::pair<int, int> a, std::pair<int, int> b) {
    return b.first > a.first;
}

int main () {
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int> > a(n);

    for (int i = 0; i < n; i++) {
        std::cin >> a[i].first;
        a[i].second = i + 1;
    }

    std::sort(a.begin(), a.end(), sr);

    for (int i = 0; i < n; i++) {
        std::cout << a[i].second << " ";
    }

    std::cout << "\n";
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
	int n;
	cin >> n;
	float a[110];
	fori(n) { cin >> a[i]; }
	float bunbo = 0;
	fori(n) { bunbo += (1 / a[i]); }
	cout << fixed << setprecision(6) << 1 / bunbo;
	return 0;
}

Measured memory_bytes: 256