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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOREACH(element, vec_name) for (auto &(element) : (vec_name))

#define VECCIN(vec_name) for (auto &element : (vec_name)) cin >> element

#define dump(x) cout << #x << " = " << (x) << endl;

using ll = long long;
using P =  pair<int,int>;

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }//最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }//最小公倍数

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 main()
{ 
    int n;
    cin >> n;
    int dp[200000];
    rep(i,200000) dp[i] = INF;

    dp[0] = 0;

    int pow = 1;
    rep(i,100000){
        pow = 1;
        while(pow<= n){
            chmin(dp[i+pow], dp[i] + 1);
            pow *= 6;
        }
    }
    
    rep(i,100000){
        pow = 1;
        while(pow<= n){
            chmin(dp[i+pow], dp[i] + 1);
            pow *= 9;
        }
    }
    

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1532
S = input()
idx = len(S)
ans = 'YES'
while idx > 0:
    if S[idx-5:idx] == 'dream':
        idx -= 5
    elif S[idx-5:idx] == 'erase':
        idx -= 5
    elif S[idx-7:idx] == 'dreamer':
        idx -= 7
    elif S[idx-6:idx] == 'eraser':
        idx -= 6
    else:
        ans = 'NO'
        break
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


map<string,int> MAP;

int main(){

	int num_query;
	scanf("%d",&num_query);

	int command,x;

	for(int loop = 0; loop < num_query; loop++){

		string tmp;
		scanf("%d",&command);

		if(command == 0){

			cin >> tmp >> x;
			MAP[tmp] = x;

		}else{

			cin >> tmp;

			if(command == 1){

				auto at = MAP.find(tmp);

				if(at == MAP.end()){

					printf("0\n");
				}else{

					printf("%d\n",MAP[tmp]);
				}
			}else{

				MAP.erase(tmp);
			}
		}
	}

	return 0;
}



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

int main() {
  int N,M;
  cin >>N>>M;
  if(N==1&&M==1){
    cout<<0<<endl;
    return 0;
  }else if(N==2&&M==2){
    cout<<2<<endl;
    return 0;
  }else{   
    cout<<N*(N-1)/2+M*(M-1)/2<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n;
V<int> v;

int main(){
    INIT;
    cin >> n;
    v.resize(n);
    REP(i,n) cin >> v[i];

    LL ans = 0;
    int i = 0, j = 1, k = 2;
    for(; k < n; i++,j++,k++) {
        if(v[i] < v[j] && v[j] < v[k]) ans++;
        if(v[i] > v[j] && v[j] > v[k]) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
 int a,b,c,d,x,y,ans;
 cin>>a>>b>>c>>d;
 if(d<=a||b<=c)ans=0;
 else{
   if(a<=c)x=c;
   else x=a;
   if(b<=d)y=b;
   else y=d;
   ans=y-x;
 }
 cout<<ans<<endl;
 return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
int W, H;
char G[62][22];
bool stable, V[62][22];
int dy[4] = {0, -1, 0, 1};
int dx[4] = {1, 0, -1, 0};

pair<double, int> dfs(int y, int x, char ch){
  double c = 0.0;
  queue<int> Q;
  V[y][x] = 1;
  int u, ny, nx, cnt = 0;
  int minx = x, maxx = x+1;
  for (Q.push(y*W+x); !Q.empty(); ){
    u = Q.front(); Q.pop();
    int b = u/W+1;
    if ( u/W == H-1 || (b < H && G[b][u%W] != '.' && G[b][u%W] != ch )){
      minx = min(minx, u%W);
      maxx = max(maxx, u%W+1);
    }
    c += u%W + 0.5;
    cnt++;
    rep(r, 4){
      ny = u/W + dy[r];
      nx = u%W + dx[r];
      if ( ny < 0 || nx < 0 || ny > H-1 || nx > W-1 || V[ny][nx]) continue;
      if ( G[ny][nx] == ch ){
	V[ny][nx] = 1;
	Q.push(ny*W+nx);
      } else if ( G[ny][nx] != '.' && r == 1 ) {
	pair<double, int> np = dfs(ny, nx, G[ny][nx]);
	c += np.first;
	cnt += np.second;
      }
    }
  }

  if ( ! ( minx < c/cnt && c/cnt < maxx ) ) stable = 0;

  return make_pair(c, cnt);
}

main(){
  while( cin >> W >> H && W ){
    rep(i, H) rep(j, W) { cin >> G[i][j]; V[i][j] = 0; }
    stable = 1;
    rep(j, W){ 
      if ( G[H-1][j] != '.' ){
	dfs(H-1, j, G[H-1][j]);
	break;
      }
    }
    cout << (stable?"STABLE":"UNSTABLE") << endl;
  }
}

Measured memory_bytes: 0
s = input()
d = {'S':0,'N':0,'E':0,'W':0}
for i in s:
    d[i] += 1
ns = (d['S'] > 0) == (d['N'] > 0)
ew = (d['E'] > 0) == (d['W'] > 0)
if ns and ew:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
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 <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    REP(i,4) s[i]-='0';
    if(s[0]-s[1]-s[2]-s[3]==7) {
        printf("%d-%d-%d-%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]-s[1]-s[2]+s[3]==7) {
        printf("%d-%d-%d+%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]-s[1]+s[2]-s[3]==7) {
        printf("%d-%d+%d-%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]-s[1]+s[2]+s[3]==7) {
        printf("%d-%d+%d+%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]+s[1]-s[2]-s[3]==7) {
        printf("%d+%d-%d-%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]+s[1]-s[2]+s[3]==7) {
        printf("%d+%d-%d+%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]+s[1]+s[2]-s[3]==7) {
        printf("%d+%d+%d-%d=7\n",s[0],s[1],s[2],s[3]);
    }
    else if(s[0]+s[1]+s[2]+s[3]==7) {
        printf("%d+%d+%d+%d=7\n",s[0],s[1],s[2],s[3]);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char str1[101], str2[101], str3[101];
int main() {
	memset(str1, NULL, sizeof(str1));
	memset(str2, NULL, sizeof(str2));
	memset(str3, NULL, sizeof(str3));
	cin >> str1;
	cin >> str2;
	cin >> str3;
	int len1 = strlen(str1);
	int len2 = strlen(str2);
	int len3 = strlen(str3);
	if (str1[len1 - 1] == str2[0] && str2[len2 - 1] == str3[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double INF=1e77;

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
struct segment{
	point<T> a,b;
};

template<class T>
T dot(const point<T> &a,const point<T> &b){ return a.x*b.x+a.y*b.y; }

template<class T>
T cross(const point<T> &a,const point<T> &b){ return a.x*b.y-a.y*b.x; }

enum {CCW=1,CW=-1,ON=0};
template<class T>
int ccw(const point<T> &a,const point<T> &b,const point<T> &c){
	T rdir=cross(b-a,c-a);
	if(rdir>0) return CCW;
	if(rdir<0) return CW;
	return ON;
}

template<class T>
bool intersect(const segment<T> &S1,const segment<T> &S2){
	if(max(S1.a.x,S1.b.x)<min(S2.a.x,S2.b.x)
	|| max(S1.a.y,S1.b.y)<min(S2.a.y,S2.b.y)
	|| max(S2.a.x,S2.b.x)<min(S1.a.x,S1.b.x)
	|| max(S2.a.y,S2.b.y)<min(S1.a.y,S1.b.y)) return false;
	return ccw(S1.a,S1.b,S2.a)*ccw(S1.a,S1.b,S2.b)<=0
		&& ccw(S2.a,S2.b,S1.a)*ccw(S2.a,S2.b,S1.b)<=0;
}

template<class T>
T dist2(const point<T> &a,const point<T> &b){
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

template<class T>
double dist2(const segment<T> &S,const point<T> &p){
	if(dot(S.b-S.a,p-S.a)<=0) return dist2(p,S.a);
	if(dot(S.a-S.b,p-S.b)<=0) return dist2(p,S.b);
	return (double)cross(S.b-S.a,p-S.a)*cross(S.b-S.a,p-S.a)/dist2(S.a,S.b);
}

template<class T>
double dist(const segment<T> &S1,const segment<T> &S2){
	if(intersect(S1,S2)) return 0;
	return sqrt(min(min(dist2(S1,S2.a),dist2(S1,S2.b)),
					min(dist2(S2,S1.a),dist2(S2,S1.b))));
}

int main(){
	for(int n;scanf("%d",&n),n;){
		point<int> s,t;
		scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);

		double r=INF;
		while(n--){
			int x1,y1,x2,y2,h; scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&h);
			point<int> a={x1,y1},b={x2,y1},c={x2,y2},d={x1,y2};

			if(x1<=min(s.x,t.x) && max(s.x,t.x)<=x2
			&& y1<=min(s.y,t.y) && max(s.y,t.y)<=y2) r=0; // ツ板?つェツ静シツ閉ェツづーツ閉「ツづ?づ?つ「ツづゥ

			// ツ板?づ個暗ェツ氾板凝淞つ「ツづ?つアツづォツつゥツづァツ静シツ閉ェツづ慊づ?づ個催?短ツ仰猟猟」
			double l=INF;
			l=min(l,dist((segment<int>){s,t},(segment<int>){a,b}));
			l=min(l,dist((segment<int>){s,t},(segment<int>){b,c}));
			l=min(l,dist((segment<int>){s,t},(segment<int>){c,d}));
			l=min(l,dist((segment<int>){s,t},(segment<int>){d,a}));

			if(l<h) r=min(r,l);
			else    r=min(r,(l*l+h*h)/(2*h));
		}

		printf("%.9f\n",r);
	}

	return 0;
}

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

using namespace std;
#define ld long double
ld dp[3000][3000];

int main()
{
    int n;
    cin >> n;
    ld arr[n+1],ans=0;
    for (int i=1; i<=n; i++)
        cin >> arr[i];

    dp[0][0]=1 , dp[1][1]=arr[1] , dp[1][0]=1-arr[1];

    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=n; j++)
        {
            if (j>i) dp[i][j]=0;
            else
            {
                if (!j) dp[i][j] =(1-arr[i])*dp[i-1][j];
                else
                {
                    if (i>1) dp[i][j] += (dp[i-1][j-1]*arr[i]);
                    dp[i][j] += (dp[i-1][j]*(1-arr[i]));
                }
            }
        }
    }

    for (int i=n/2+1; i<=n; i++)
        ans += dp[n][i];
    cout << fixed << setprecision(9) << ans << "\n";
  
    return 0;
}


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

int main() {
  string n;
  cin >> n;
  if(n.at(0) == n.at(1) && n.at(1) == n.at(2) || n.at(1) == n.at(2) && n.at(2) == n.at(3))
    cout << "Yes" << endl;
  else cout << "No" << endl;
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import sys
from collections import Counter
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter()
for a in a_ls:
    if a % 4 == 0:
        ct.update([2])
    elif a % 2 == 0:
        ct.update([1])
    else:
        ct.update([0])
if ct[1] == 0:
    if ct[2] >= ct[0] - 1:
        print("Yes")
    else:
        print("No")
else:
    if ct[2] >= ct[0]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14636
#include<stdio.h>
#define ll long long
int main(){
    ll  x;
    scanf("%lld",&x);
    ll ans=0;
    while(x>=500){
        ll p=x/500;
        x-=p*500;
        ans+=1000*p;
    }
    while(x>=5){
        x-=5;
        ans+=5;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std; 
int main() 
{ 
    int N, K;
    cin>>N>>K;
    int ara[N];
    for(int i=0; i<N; i++)
    {
        cin>>ara[i];
    }
    int n = sizeof(ara)/sizeof(ara[0]); 
    sort(ara, ara+n);
    int sum=0;
    for(int i=0; i<K; i++)
    {
       sum = sum + ara[i];
    }
    cout<<sum<<endl; 
    return 0; 
} 


Measured memory_bytes: 3628
#include <cstdio>
#include <iostream>
#include <vector>

int main() {
  std::vector<int> cbt;
  cbt.push_back(0);
  int h;
  std::cin >> h;
  for (int i = 0; i < h; ++i) {
    int k;
    std::cin >> k;
    cbt.push_back(k);
  }
  for (int i = 1; i < h+1; ++i) {
    printf("node %d: key = %d, ", i, cbt[i]);
    if (i != 1)
      printf("parent key = %d, ", cbt[i/2]);
    if (2*i < h+1)
      printf("left key = %d, ", cbt[2*i]);
    if (2*i < h)
      printf("right key = %d, ", cbt[2*i+1]);
    std::cout << std::endl;
  }
}

Measured memory_bytes: 3236
v,e=map(int,input().split())
s=sorted([list(map(int,input().split()))for i in range(e)],key=lambda x:x[2])
d=[i for i in range(v)]
def f(x):
    if x==d[x]:
        return x
    d[x]=f(d[x])
    return f(d[x])
a=0
for i,j,h in s:
    i,j=f(i),f(j)
    if i!=j:
        d[i]=j
        a+=h
print(a)


Measured memory_bytes: 28968
M, D = [int(i) for i in input().split()]
cnt = 0
for m in range(1, M + 1):
  for d in range(1, D + 1):
    d1 = d // 10
    d2 = d % 10
    if d1 < 2 or d2 < 2:
      continue
    if d1 * d2 == m:
      cnt += 1
print(cnt)

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
ll my_pow(ll x, ll y){
  ll rtn = 1;
  rep(i,y) rtn*=x;
  return rtn;
}

ll get_digits_num(ll n){
  ll ret=0;
  while(n){
    n/=10;
    ret++;
  }
  return ret;
}

ll gcd(ll m, ll n){
  if(m<n) swap(m,n);
  if(n==0) return m;
  return gcd(n, m%n);
}



ll get_digits_in(ll n,ll m, ll max_digits){
  rep(i,max_digits-m){
    n/=10;
  }
  return n%10;
}

int main() {
  cout<<fixed<<setprecision(10);

  ll n;cin>>n;
  vint a(n);rep(i,n)cin>>a[i];

  ll ans = 0;
  rep(i,n){
    ans += (a[i]-1);
  }

  cout << ans <<endl;

}

















//


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int A[100000+1];
long long mx[100000+1];
int main(){
  int i;
  long long res = 0;
  rd(N);N += (1);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  if(N==1 && A[0] != 1){
    wt_L(-1);
    wt_L('\n');
    return 0;
  }
  mx[0] = 1;
  for(i=(1);i<(N);i++){
    mx[i] = (mx[i-1] - A[i-1]) * 2;
    chmin(mx[i], 4611686016279904256LL);
    if(mx[i] < A[i]){
      wt_L(-1);
      wt_L('\n');
      return 0;
    }
  }
  mx[N-1] = A[N-1];
  for(i=(N-1)-1;i>=(0);i--){
    chmin(mx[i], mx[i+1] + A[i]);
  }
  {
    int xr20shxY;
    long long WYIGIcGE;
    if(N==0){
      WYIGIcGE = 0;
    }
    else{
      WYIGIcGE = mx[0];
      for(xr20shxY=(1);xr20shxY<(N);xr20shxY++){
        WYIGIcGE += mx[xr20shxY];
      }
    }
    wt_L(WYIGIcGE);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, A[1d5+1];
// ll mx[1d5+1];
// {
//   ll res = 0;
//   rd(N++,A(N));
//   if(N==1 && A[0] != 1) wt(-1), return 0;
// 
//   mx[0] = 1;
//   rep(i,1,N){
//     mx[i] = (mx[i-1] - A[i-1]) * 2;
//     mx[i] <?= ll_inf;
//     if(mx[i] < A[i]) wt(-1), return 0;
//   }
//   mx[N-1] = A[N-1];
//   rrep(i,N-1) mx[i] <?= mx[i+1] + A[i];
//   wt(sum(mx(N)));
// }


Measured memory_bytes: 5668
def main():
    N, M = list(map(int, input().split()))

    lst = [[0] for _ in range(N)]
    for i in range(M):
        p, S = input().split()
        p = int(p) -1

        if lst[p][-1] == 0:
            lst[p][-1] = S
        elif lst[p][-1] != 'AC':
            lst[p].append(S)

    clear_count = 0
    penalty_count = 0
    for l in lst:
        if l[-1] == 'AC':
            clear_count += 1
            for j in l:
                if j == 'WA':
                    penalty_count += 1

    print(clear_count, penalty_count)

if __name__ == "__main__":
    main()


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



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


    int n[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;

    cout << n[k-1] << endl;


    return 0;
}



Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a,b = LI()
    c,d = LI()
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    ans = float("inf")
    for w in range(1,1000):
        ans = min(ans, abs(a%w-b%w)+abs(a//w-b//w)+abs(c%w-d%w)+abs(c//w-d//w))
    print(ans)
    return

#B
def B():
    n = I()
    dp = [-1]*394
    dp[0] = 0
    for i in range(n):
        l,r,p = LI()
        for j in range(l,394):
            for k in range(l,r+1):
                if j-k >= 0:
                    if dp[j-k] >= 0:
                        if dp[j-k]+p > dp[j]:
                            dp[j] = dp[j-k]+p
    m = I()
    ans = [None for i in range(m)]
    for i in range(m):
        k = I()
        if dp[k] == -1:
            print(-1)
            quit()
        ans[i] = dp[k]
    for i in ans:
        print(i)
    return

#C
def C():
    def dfs(x):
        if f[x] != None:
            return f[x]
        res = 0
        for y,c in v[x]:
            res = max(res,dfs(y)+c)
        f[x] = res
        return f[x]
    n,m = LI()
    v = [[] for i in range(n)]
    f = defaultdict(lambda : None)
    f[0] = 0
    for i in range(m):
        a,b,c = LI()
        v[b].append((a,c))
    print(dfs(n-1))
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    C()



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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    for(int i=0;i<=n;++i){
        int x = 108*i/100;
        if(x == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
import math

def divisors(x):
    l = [[], []]
    for i in range(1, int(math.sqrt(x))+1):
        if x % i == 0:
            if i**2 != x:
                l[0].append(i)
                l[1].append(x//i)
            else:
                l[0].append(i)
    return l[0]+l[1][::-1]

def primenumber(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x % i == 0:
            return False
    return True

a, b = map(int, input().split())
cnt = 0
for i in divisors(math.gcd(a, b)):
    if i == 1:
        cnt += 1
    elif primenumber(i):
        cnt += 1
print(cnt)

Measured memory_bytes: 9256
import collections

n = int(input())
v = list(map(str, input().split()))
ans = 0

if len(set(v)) == 1:
    print(n//2)

else:
    v_odd = collections.Counter(v[0::2])
    v_even = collections.Counter(v[1::2])

    v_odd = list(sorted(v_odd.items(), key = lambda x:-x[1]))
    v_even = list(sorted(v_even.items(), key = lambda x:-x[1]))

    if v_odd[0][0] == v_even[0][0]:
        if v_odd[1][1] > v_even[1][1]:
            print(n - v_odd[1][1] - v_even[0][1])
        else:
            print(n - v_odd[0][1] - v_even[1][1])
 
    else:
        print(n - v_odd[0][1] - v_even[0][1])

Measured memory_bytes: 25564
#include <bits/stdc++.h>
        //#define endl '\n'
        #define modulo 1000000007
        #define int long long
        #pragma GCC optimize("-Ofast")
        #define float double
        #define PI 3.141592653589793238462643383279502884
        #define sinDegrees(x) sin((x) * PI / 180.0)
        #define tanDegrees(x) tan((x) * PI / 180.0)
        #define atanDegrees(x) atan(x)* 180.0 / PI
        #define f first
       // #define s second
        using namespace std;
        int power(int x,int y,int m)
        {
        int temp;
        if(y == 0)
        return 1;
        temp = (power(x, y/2,m))%m;
        if (y%2 == 0)
        return ((temp%m)*temp);
        else
        return ((x*temp%m)*temp%m)%m;
        }
        int inv(int x)
        {
        return (power(x,modulo-2,modulo))%modulo;
        }
        bool comp(int a,int b)
        {
            return a>b;
        }
        ///Solution created by:Ahmadsm2005
        int32_t main()
        {
            //freopen("output.txt","w", stdout);
            //freopen("input0.txt","r", stdin);
            iostream::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
            string s;
            cin>>s;
            vector<vector<int>>lolz(26);
            for(int i=0;i<s.size();i++){
            lolz[s[i]-'a'].push_back(i+1);
            }
            int miner=INT_MAX;
            for(int i=0;i<26;i++){
            if(lolz[i].size())
            for(int l=0;l<lolz[i].size()-1;l++){
            miner=min(miner,lolz[i][l+1]-lolz[i][l]);
            if(miner<3){
            cout<<lolz[i][l]<<' '<<lolz[i][l+1];
            exit(0);
            }
            }
            }
            cout<<-1<<' '<<-1;
            return 0;
        }


Measured memory_bytes: 1612
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int len = (int)s.length();
	int ans = 999;
	for (int i = 0; i <= len - 3; ++i) {
		int n = atoi(s.substr(i, 3).c_str());
		ans = min(ans, abs(753 - n));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
std::vector<int>a[maxn];
int h[maxn];
int n,m,k;
int check(int x,int y)
{
	if(x<1||x>n||y<1||y>m)return 1;
	int pos=std::lower_bound(a[y].begin(),a[y].end(),x)-a[y].begin();
	if(pos==a[y].size())return 0;
	else return (x==a[y][pos]);
}
int main()
{
	n=read(); m=read(); k=read();
	for(int i=1;i<=k;i++){
		int x=read(),y=read();
		a[y].push_back(x);
	}
	for(int i=1;i<=m;i++){
		std::sort(a[i].begin(),a[i].end());
		h[i]=n;
	}
	int x=1,y=1;
	for(int i=1;i<=m;i++){
		// printf("%d %d\n",x,y);
		h[y]=x;
		if(check(x+1,y))break;
		else ++x;
		// puts("A");
		while(x<=n&&check(x,y+1))++x;
		++y;
		if(check(x,y))break;
	}
	int ans=n;
	for(int i=1;i<=m;i++)
		for(int j=0;j<a[i].size();j++)
			if(a[i][j]>h[i])ans=std::min(ans,a[i][j]-1);
	writeln(ans);
	// for(int i=1;i<=m;i++)
	// 	writesp(h[i]);
	// putchar('\n');
	return 0;
}

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

using namespace std;
#define taskname "A"
#define pb	push_back
#define mp 	make_pair
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)

#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 6;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    int x , y;cin >> x >> y;
    if(x % y == 0)cout << -1;
    else cout << x;
}



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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

int main()
{
    solve();
}

void solve()
{
    int n;
    string s;
    in2(n, s);
    int flag[3][10];
    rep(i, 10) rep(j, 3) flag[j][i] = 0;
    int ans = 0;
    rep(i, n)
    {
        if (flag[0][s[i] - '0'] == 1)
        {
            continue;
        }
        flag[0][s[i] - '0'] = 1;
        repi(i, j, n)
        {
            if (flag[1][s[j] - '0'] == 1)
            {
                continue;
            }
            flag[1][s[j] - '0'] = 1;
            repi(j, k, n)
            {
                if (flag[2][s[k] - '0'] == 1)
                {
                    continue;
                }
                flag[2][s[k] - '0'] = 1;
                ans++;
            }
            rep(m, 10) flag[2][m] = 0;
        }
        rep(m, 10) flag[1][m] = 0;
    }
    out(ans);
}

Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int a[100001];
int mapdata[200001];
int N, Z, W, x,y;
vector<int> v;
int dp[2005][2];

enum turn {
	TURN_X,
	TURN_Y,
};

int minimax(int pos, turn turn) {

	if (dp[pos][turn] != -1)return dp[pos][turn];

	if (turn == TURN_X) {
		int val = -1;
		REP(i, 1, N) {
			int tmp;
			if (pos+i == N - 1) {
				//最後を取るパターン
				tmp = abs(a[pos] - a[pos+i]);
			}
			else {
				tmp = minimax(pos + i, TURN_Y);
			}
			//子ノードのスコアの最大値
			if (tmp > val) {
				val = tmp;
			}
			if (pos + i == N - 1) break;
		}
		return dp[pos][turn] = val;
	}

	if (turn == TURN_Y) {
		int val = LL_HALFMAX;
		REP(i, 1, N) {
			int tmp;
			if (pos+i == N - 1) {
				//最後を取るパターン
				tmp = abs(a[pos] - a[pos+i]);
			}
			else {
				tmp = minimax(pos + i, TURN_X);
			}
			//子ノードのスコアの最小値
			if (tmp < val) {
				val = tmp;
			}
			if (pos + i == N - 1) break;
		}
		return dp[pos][turn] = val;
	}
}


signed main() {
	rep(i, 2005)rep(j, 2)dp[i][j] = -1;

	cin >> N >> Z >> W;
	a[0] = Z;
	a[1] = W;
	rep(i, N) cin >> a[i+2];
	N += 2;
	cout << minimax(1, TURN_X) << "\n";

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>

using namespace std;
typedef long long ll;

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


    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j;
  
    ll K;
    vector<ll> a;

    ll Q,N;
    string S;
    cin>>S;
    ll flag=0;
    ll t1=0;
    ll t2=0;
    if(S[0]==S[1]&&S[0]==S[2]){
         cout<< "No" << endl;
            return 0;
    }
        if(S[0]==S[1]){
            if(S[2]==S[3]){
                
            cout<< "Yes" << endl;
            return 0;
            }
        }
    if(S[0]==S[2]){
            if(S[1]==S[3]){
            cout<< "Yes" << endl;
            return 0;
            }
        }if(S[0]==S[3]){
            if(S[2]==S[1]){
            cout<< "Yes" << endl;
            return 0;
            }
        }
       


        cout<< "No" << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main(){
  FastIO;
  ll n;
  cin>>n;
  cout<<(n*n*n);
  return 0;
} 


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

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

const ull mod = (ull)1e9 + 7;
ll n;
vector<vector<ll>> as;
ll ans = 1e15;

void swapLine(int i) {
	ll a1 = as[i][0];
	ll a2 = as[i+1][0];
	ll b1 = as[i][1];
	ll b2 = as[i+1][1];
	as[i][0] = b2;
	as[i+1][0] = b1;
	as[i][1] = a2;
	as[i+1][1] = a1;
}

void dfs(int index, ll c, ll sum) {
	if (index == n - 1) {
		if (as[index][0] >= c) {
			ans = min(ans, sum);
		}
		return;
	}
	for (int i = index; i < n; i++) {
		if (as[i][(i - index) % 2] >= c) {
			for (int j = i - 1; j >= index; j--) {
				swapLine(j);
			}
			int dist = i - index;
			if (dist + sum < ans) {
				dfs(index + 1, as[index][0], dist + sum);
			}
			for (int j = index; j < i; j++) {
				swapLine(j);
			}
		}
	}
}

int main(void)
{
	cin >> n;
	as.resize(n, vector<ll>(2));
	rep(i, n) {
		cin >> as[i][0];
	}
	rep(i, n) {
		cin >> as[i][1];
	}
	dfs(0, -1, 0);
	if (ans == 1e15) {
		cout << -1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// B Two Switches
// 096 C Grid repainting
#include <bits/stdc++.h>
using namespace std;

int main(){

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    bool is_a_on = false;
    bool is_b_on = false;
    int count = 0;
    for (int i = 0; i < 100; i ++)
    {
        if (i >= B or i < A)
            is_a_on = false;
        else 
            is_a_on = true;

        if (i >= D or i < C)
            is_b_on = false;
        else 
            is_b_on = true;

        if(is_a_on and is_b_on)            
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(D, G, PC):

    ans = sys.maxsize
    PC = list(reversed(PC))
    for i in product([0, 1], repeat=D):
        g = G
        p = 0
        for j, v in enumerate(i):
            if v == 0:
                continue
            p += PC[j][0]
            g -= PC[j][1] + PC[j][0] * (D-j) * 100
        if g > 0 and 0 in i:
            j = i.index(0)
            for _ in range(PC[j][0]-1):
                p += 1
                g -= (D-j)*100
                if g <= 0:
                    break
        if g <= 0:
            ans = min(ans, p)

    return ans


def main():
    D, G = read_int_n()
    PC = [read_int_n() for _ in range(D)]
    print(slv(D, G, PC))


if __name__ == '__main__':
    main()


Measured memory_bytes: 64492
#include <bits/stdc++.h>
using namespace std;
string S;
int64_t K;

int main()
{
  cin >> S >> K;
  vector<string> st(0);
  for (int i = 0; i < S.size(); i++)
  {
    string s = S.substr(i, S.size() - i);
    st.push_back(s);
  }
  sort(st.begin(), st.end());
  set<string> used;
  for (int i = 0; i < st.size(); i++)
  {
    for (int j = 0; j < st.at(i).size(); j++)
    {
      string subs = st.at(i).substr(0, j + 1);
      used.insert(subs);
      if (used.size() == K)
      {
        cout << st.at(i).substr(0, j + 1) << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 16128
a = list(input())
b = list(input())
c = list(input())
next = "a"

for i in range(len(a + b + c)):
    if next == "a":
        if len(a) == 0:
            print("A")
            break
        next = a[0]
        a = a[1:]
    elif next == "b":
        if len(b) == 0:
            print("B")
            break
        next = b[0]
        b = b[1:]
    else:
        if len(c) == 0:
            print("C")
            break
        next = c[0]
        c = c[1:]


Measured memory_bytes: 38352
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b, c, x;
    cin >> a >> b >> c >> x;

    int res = 0;
    rep(i, a + 1) {
        rep(j, b + 1) {
            rep(k, c + 1) {
                if (i * 500 + j * 100 + k * 50 == x) res++;
            }
        }
    }

    cout << res << endl;
    return 0;
}

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

int main(void){
  int a, b;
  char op = '0';

  while(op != '?'){
    cin >> a >> op >> b;

    if( op == '+'){
      cout << a + b << endl;
    }else if( op == '-'){
      cout << a - b << endl;
    }else if( op == '*'){
      cout << a * b << endl;
    }else if( op == '/'){
      cout << a / b << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
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 repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}

ll lcm(ll x, ll y){
  return x / gcd(x, y) * y;
}

ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vl t(n);
  rep(i,n) cin >> t[i];
  ll ans = nlcm(t);
  cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int a, b;
    cin >> a >> b;
    int q;
    cin >> q;
    vector<ll> s(a), t(b);
    rep(i, a) {
        cin >> s[i];
    }
    rep(i, b) {
        cin >> t[i];
    }
    vector<ll> x(q);
    rep(i, q) {
        cin >> x[i];
    }

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    rep(i, q) {
        auto str = upper_bound(s.begin(), s.end(), x[i]);
        auto ttr = upper_bound(t.begin(), t.end(), x[i]);
        ll sp = *str - x[i];
        ll sm = x[i] - *(str-1);
        ll tp = *ttr - x[i];
        ll tm = x[i] - *(ttr-1);
        if(str == s.begin()) {
            sm = INT64_MAX/10;
        }
        if(ttr == t.begin()) {
            tm = INT64_MAX/10;
        }
        if(str == s.end()) {
            sp = INT64_MAX/10;
        }
        if(ttr == t.end()) {
            tp = INT64_MAX/10;
        }

        ll mi = min({sp + abs(sp-tp), sp + sp + tm, sm + abs(sm-tm), 2*sm + tp, tp + abs(tp-sp), 2*tp + sm, tm + abs(tm-sm), 2*tm + sp});
        cout << mi << '\n';
    }
}

Measured memory_bytes: 3712
#!/usr/bin/env ruby
require 'set'

def main
    a,b,c,k = gets.chomp.split(" ").map(&:to_i)
    case
    when k<a
        puts k
    when k<(a+b)
        puts a
    else
        puts a-(k-a-b)
    end
end

main

# s[0,6] # 0番目から6文字
# s[0..6] # 0番目から6番目まで
# s[5..-1] # 5番目から最後まで
# until s.empty? do

Measured memory_bytes: 14400
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    if (N % 2 == 0) {
      System.out.println(N);
    } else {
      System.out.println(N * 2);
    }

  }
}

Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int table[55];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string a,b,c;cin>>a>>b>>c;
    cout << (char)(a[0]-32) << (char)(b[0]-32) << (char)(c[0]-32) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll K;
  scanf("%lld",&K);
  cout << (K/2)*((K+1)/2) << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  ll n = s.size();
  map<char, ll> mp;
  rep(i, n) mp[s[i]]++;
  ll ans = n*(n-1)/2+1;
  for (auto e : mp)
    ans -= e.second*(e.second-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 720
#include<stdio.h>

int main(){
	int N;
	scanf("%d",&N);
	int A[N];
	int i;
	for(i=0;i<N;i++)
	{
		scanf("%d",&A[i]);	
	}
	
	int count=0;
	
	 for(int i=0;i<N-1;i++)
        for(int j=0;j<N-i-1;j++)
        if(A[j]>A[j+1])
    {
        int t;
        t=A[j];
        A[j]=A[j+1];
        A[j+1]=t;
        count++;
    }
	
	for(int k=0;k<N;k++)
        {
            //cout<<A[k];
            printf("%d",A[k]);
            if(k!=N-1)
                printf(" ");
        }
    printf("\n");
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2096
#include <stdio.h>

int main(){
	int n,i,j,tmp,kuri;
	int num[5];

	for(i = 0;i < 5;i++){
		num[i] = 0;
	}

	scanf("%d",&n);

	num[0] = 1;
	kuri = 0;

	for(i = 1;i <= n;i++){
		for(j = 0;j < 5;j++){
			num[j] *= i;
			num[j] += kuri;
			kuri = 0;
			if(num[j] >= 10000){
				kuri = num[j]/10000;
				num[j] %= 10000;
			}
		}
	}

	tmp = 4;
	while(num[tmp] == 0){
		tmp--;
	}

	printf("%d",num[tmp]);

	for(i = tmp-1;i >= 0;i--){
		printf("%04d",num[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 608
#include <cstdio>
#include <cstring>

char s[100010];
int len;

void solve()
{
	int i;
	int cur=1;
	len = strlen(s);
	if(s[len-1] == '1' || s[0] == '0'){
		printf("-1\n");
		return ;
	}
	for(i=0; i<(len-1)/2; i++){
		if(s[i] != s[len-2-i]){
			printf("-1\n");
			return ;
		}
	}
	int p=1;
	for(i=0; i<len-1; i++){
		if(s[i] == '0'){
			cur ++;
			printf("%d %d\n", p, cur);
		}
		else{
			cur ++;
			printf("%d %d\n", p, cur);
			p = cur;
		}
	}
}

int main()
{
	scanf("%s", s);
	solve();
	return 0;
}

Measured memory_bytes: 1408