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

int n,m,z,a[15][1005],cut[15],now[15],tmp[15],ans=0x3f3f3f3f;

int main()
{
    scanf("%d%d%d",&n,&m,&z);
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
            scanf("%1d",&a[i][j]);
    for(int i=0;i<(1<<(n-1));i++)
    {
        int cnt=0,ct=0,ok=1;
        memset(cut,0,sizeof(cut));
        memset(now,0,sizeof(now));
        for(int j=0;j<n-1;j++)
            if(i&(1<<j))
                cnt++,cut[j]=1;
        ct=cnt;
        for(int j=0;j<m;j++)
        {
            int flag=0;
            memset(tmp,0,sizeof(tmp));
            for(int k=0,cur=0;k<n;k++)
                tmp[cur]+=a[k][j],cur+=cut[k];
            for(int k=0;k<=ct;k++)
            {
                if(tmp[k]>z) ok=0;
                if(tmp[k]+now[k]>z) flag=1;
            }
            if(!ok) break;
            if(!flag)
                for(int k=0;k<=ct;k++) now[k]+=tmp[k];
            else
            {
                cnt++;
                for(int k=0;k<=ct;k++) now[k]=tmp[k];
            }
        }
        if(ok) ans=min(cnt,ans);
    }
    printf("%d",ans);
    return 0;
}

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

long int divide_sum(long int N){
    int digits;
    long int Ncp=N;
    for(int i=0; i<10;i++) {
        if(Ncp/10==0) {
            digits=i;
            break;
        } else {
            Ncp /= 10;
        }
    }

   long int sum=0;
   if(N/10==0) return N;
   sum += N;
    long int divide_digit=10;
    long int patarn=1;
    for(int i=0;i<digits;i++) {
        sum += (N/divide_digit)*patarn + divide_sum(N%divide_digit);
        divide_digit*=10;
        patarn*=2;

    }

    return sum;
}

int main() {
  long int N;
  cin >> N;

  long int sum=0;

  sum = divide_sum(N);
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int X, N;
    cin >> X >> N;
    map<int, bool> mp;
    rep(i, N)
    {
        int p;
        cin >> p;
        mp[p] = true;
    }

    auto it = mp.find(X);
    if(it==mp.end())
    {
        cout << X << endl;
        return 0;
    }
    else
    {
        rep(sa, 100)
        {
            if(mp.find(X-sa)==mp.end())
            {
                cout << X-sa << endl;
                return 0;
            }
            if(mp.find(X+sa)==mp.end())
            {
                cout << X+sa << endl;
                return 0;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int h[105];

int main(void){
    int n,c=0,ans=0;cin>>n;
    for(int i=0;i<n;i++)cin>>h[i];
    for(int i=1;i<n;i++){
        if(c==0&&h[i-1]>0){ans+=h[i-1];c=1;}
        if(c>0&&h[i-1]<h[i])ans+=h[i]-h[i-1];
    }
    if(c==0&&h[n-1]>0)ans=h[n-1];
    cout<<ans<<endl;
    
    return 0;
}


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

using namespace std;


char *p;
using pi = pair<int, int>;
using pn = pair<int, pi>;

#define L second.first
#define R second.second

string as, bs;
vector<pn> A, B;

int make(vector<pn>& G){
    ++p;
    int l,r;
    if(*p == '('){
        l = make(G);
    } else{
        l = -1;
    }
    ++p; ++p;
    int v = 0;
    for(; *p != ']';){
        v = v*10+ *p - '0';
        ++p;
    }
    ++p; ++p;
    if(*p == '('){
        r = make(G);
    } else{
        r = -1;
    }
    G.push_back(pn(v, pi(l,r)));
    ++p;
    return G.size()-1;
}

string solve(int a, int b){
    string r = "(";
    if(A[a].L >= 0 && B[b].L >= 0){
        r += solve(A[a].L, B[b].L);
    }
    r += ")["s + to_string(A[a].first + B[b].first) + "](";
    if(A[a].R >= 0 && B[b].R >= 0){
        r += solve(A[a].R, B[b].R);
    }
    r += ")";
    return r;
}

main(){
    cin >> as >> bs;
    p = &as[0]; make(A);
    p = &bs[0]; make(B);
    auto ret = solve(A.size()-1, B.size()-1);
    cout << ret << endl;
}


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

int main() {
  string a, b;
  int n = 0;
  cin >> a >> b;
  for(int i = 0; i < 3; i++){
    if(a.at(i) == b.at(i))
      n++;
  }
  cout << n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 int arr[200020];

int main() {
    int n,a;
    cin>>n;
    for(int i=1; i<n; i++) {
        cin>>a;
        arr[a]++;
    }

    for(int i=1; i<n; i++) {
        cout<<arr[i]<<endl;
    }
    cout<<"0"<<endl;


    return 0;
}








Measured memory_bytes: 4412
#include<iostream>
using namespace std;
int main(){
int x,y;
for(int i=1;i<=10000;i++){
cin >> x >> y;
if(x==0&&y==0)break;
if(x>=y){cout << y << " " << x << endl;}
if(x<y){cout << x << " " << y << endl;}
}


return 0;
}


Measured memory_bytes: 3076
import fractions
def lcm(a, b):
    y = a*b // fractions.gcd(a, b)
    return (y)
N=int(input())
T = [int(input()) for i in range(N)]
if N==1:
    t=T[0]
else:
    t=lcm(T[0],T[1])
    if N>2:
        for i in range(1,N):
            t=lcm(t,T[i])
print(t)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
int64 F[22][22];
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int64 n;
  cin >> n;
  int64 res = 0;
  for (int i = 0; i < n; ++i) {
    string t;cin>>t;
    int64 a=0,b=0,q=0,p=0;
    for(int j=0;j<SZ(t);++j)if(t[j]=='.'){
      q=1;
    }else if(q==0){
      a=a*10+t[j]-'0';
    }else{
      b=b*10+t[j]-'0';++p;
    }
    while(p!=9)b*=10,++p;
    a=a*1e9+b;
    int x = 0, y = 0;
    while (a % 2 == 0) a /= 2, x++;
    while (a % 5 == 0) a /= 5, y++;
    x = min(x, 18);
    y = min(y, 18);
    for (int j = 0; j < 19; ++j)
      if (j + x >= 18) {
        if (y == 18)
          res += F[j][18];
        else
          res += F[j][18] - F[j][18 - y - 1];
      }
    for (int j = y; j < 19; ++j) F[x][j]++;
  }
  cout << res << '\n';

  return 0;
}
//2020.08.09 20:06:25


Measured memory_bytes: 3616
#include<stdio.h>

int main(){
	int A[4][3][10]={{{0}}},i,j,k,n,b,f,r,v;
	scanf("%d",&n);
	
	while(n){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		A[b-1][f-1][r-1] += v;
		n--;
	}
	
	for(i = 0; i < 4; i++){
		if(i != 0)printf("####################\n");
		for(j = 0; j < 3; j++){
			for(k = 0; k < 10; k++){
				if(k == 9){
					printf(" %d\n",A[i][j][k]);
					break;
				}
				printf(" %d",A[i][j][k]);
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 2056
#include<iostream>

using namespace std;

#define INF 1000000007
int n,w;
int v[100][2];
int dp[10001];

int dfs(int k){
  for(int i = 10001; i >= 0; i--){
    if(i + v[k][0] <= 10001){
      if(dp[i] != INF){
        dp[i+v[k][0]] = min(dp[i+v[k][0]], dp[i] + v[k][1]);
      }
    }
  }
  if(k < n-1) return dfs(k+1);
  else return 0;
}

int main(){
  cin >> n >> w;
  for(int i = 0; i < n ;i++){
    cin >> v[i][0] >> v[i][1];
  }
  for(int i = 0; i < 10001 ; i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  dfs(0);
  int m = 0;
  for(int i = 0; i < 10001; i++){
    if(dp[i] <= w) m = i;
  }
  cout << m << endl;
}



Measured memory_bytes: 3136
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void 
debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  int Q;cin>>Q;
  while(Q--){
    lint A,B;cin>>A>>B;
    if(A>B) swap(A,B);
    auto getsq=[&](lint x){
      lint y=sqrt((double)x);
      for(int t=3;;--t){
        lint z=y+t;
        if(z*z<x) return z;
      }
    };
    lint md=getsq(A*B);
    lint res;
    if(A==B) res=A+B-2;
    else if(A+1==B) res=A+B-3;
    else{
      res=md*2-2;
      if(md*(md+1)<A*B) ++res;
    }
    cout<<res<<endl;
  }
  return 0;
}





Measured memory_bytes: 256
n, m = map(int, input().split())

L, R = [], []
for _ in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

max_l = max(L)
min_r = min(R)

if max_l <= min_r:
    print(min_r - max_l + 1)
else:
    print(0)


Measured memory_bytes: 10996
#include <cstdio> //{{{
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>

#define ALL(c) (c).begin(), (c).end()
#define DUMP(x) std::cerr << #x << ':' << (x) << '\n';

typedef long long ll;

inline int in(){int x;scanf("%d",&x);return x;}
template<typename T, typename U>inline bool chmax(T&x,U a){if(x>=a)return 0;x=a;return 1;}
template<typename T, typename U>inline bool chmin(T&x,U a){if(x<=a)return 0;x=a;return 1;}
//}}}

using namespace std;

#include <sstream>

string to_s(int x) {
  stringstream ss;
  ss << x;
  return ss.str();
}

int main()
{
  int N = in();
  string S = "";
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S += s;
  }
  for (int i = 0; i < 1000; i++){
    auto s = to_s(i);
    if (S.find(s) == std::string::npos) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }
  else if(abs(a-b)<=d&&abs(b-c)<=d){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  int ans = 0;
  rep(i,n-2) if((p[i]<p[i+1]&&p[i+1]<p[i+2]) || (p[i]>p[i+1]&&p[i+1]>p[i+2])) ++ans;
  cout << ans << endl;
}


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

bool search(int a[],int n,int key){
	int i=0;
	a[n]=key;
	while(a[i]!=key) i++;
	return i!=n;
}



int main(){
	int n,q,S[10000+1],key,cnt=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	scanf("%d",&q);
	
	for(int i=0;i<q;i++){
		scanf("%d",&key);
		if(search(S,n,key))cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 3244
from itertools import product as pro

h,w,K=map(int,input().split())
C=[]
for _ in range(h):
    C.append(list(str(input())))



L=['0','1']
Sh=pro(L,repeat=h)


ans=0
for i in Sh:
    Sw=pro(L,repeat=w)
    for j in Sw:
        temp=0

        for k in range(h):
            for l in range(w):
                if i[k]=='0' and j[l]=='0':
                    if C[k][l]=='#':
                        temp+=1
        
        if temp==K:
            ans+=1
           

print(ans)


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

using namespace std;

int main(){
    string str,ans="CODEFESTIVAL2016";
    int flag=0;
    cin >> str;
    for(int i=0;i<ans.size();i++){
        if(str[i]!=ans[i]){
            flag++;
        }
    }
    cout << flag <<endl;
}


Measured memory_bytes: 256
while True:
    N = int(input())
    b = input().split()
    a = [int(i) for i in b]
    if (N >= 1 and N <= 100):
        for i in a:
            if (i < 1 or i > 100):
                continue
    else:
        continue
    break
a.sort(reverse=True)

s = [0,0]
for i in range(len(a)):
    s[i%2] = a[i] + s[i%2]
print(s[0] - s[1])

Measured memory_bytes: 3064
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i,j;
    int n;
    int* x;
    double avg = 0;
    int sum = 0;

    scanf("%d", &n);

    x = (int*)malloc(sizeof(int) * n);

    for(i=0;i<n;i++){
        scanf("%d", x + i);
        avg += *(x+i);
    }
    avg = round(avg / n);

    for(i=0;i<n;i++){
        sum += pow(*(x+i)-avg, 2);
    }

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

Measured memory_bytes: 384
t=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if a[0]>b[0]:
    a,b=b,a
p=t[0]*(a[0]-b[0])
q=t[1]*(a[1]-b[1])
if p+q==0:
    print('infinity')
elif p+q<0:
    print(0)
else:
    k=-p//(p+q)
    if -p%(p+q)==0:
        print(2*k)
    else:
        print(2*k+1)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

int flag=0;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<s.size();j++){
      if(s[(i+j)%s.size()]!=t[j]) break;
      if(j==s.size()-1) flag=1;
    }
    if(flag){
      cout<<"Yes"<<endl;
      return 0;
    }
  }

  cout<<"No"<<endl;
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m,ll mod);
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)1e6+11;
ll a,b,c,d;
map<ll,ll> mp;
ll cost(ll n){
        if (n == 0) return 0;
    if (n == 1) return d;
    if (mp.count(n)) return mp[n];
    ll l2 = (n/2)*2;
    ll r2 = ((n+1)/2)*2;
    ll l3 = (n/3)*3;
    ll r3 = ((n+2)/3)*3;
    ll l5 = (n/5)*5;
    ll r5 = ((n+4)/5)*5;
 
    ll res = 1e18;
    if (n< res/d) res = n*d;
    res = min(res, llabs(l2-n)*d + a + cost(l2/2));
    res = min(res, llabs(r2-n)*d + a + cost(r2/2));
 
    res = min(res, llabs(l3-n)*d + b + cost(l3/3));
    res = min(res, llabs(r3-n)*d + b + cost(r3/3));
 
    res = min(res, llabs(l5-n)*d + c + cost(l5/5));
    res = min(res, llabs(r5-n)*d + c + cost(r5/5));
 
    mp[n] = res;
 
    return res;
}
void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
                mp.clear();
        mp[0]=0;
        cin>>n;
        cin>>a>>b>>c>>d;
        ll ans=cost(n);
        if(d*n>0)
        ans=min(ans,d*n);
        cout<<ans<<endl;
        
                
        
}
int main(){
        FS;
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod=MOD){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	int n;
	cin >> n;
	int ans = 7 % n;
	for (int i = 1; i <= n; i++)
	{
		if (ans == 0)
		{
			cout << i;
			return 0;
		}
		ans = (ans * 10 + 7) % n;
	}
	cout << -1;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <map>

int main() {
  std::map<std::string, int> m;
  m["SUN"] = 7;
  m["MON"] = 6;
  m["TUE"] = 5;
  m["WED"] = 4;
  m["THU"] = 3;
  m["FRI"] = 2;
  m["SAT"] = 1;
  
  std::string input;
  std::cin >> input;
  std::cout << m[input] << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  std::bitset<1000100> isprime;

  isprime.flip();

  isprime[0]=false;
  isprime[1]=false;

  for(ll i=2;i<1000100;i++){
    if(isprime[i]){
      for(ll j=2*i;j<1000100;j+=i){
        isprime[j]=false;
      }
    }
  }

  ll a,d,n;
  while(std::cin>>a>>d>>n,a){
    ll cnt=0;
    for(ll i=a;;i+=d){
      if(isprime[i]){
        cnt++;
        if(cnt==n){
          std::cout<<i<<"\n";
          break;
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3272
n = int(input())
for i in range(1, n+1, 1):
    x = i;
    if x % 3 == 0:
        print('', i, end='')
        continue
    while x:
        if x % 10 == 3:
            print('', i, end='')
            break
        x //= 10
print()

Measured memory_bytes: 8180
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

int main(){

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

    if(a+W < b){
        if(b-a-W > 0){
            cout << b-a-W << endl;
        }else{
            cout << 0 << endl;
        }
    }else if(b < a){
        if(a-b-W > 0){
            cout << a-b-W << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        cout << 0 << endl;
    }


}

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

int main(){
    int ans=0;
    int n;
    int64_t r1,ri,rinext;
    cin >> n;
    int64_t data[n];
    int64_t r[n];

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

    r1=2*data[0];
    for (int i = 1; i < n/2 + 1; i++){
        r1 += 2*(data[i*2]-data[i*2-1]);
    }
    r[0] = r1/2;

    for (int i = 1; i < n; i++){
        r[i] =2*data[i-1]-r[i-1];
    }
    
    for (int i = 0; i < n; i++)std::cout << r[i]<<" ";
    //cout <<fixed<<setprecision(16)<< << endl;
    cout << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;
const int mod = 1e9+7;
int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int lcs(string a, string b) {
  int n = a.size(), m = b.size();
  int dp[2][m+1];
  for(int i = 0;i <= n;i++) {
    for(int j = 0;j <= m;j++) {
      if(i==0||j==0) dp[i%2][j] = 0;
      else {
        if(a[i-1] == b[j-1]) dp[i%2][j] = 1 + dp[1-i%2][j-1];
        else dp[i%2][j] = max(dp[i%2][j-1], dp[1-i%2][j]);
      }
    }
  }
  return dp[n%2][m];
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

ll fact(int n) {
  ll ans = 1;
  fr(i,2,n+1) ans = (ans*i)%mod;
  return ans;
}

int main() {
  string s;
  cin>>s;
  int apos = -1, zpos = -1;
  frn(i,s.size()) {
    if(s[i]=='A'){
      apos = i;
      break;
    }
  }
  for(int i = s.size()-1;i >= 0;i--) {
    if(s[i]=='Z') {
      zpos = i;
      break;
    }
  }
  cout<<zpos - apos + 1;
}



Measured memory_bytes: 640
/**
 * Grading.cpp
 * Create:20180425
 * Description:ある文字列の中から、
 * 連続した特定の文字列を発見できるか判定するプログラム。
 */
#include <iostream>

bool bruteforce(const std::string &s,const std::string &p);

int main(int argc, char* argv[]){
  std::string s;  // 検索される文章
  std::string p;  // 検索する文節

  std::cin >> s >> p;

  s += s.substr(0, p.size());

  if (bruteforce(s, p)){
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}

/**
 * 全探索型の検索関数
 * @param  s 検索対象
 * @param  p 検索内容
 * @return   検索結果
 */
bool bruteforce(const std::string &s,const std::string &p){
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < p.size(); j++){
      if (i + j >= s.size())
        break;
      if (s[i + j] == p[j]){
        // std::cout << "s:" << s[i + j] << " p:" << p[j] << std::endl;
      } else {
        break;
      }
      if (j == p.size() - 1){
        return true;
      }
    }
  }
  return false;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int a,b;
  cin >> a >> b;
  int cnt=a;
  int n=1;
  
  if(b==1){
    cout << 0 << endl;
    return(0);
  }
  
  while(cnt < b){
    cnt += a-1;
    n++;
  }
  cout << n << endl;
  
  return(0);
}

Measured memory_bytes: 3612
n, m = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(m)]

cnt = 0

from collections import deque

for i in a:
    b = a[:]
    start = i[0]
    goal = i[1]
    b.remove(i)
    q = deque()
    q.append(start)

    searched = {start}
    while q:
        current = q.popleft()
        if current == goal:
            break
        for j in b:
            if current == j[0] and j[1] not in searched:
                q.append(j[1])
                searched.add(j[1])
            elif current == j[1] and j[0] not in searched:
                q.append(j[0])
                searched.add(j[0])
    else:
        cnt += 1


print(cnt)





Measured memory_bytes: 3316
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

// デフォルト変数定義
int n,m,a,b,c,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(x);
  YES(x==3||x==5||x==7);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int cost[n];
	int height[n];
    for(int i=0;i<n;i++)
      cin>>height[i];
   if(n>=1)
     cost[0]=0;
   //if(n>=2)
   //  cost[1]=abs(height[0]-height[1]);
  for(int i=1;i<n;i++){
  	int count=1;
  	cost[i]=INT_MAX;
  	while(count<=k&&i-count>=0){
		cost[i]=min(cost[i],cost[i-count]+abs(height[i-count]-height[i]));		
		count++;
  	}
  }
  cout<<cost[n-1];	
      
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int NN = 1e7;
const int M = 1e9+7;
int main(){
    int x,y;cin>>x>>y;
    ll N = (x+y)/3;
    ll K = (2*x-y)/3;
    vector<ll> fact(NN),ifact(NN),inv(NN);
   
    fact[0] = ifact[0] = inv[1] = fact[1] = ifact[1] = 1;
	for(int i = 2; i < NN; i++){
		fact[i] = fact[i-1]*i%M;
		inv[i] = (M-M/i*inv[M%i]%M)%M;
		ifact[i] = inv[i]*ifact[i-1]%M;
	}

    if((x+y)%3!=0) {
        cout<<0;
        return 0;
    }
  
    x-=N;
    y-=N;
    if(x<0 || y<0){
        cout<<0;
        return 0;
    }
    cout<<fact[x+y]%M*ifact[x]%M*ifact[y]%M;

}


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

int main() {
  long long n,c=1,d=1,e=1;
  cin >> n;
  if(n ==2){
    cout << 2;
    return 0;
  }
  else if(n == 1){
    cout << 0;
    return 0;
  }
  for(int i = 1; i <= n ; i++){
    c = c * 10;
    c = c % 1000000007;
    d = d * 9;
    d = d % 1000000007;
    e = e * 8;
    e = e % 1000000007;
  }
  c = c - 2 *d + e;
  if(c < 0) c = c + 1000000007;
  if(c < 0) c = c + 1000000007;
  if(c < 0) c = c + 1000000007;
  cout << c;
  
}


Measured memory_bytes: 3568
import numpy as np
from functools import partial
D = int(input())
C = list(map(int, input().split()))
B = np.array([0] * 26)
S = [list(map(int, input().split())) for _ in range(D)]

def calc_satisfaction(d, t):
    _B = np.array(B)
    _B[t-1] = d
    satiety = sum(C * (d - _B))
    return S[d-1][t-1] - satiety

satisfaction = 0
for d in range(1, D+1):
    f = partial(calc_satisfaction, d)
    t, satisfaction_d = max([(t, f(t)) for t in range(1, 27)], key=lambda x: x[1])
    B[t-1] = d
    satisfaction += satisfaction_d
    print(t)

Measured memory_bytes: 27532
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let a = get!();
    let b = get!();
    
    let mut ans = 0;
    let mut holes = 1;
    while holes < b {
        ans += 1;
        holes += a - 1;
    }
    
    println!("{}", ans);
}

Measured memory_bytes: 4352
str = gets.to_s

q = gets.to_i

q.times do
  operation = gets.to_s.split
  a = operation[1].to_i
  b = operation[2].to_i

  case operation[0]
  when 'replace'
    _p = operation[3]
    str[a..b] = _p
  when 'reverse'
    str[a..b] = str[a..b].reverse
  when 'print'
    puts str[a..b]
  end
end



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

int main(){
	double a,b,c;	cin>>a>>b>>c;
	if((a+b+c)/max(max(a,b),max(b,c))==2.0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::min;

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

    let answer = solve(&buf);

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

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

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut min_capacity: usize = iterator.next().unwrap().parse().unwrap();
    min_capacity = min(min_capacity, iterator.next().unwrap().parse().unwrap());
    min_capacity = min(min_capacity, iterator.next().unwrap().parse().unwrap());
    min_capacity = min(min_capacity, iterator.next().unwrap().parse().unwrap());
    min_capacity = min(min_capacity, iterator.next().unwrap().parse().unwrap());

    if min_capacity >= n {
        return "5".to_string()
    }

    if n % min_capacity == 0 {
        return format!("{}", 5 + (n / min_capacity - 1));
    }

    return format!("{}", 5 + (n / min_capacity));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
int n,k;
cin>>n>>k;
ll h[n];
REP(i,n){
    cin>>h[i];
}
sort(h,h+n);
ll sum=0;
REP(i,n-k){
    sum+=h[i];
}
cout<<sum<<endl;
}


  

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

int compare_char(const void *a, const void *b){
    return strcmp(( char * )a , ( char * )b );
}

int main(void){
    char s[100],t[100];
    int slen,tlen,i,j;
    scanf("%s",s);
    scanf("%s",t);
    slen = strlen(s);
    tlen = strlen(t);
    qsort(s,slen,sizeof(char),compare_char);
    qsort(t,tlen,sizeof(char),compare_char);
    for(i=0,j=tlen-1;i<slen&&j>=0;i++,j--){
        if(s[i]!=t[j]){
             if(s[i]<t[j]){
                printf("Yes\n");
                return 0;
            }else{
                printf("No\n");
                return 0;
            }
        }
    }
    if(slen<tlen){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

int main (void){

  int N;
  std::cin >> N;

  std::string S;
  std::cin >> S;

  std::vector<int> siro(N+2);
  siro[0] = 0;
  if (S[0] == '#') siro[1] = 1;
  else siro[1] = 0;
  for(int i=1; i<N+1; i++){
    if ( i == N ) siro[N+1] = siro[N];
    if ( S[i] == '#' ) siro[i+1] = siro[i]+1;
    else siro[i+1] = siro[i];
  }

  std::vector<int> kuro(N+2);
  kuro[N+1] = 0;
  if (S[N-1] == '.') kuro[N] = 1;
  else kuro[N] = 0;
  for(int i=N-2; i>=0; i--){
    if ( S[i] == '.' ) kuro[i+1] = kuro[i+2]+1;
    else kuro[i+1] = kuro[i+2];
  }
  kuro[0] = kuro[1];

  int min_ = 999999999;
  for(int i=0; i<N+1; i++){
    min_ = std::min(min_, siro[i]+kuro[i+1]);
  }

  std::cout << min_ << std::endl;
  return 0;
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
const int mod=1e9+7;
const int N=1e5+5;


int main()
    {
        Nitroboost;
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif

        int n;
        cin>>n;
        ll a[n];
        ll total=0;
        ll ans=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            ans=(ans+a[i]*total*1ll%mod)%mod;
            total=(total+a[i])%mod;
        }

        
       
        cout<<ans;

    }


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

int main() {
    int n;
    while (true) {
        cin >> n;
        if (n == 0) return 0;
        int res;
        double diff = 1000000;
        for (int i = 0; i < n; i++) {
            int p;
            double h, w;
            cin >> p >> h >> w;
            double bmi = w / (h / 100.0) / (h / 100.0);
            if (fabs(22.0 - bmi) < diff) {
                diff = fabs(22.0 - bmi); 
                res = p;
            }
        }
        cout << res << endl;
    }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    Vl H(N);
    for (ll i = 0; i < N; i++) {
        cin >> H[i];
    }
    ll ans = 0;
    while (true) {
        ll cnt = 0;
        for (ll i = 0; i < N - 1; i++) {
            if (H[i] > 0 && H[i + 1] == 0) ++cnt;
            if (H[i] > 0) --H[i];
        }
        if (H[N - 1] > 0) {
            ++cnt;
            --H[N - 1];
        }

        if (cnt == 0) break;

        ans += cnt;
    }

    cout << ans << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int g = gcd(a, b);
    if(c%g == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = [int(n) for n in input().split()]

count = 0
arr.sort()
arr.reverse()
temp = arr.copy()
count +=arr[0]
arr.remove(max(arr))
x=n
n=n-2

if(n%2==0):
    for i in range(int(n/2)):
        count+=(2*arr[i])
    print(count)
else:
    for i in range(int((n-1)/2)):
        count+=(2*arr[i])
    count+=(temp[int(x/2)])
    print(count)

Measured memory_bytes: 31592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define maxn 100010
using namespace std;
typedef long long ll;
ll n,m,a,b;
ll quick_pow(ll x,ll p)
{
    ll an=1;
    ll po=x;
    while(p)
    {
        if(p%2)  an=(an*po)%mod;
        po=(po*po)%mod;
        p/=2;
    }
    return an;
}
ll fac[maxn*2],inv[maxn*2];
ll f[maxn];
int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    fac[0]=1;
    for(ll i=1;i<=2*max(n,m);i++)  fac[i]=(fac[i-1]*i)%mod;
    for(ll i=0;i<=2*max(n,m);i++)  inv[i]=quick_pow(fac[i],mod-2);
    for(int i=1;i<=n-a;i++)  f[i]=fac[i+b-2]*inv[i-1]%mod*inv[b-1]%mod;
    for(int i=1;i<=n-a;i++)  f[i]=f[i]*fac[n-i+m-b-1]%mod*inv[m-b-1]%mod*inv[n-i]%mod;
    ll ans=0;
    for(int i=1;i<=n-a;i++)  ans=(ans+f[i])%mod;
    printf("%lld\n",ans);
    return 0;
}

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

using namespace std;

#define int long long

const long double eps = 1e-5;

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

    int a, b, c;
    cin >> a >> b >> c;
    if (c - a - b >= 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	s := readString()
	s = strings.Replace(s, ",", " ", -1)
	println(s)
}


Measured memory_bytes: 640
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    val k = readLong()

    val runLengthS = runLengthEncode(s)
    if (runLengthS.size == 1) {
        println(s.length * k / 2)
        return
    }

    var ansForS = 0
    for (run in runLengthS) {
        ansForS +=  run.length / 2
    }

    val runLengthSS = runLengthEncode(s + s)
    var ansForSS = 0
    for (run in runLengthSS) {
        ansForSS += run.length / 2
    }

    val diff = ansForSS - ansForS
    println(ansForS + diff * (k - 1))
}

data class RunLength<T>(val value: T, val length: Int)

/** O(s.length) */
fun runLengthEncode(s: String): List<RunLength<Char>> {
    if (s.isEmpty()) return emptyList()

    val runLengthList = mutableListOf<RunLength<Char>>()
    var currentChar = s.first()
    var length = 1
    for (c in s.substring(1)) {
        if (c == currentChar) {
            length++
        } else {
            runLengthList += RunLength(currentChar, length)
            currentChar = c
            length = 1
        }
    }
    runLengthList += RunLength(currentChar, length)

    return runLengthList
}

//fun runLengthEncode(s: CharSequence): List<RunLength<Char>> = s.fold(mutableListOf<RunLength<Char>>()) { acc, value ->
//    if (acc.isNotEmpty() && acc.last().value == value) {
//        acc.last().length++
//    } else {
//        acc += RunLength(value, 1)
//    }
//    acc
//}

//fun runLengthEncode(s: CharSequence) = s.fold(listOf<RunLength<Char>>()) { acc, value ->
//    if (acc.isEmpty()) {
//        acc + RunLength(value, 1)
//    } else {
//        val last = acc.last()
//        if (last.value == value) {
//            acc.dropLast(1) + last.copy(length = last.length + 1)
//        } else {
//            acc + RunLength(value, 1)
//        }
//    }
//}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 33820
def main15():
    data = input().split()
    num = []
    for i in range(2):
        num.append(int(data[i]))
    data2 = input().split()
    num2 = []
    for i in range(num[0]):
        num2.append(int(data2[i]))
    length = 0
    result = 1
    for i in range(num[0]):
        length = length + num2[i]
        if length > num[1]:
            break
        else:
            result = result + 1
    print(result)

if __name__ == "__main__":
    main15()

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CEnergyDrinkCollector solver = new CEnergyDrinkCollector();
        solver.solve(1, in, out);
        out.close();
    }

    static class CEnergyDrinkCollector {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            List<Pair> stores = new ArrayList<>();

            for (int i = 0; i < N; i++) {
                stores.add(new Pair(in.nextLong(), in.nextLong()));
            }
            stores.sort((x, y) -> x.first - y.first == 0 ?0:(x.first - y.first>0?1:-1) );

            long ans = 0;
            long remain = M;
            out:
            for (int i = 0; i < N; i++) {
                Pair store = stores.get(i);
                for (long j = store.second; j > 0; j--) {
                    ans += store.first;
                    remain--;
                    if (remain <= 0) break out;
                }
            }
            out.println(ans);
        }

        class Pair {
            public long first;
            public long second;

            public Pair(long first, long second) {
                this.first = first;
                this.second = second;
            }

        }

    }
}


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

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

	int c[s.size()];
	for (int i = 0; i < s.size(); i++) {
		c[i] = (int)(s.at(i) - '0');
	}

	int u = c[0] * 10 + c[1];
	int d = c[2] * 10 + c[3];

	bool u_mm_flag = false;
	bool d_mm_flag = false;

	if (1 <= u && u <= 12) u_mm_flag = true;
	if (1 <= d && d <= 12) d_mm_flag = true;

	string ans;

	if (u_mm_flag && d_mm_flag) { 
		ans = "AMBIGUOUS";
	}
	else if (!u_mm_flag && d_mm_flag) {
		ans = "YYMM";
	}
	else if (u_mm_flag && !d_mm_flag) {

		ans = "MMYY";
	}
	else {

		ans = "NA";
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int t;
vector<int> n;

void init(){
  t=0;
  n.resize(0);
}

bool input(){
  cin>>t;
  if(t==false)return false;
  int t_n;
  cin>>t_n;
  for(int i=0;i<t_n;i++){
    int a,b;
    cin>>a>>b;
    n.push_back(b-a);
  }
  return true;
}

int solve(){
  int res=t;
  for(int i=0;i<n.size();i++){
    res-=n[i];
  }
  res=max(res,0);
  return res;
}

int main(){
  while(init(),input()){
    int ans=solve();
    if(ans==0){
      cout<<"OK"<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
}

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

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

  int N, M; cin >> N >> M;
  bool flag = false;
  vector<int> v(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c; cin >> s >> c; s--;
    if (v[s] < 0) v[s] = c;
    else if (v[s] != c) flag = true;
  }
  if (flag) {
    cout << "-1\n";
    return 0;
  }
  if (N == 1) {
    cout << (v[0] < 0 ? 0 : v[0]) << "\n";
    return 0;
  }
  if (v[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  cout << (v[0] < 0 ? 1 : v[0]);
  for (int i = 1; i < N; i++) cout << (v[i] < 0 ? 0 : v[i]);
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int a[101];
	int n;

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

	for(int i=n-1;i>=0;i--)
	{
		if(i == 0)
		{
			cout << a[i] << endl;
		}
		else
		{
			cout << a[i] << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
	


int main(){
	
	long long N;
	cin>>N;
	
	if(N%2==1){
		cout<<0<<endl;
		return 0;
	}
	
	long long ans = 0;
	long long k = 10;
	
	for(int i=0;true;i++){
		ans += N/k;
		k*=5;
		if(k>1000000000000000000)break;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

using namespace std;

int main(){
   int N;
   cin >> N;
   vector<int> L(2*N);
   for(int i=0;i<2*N;i++)cin >> L[i];
   sort(L.begin(),L.end());
   int ans=0;
   for(int i=0;i<N;i++){
      ans += L[2*i];
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256