akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

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

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



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

    int N, W;
    cin >> N >> W;
    vector<pair<int, int>> wv(N);
    cin >> wv;

    vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
    REP(i, N) {
        REP(w, W + 1) {
            chmax(dp[i + 1][w], dp[i][w]);
            if (w + wv[i].first > W)continue;
            chmax(dp[i + 1][w + wv[i].first], dp[i][w] + wv[i].second);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
# coding: utf-8
# Your code here!
import math
def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False

if __name__ == '__main__':
    Q = int(input())
    
    input_list = sieve_of_erastosthenes(100010)
    
    li = []
    
    cnt=0
    li.append(cnt)
    for i in range(1, 100010):
        if int(i)%2 == 1:
            if input_list[int(i)] == True and input_list[int((i+1)/2)] == True:
                cnt = cnt+1
                
        li.append(cnt)
    
    
    for i in range(Q):
        l,r = map(int, input().split())
        print(li[r]-li[l-1])
    




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

class TETORIS {
public:
	int N;
	vector<vector<int> > bd;
	TETORIS() : N(0) {}
	void put(int len, int pos) {
		int k = bd.size()-1;
		for (; k>=0; --k) {
			for (int i=0; i<len; ++i) {
				if (bd[k][pos+i]) goto brk;
			}
		} brk:;
		++k;
		if (bd.size() == k) bd.push_back(vector<int>(5, 0));
		for (int i=0; i<len; ++i) {
			bd[k][pos+i] = 1;
		}
		N += len;
	}
	void update() {
		for (int i=bd.size()-1; i>=0; --i) {
			if ( ! count(bd[i].begin(), bd[i].end(), 0)) {
				bd.erase(bd.begin()+i);
				N -= 5;
			}
		}
	}
};

int main() {
	int n, d, p, q;
	while (cin >> n, n) {
		TETORIS tet;
		for (int i=0; i<n; ++i) {
			cin >> d >> p >> q;
			if (d == 1) {
				tet.put(p, q-1);
				tet.update();
			} else {
				for (int j=0; j<p; ++j) tet.put(1, q-1);
				tet.update();
			}
		}
		cout << tet.N << endl;
	}
	return 0;
}

Measured memory_bytes: 1572
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int n;
  cin >> n;
  int64_t res = 0;
  map<int64_t, int> mp;
  rep(i,n) {
    int64_t k;
    cin >> k;
    res += k;
    mp[k]++;
  }
  
  int q;
  cin >> q;
  //cout << res << endl;
  rep(i,q) {
    int64_t b, c;
    cin >> b >> c;
    /*for (auto p : mp) {
      cout << i+1 << " ";
      cout << p.fi << ":" << p.se << endl;
    }*/
    res = res - b*mp[b] + c*mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    cout << res << endl;
  }
  return 0;
}



Measured memory_bytes: 9532
#include <iostream>

using namespace std;

int main()
{
    string x;
    cin >> x;
    int ans = x.size();
    int cur = 0;
    for (int i = 0; i < x.size(); i++)
    {
        if (x[i] == 'S')
        {
            cur++;
        }
        else
        {
            if (cur > 0)
            {
                cur--;
                ans -= 2;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 832
N = int(input())
x = list(map(int,input().split()))

p = sum(x)/N

q = int(p)

ans1 = 0
ans2 = 0
for i in range(N):
	ans1 += (x[i]-q)*(x[i]-q)
	ans2 += (x[i]-q-1)*(x[i]-q-1)
print(min(ans1,ans2))



Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 100000
char s[MAXN+5];
int a[30];
int main() {
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(len<2) {
		puts("-1 -1");
		return 0;
	}
	for(int i=2;i<=len;i++) {
		if(s[i]==s[i-1]||s[i]==s[i-2]||s[i-1]==s[i-2]) {
			if(i==2)
				printf("1 2\n");
			else
				printf("%d %d",i-2,i);
			return 0;
		}
	}
	puts("-1 -1");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
vector<int> G[610];
long double dp[610],ans = 6000000,INF = 1000000000000;
int a[610];
pair<int,int> p[200010];
int main(){
	cout.precision(20);
	int i,j,n,m;
	cin >> n >> m;
	for(i=0;i<m;i++){
		int s,t;
		cin >> s >> t; s--; t--;
		G[s].push_back(t);
		p[i] = {s,t};
	}
	for(i=0;i<n;i++){
		dp[i] = INF;
	}
	dp[n - 1] = 0;
	for(i=n - 2;i>=0;i--){
		long double mx = -1,sum = 0;
		j = -1;
		for(int v:G[i]){
			sum += dp[v];
			if(dp[v]>mx){
				mx = dp[v];
				j = v;
			}
			a[i] = j;
		}
		long double sz = G[i].size();
		dp[i] = sum/sz + (long double)1;
	}
	ans = min(ans,dp[0]);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			dp[j] = INF;
		}
		dp[n - 1] = 0;
		for(j=n - 2;j>=0;j--){
			long double sum = 0;
			for(int v:G[j]){
				if(j==i && v==a[j]) continue;
				sum += dp[v];
			}
			long double sz = G[j].size();
			if(j==i) sz--;
			dp[j] = sum/sz + (long double)1;
		}
		ans = min(ans,dp[0]);
	}
	cout << ans << endl;
}
			

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

int main()
{
	int i,ans=0;
	string f;
	cin>>f;
	for(i=0;i<f.size()-1;i++)
	{
		if(f[i]!=f[i+1])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
flag = 0
for i in range(N):
    if(A[i] % 2 != 0):
        continue
    else:
        if(A[i] % 3 != 0 and A[i] % 5 != 0):
            flag = 1
            break
if(flag == 0): print('APPROVED')
else: print('DENIED')

Measured memory_bytes: 3060
s = input()
ss = []
s1  ="R"
cnt = 0
for i in s:
    if i == s1:
        cnt+=1
    else:
        ss.append(cnt)
        cnt = 1
        if s1=="R":
            s1="L"
        else:
            s1="R"
ss.append(cnt)
ret = [0] * len(s)
v_total = 0
for i,v in enumerate(ss):
    v_total += v
    if i % 2 == 0:
        ret[v_total]+=v//2
        ret[v_total-1]+=(v+1)//2
    else:
        ret[v_total-v]+=(v+1)//2
        ret[v_total-v-1]+=v//2
print(" ".join(map(str,ret)))

Measured memory_bytes: 11260
#include<stdio.h>
#include<math.h>
int isprime(int n)
{
	int i;
	for(i=2;i<=(int)sqrt(n);i++)
	     if(n%i==0)
		 return 0;
	return 1;
}

int main()
{
	int X;
	while(scanf("%d",&X)!=EOF)
	{
		if(isprime(X))
		printf("%d\n",X);
		else
		{
			int i;
			for(i=X+1;;i++)
				if(isprime(i))
				{
					printf("%d\n",i);
					break;
				}
		}
		
	}
	return 0;
}

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

int main(){
    ll n,m;
    cin >> n >> m;
    if(2*n<=m){
        m-=2*n;
    }else{
        n=m/2;
        m=0;
    }
    cout << m/4+n;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<tuple>
#include<queue>
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;

typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
typedef tuple<int,int,int,int> tp;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};
vi p;
vvi q,r;
Def d[110][21][110];
Def wa[21][110][110];
class DIJ{
	public:
	struct edge{
		Def to,cost,com;
	};
	vector<vector<edge> > G;
	Def n,L;
	DIJ(Def size, Def l = 1){
		n = size;
		L = l;
		G = vector<vector<edge> >(n);
	}
	void syoki(){
		rep(i,21)rep(j,110)rep(k,110)wa[i][j][k]=inf;
		rep(i,21)rep(j,110)wa[i][j][j]=0;

	}
	void add_edge(Def a, Def b, Def c,Def d){
		edge e = {b,c,d}, ee = {a,c,d};
		G[a].pb(e);
		G[b].pb(ee);
		wa[d][a][b]=wa[d][b][a]=min(c,wa[d][a][b]);
	}
	void wa_shal(){
		rep(q,21)rep(i,n)rep(j,n)rep(k,n){
			wa[q][j][k]=min(wa[q][j][i]+wa[q][i][k],wa[q][j][k]);
		}
	}
	int g(int com,int d){
		int s=0;
		int j;
		for(j=0;j<p[com]-1;j++){
			if(d<q[com][j+1])break;
			s+=(q[com][j+1]-q[com][j])*r[com][j];
		}
		return (d-q[com][j])*r[com][j]+s;
	}
	int f(int com,int pre,int pos,int to){
		int ret=max(0,g(com,wa[com][pre][to])-g(com,wa[com][pre][pos]));
//		cout<<com<<" "<<pre<<" "<<pos<<" "<<to<<" "<<ret<<endl;
		return ret;
	}
	void dij(Def a, Def b){
		rep(i,110) rep(j,21) rep(k,110) d[i][j][k] = inf;
		d[a][0][a] = 0;
		priority_queue<tp> q;
		q.push(tp(0,a,0,a));
		while(!q.empty()){
			Def pos,com,pre,cost;//cost, pos, t;
			tie(cost,pos,com,pre) = q.top();
			cost *= -1;
			q.pop();
			if(cost > d[pos][com][pre]) continue;
//			cout<<cost<<" "<<pos<<" "<<com<<" "<<pre<<endl;
			rep(i,G[pos].size()){
				edge e = G[pos][i];
				Def to = e.to;
				Def ncom = e.com;//(a * v + b) % c;
				Def ncost = cost;//+f(e.com,pos,to);// + e.cost * v;
				Def npre;//=pos;
				if(com==ncom){
					ncost+=f(e.com,pre,pos,to);
					npre=pre;
				}else{
					ncost+=f(e.com,pos,pos,to);
					npre=pos;
				}
				if(ncost < d[to][ncom][npre]){
					d[to][ncom][npre] = ncost;
					q.push(tp(-ncost, to, ncom, npre));
				}
			}
		}
		int out = inf;
		rep(i,21)rep(j,110) out = min(out, d[b][i][j]);
		if(out==inf)cout<<-1<<endl;
		else cout << out << endl;
	}
};
int main(){
	int n,m,c,s,g;
	while(cin>>n>>m>>c>>s>>g,n){
		DIJ dij(n);
		dij.syoki();
		rep(i,m){
			int x,y,d,C;
			cin>>x>>y>>d>>C;
			dij.add_edge(x-1,y-1,d,C-1);
		}
		p=vi(c);
		rep(i,c)cin>>p[i];
		q=vvi(c);
		r=vvi(c);
		rep(i,c){
			q[i]=vi(p[i]);
			rep(j,p[i]-1)cin>>q[i][j+1];
			r[i]=vi(p[i]);
			rep(j,p[i])cin>>r[i][j];
		}
		dij.wa_shal();
		dij.dij(s-1,g-1);
	}
}

Measured memory_bytes: 5956
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

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

int main(void)
{
    ll k;
    cin >> k;
    rep(i,k) cout << "ACL";
    
    return 0;
}


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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 1000;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(cin >> n >> m) {
    for(int i = 0; i < n; ++i) {
      cin >> ps[i].first >> ps[i].second;
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; cin >> s >> t >> u >> v;
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1320
import math
from collections import defaultdict
N, M = list(map(int, input().split(' ')))
if M == 1:
    print(1)  # a_i = 1 for all i
    exit(0)
# prime factorization of M
fact = defaultdict(int)
for i in range(2, int(math.sqrt(M) + 1)):
    while M % i == 0:
        M //= i
        fact[i] += 1
if M != 1:
    # M is prime
    fact[M] = 1
# calculate answer
answer = 1
mod = 10**9 + 7
for f in fact.values():
    # calc combination(f + N - 1, f) = (f + N - 1) * ... * N / f!
    numerator = 1
    denominator = 1
    for i in range(f):
        numerator *= (N + i)
        denominator *= (i + 1)
    answer *= (numerator // denominator)
    answer %= mod
print(answer)

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		StringBuffer sb =new StringBuffer(br.readLine());
		int start = 0;
		int end = sb.length() - 1;
		int count = 0;
		
		while(end > start)
		{
			if(sb.charAt(start) == 'W')
			{
				if(sb.charAt(end) == 'R')
				{
				//	sb.replace(start, end, sb.toString());
					count++;
					start++;
					end--;
					
				}
				else
				{
					end--;
				}
			}
			else
			{
				start++;
				
			}
			//System.out.println(count);
		}
		System.out.println(count);
		
	}

}


Measured memory_bytes: 36280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    string S;
    cin >> S;
    int a = S[0] - '0';
    int b = S[1] - '0';
    int c = S[2] - '0';
    int d = S[3] - '0';

    int op1[8] = {0, 0, 0, 0, 1, 1, 1, 1};
    int op2[8] = {0, 0, 1, 1, 0, 0, 1, 1};
    int op3[8] = {0, 1, 0, 1, 0, 1, 0, 1};

    for (int i = 0; i < 8; i++)
    {
        int ans = a;
        if (op1[i])
        {
            ans += b;
        }
        else
        {
            ans -= b;
        }
        if (op2[i])
        {
            ans += c;
        }
        else
        {
            ans -= c;
        }
        if (op3[i])
        {
            ans += d;
        }
        else
        {
            ans -= d;
        }
        if (ans == 7)
        {
            cout << a << (op1[i] ? '+' : '-');
            cout << b << (op2[i] ? '+' : '-');
            cout << c << (op3[i] ? '+' : '-');
            cout << d << "=7" << endl;
            return 0;
        }
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
from math import cos, radians, sqrt

a_hour_cm, b_min_cm, h_time_hour, m_time_min = map(int, input().split())

min_hand_angle = m_time_min * 6
hour_hand_angle = h_time_hour * 30 + m_time_min / 2

sandwiched_angle = abs(hour_hand_angle - min_hand_angle)

result = sqrt(a_hour_cm ** 2 + b_min_cm ** 2 - 2 * a_hour_cm * b_min_cm * cos(radians(sandwiched_angle)))
print(result)


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

#define int long long

const int N = 1e5 + 10;
int n, ar[N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	sort(ar, ar + n);
	
	int x = ar[n - 1], mn = abs(x / 2 - ar[0]), ans = ar[0];
	for (int i = 0; i < n - 1; i++)
		if (abs((x + 1) / 2 - ar[i]) < mn)
			mn = abs((x + 1) / 2 - ar[i]), ans = ar[i];
	cout << x << ' ' << ans << endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int d, n;
  cin >> d >> n;
  if(d==0){
    if(n==100){
      cout << 101 << endl;
    }else{
      cout << n << endl;
    }
  }
  else if(d==1){
    int sum = 100;
    if(n==100){
      cout << 10100 << endl;
    }else{
      cout << n * 100 << endl;
    }
  }
  else if(d==2){
    if(n==100){
      cout << 1010000 << endl;
    }
    else{
      cout << n * 10000 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    string S; cin >> S;
    int a=0,b=0; int pos=0,res=0;
    rep(i,S.size()){
        if(S[i]=='(') {b++; pos++;}
        else {a++; if(pos>0){pos--; res++;} }
    }
    rep(i,a-res){
        cout << '(' ;
    }
    cout << S;
    rep(i,b-res){
        cout << ')';
    }
    cout << endl;
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2* array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2* array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
	cout << endl;
}

class list {
private:
	class elm {
	public:
		int val;
		bool sav;
		elm* fwd,*bwd;
	};
	elm* top;
public:
	list() {
		top = new elm;
		top->fwd = top;
		top->bwd = top;
		top->sav = true;
	}
	void ins(int x) {
		elm* ne = new elm;
		ne->val = x;
		ne->fwd = top;
		ne->bwd = top->bwd;
		ne->sav = false;
		top->bwd->fwd = ne;
		top->bwd = ne;
	}
	void del(int x) {
		elm *cur = top->bwd;
		while(cur != top) {
			if(cur->val == x) {
				cur->fwd->bwd = cur->bwd;
				cur->bwd->fwd = cur->fwd;
				return;
			}
			cur = cur->bwd;
		}
	}
	void delF() {
		top->bwd = top->bwd->bwd;
		top->bwd->fwd = top;
	}
	void delL() {
		top->fwd = top->fwd->fwd;
		top->fwd->bwd = top;
	}
	void dump() {
		elm *cur = top->bwd;
		while(cur != top) {
			cout << cur->val;
			cur = cur->bwd;
			if(cur != top) cout << " ";
		}
		cout << endl;
	}
};

int main(int argc,char** argv) {
	int n;
	string s;
	cin >> n;
	list l;
	for(int i = 0;i < n;i++) {
		cin >> s;
		if(s == "insert") {
			int a;
			cin >> a;
			l.ins(a);
		}else if(s == "delete") {
			int a;
			cin >> a;
			l.del(a);
		}else if(s == "deleteFirst") l.delF();
		else if(s == "deleteLast") l.delL();
	}
	l.dump();
}



Measured memory_bytes: 37508
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int main(){
    int d,n;
    cin >> d >> n;
    if(n==100) n++;
    if(d<1){
        cout << n << endl;
    }else{
        int ans = 1;
        for(int i=0; i<d; i++){
            ans*=100;
        }
        cout << ans*n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
K = int(input())

def S(n):
    return sum(int(c) for c in str(n))

n9 = 0  # the number of 9s

count = 0
upper = 1
while count < K:
    n = int(str(upper) + ('9' * n9))
    if n <= S(n) * (10 ** n9):
        print(n)
        count += 1
        upper += 1
    else:
        n9 += 1
        upper //= 10


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


typedef unsigned long long ull;
int n, m, p, q;
const int max_size = 1000;
char field[max_size][max_size]; // でかい方
char patterns[max_size][max_size]; // 小さい方

ull hash_[max_size][max_size], tmp[max_size][max_size];

// でかい方のhash計算用だが, 小さい方にも使える
void compute_hash(char a[max_size][max_size], int n, int m) {
    const ull B1 = 9973;
    const ull B2 = 1000000007;
    
    // B1^q
    ull t1 = 1;
    rep(j, q) t1 *= B1;
    
    // 行方向
    rep(i, n) {
        ull e = 0;
        rep(j, q) e = e * B1 + a[i][j];
        for (int j = 0; j + q <= m; ++j) {
            tmp[i][j] = e;
            if (j + q < m) e = e * B1 - t1 * a[i][j] + a[i][j + q];
        }
    }
    
    // B1^p
    ull t2 = 1;
    rep(i, p) t2 *= B2;
    
    // 列方向
    for (int j = 0; j + q <= m; ++j) {
        ull e = 0;
        rep(i, p) e = e * B2 + tmp[i][j];
        
        for (int i = 0; i + p <= n; ++i) {
            hash_[i][j] = e;
            if (i + p < n) e = e * B2 - t2 * tmp[i][j] + tmp[i + p][j];
        }
    }
}

void solve() {
    set<ull> unseen;
    
    compute_hash(patterns, p, q);
    unseen.insert(hash_[0][0]);
    // cout << hash_[0][0] << endl;
    
    compute_hash(field, n, m);
    for (int i = 0; i + p <= n; ++i) {
        for (int j = 0; j + q <= m; ++j) {
            // cout << i << " " << j << " " << hash_[i][j] << " " << n << " " << m << " " << p << " " << q << endl;
            
            if (unseen.find(hash_[i][j]) != unseen.end()) {
                cout << i << " " << j << endl;
            }
        }
    }
    
    
}

int main() {
    
    cin >> n >> m;
    rep(i, n) rep(j, m) cin >> field[i][j];
    
    cin >> p >> q;
    rep(i, p) rep(j, q) cin >> patterns[i][j];
    
    solve();
}



Measured memory_bytes: 19700
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define re register
#define MAXN 200001
#define inf 200001
#define ll long long
using namespace std;
double d,n,m;
int main()
{
	cin>>n>>m>>d;
	double v=(n-d)*2;
	if(d==0) v/=2;
	printf("%.10lf",v/(n*n)*(m-1));
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      int l = s - i - j;
      if (l + i + j == s && l >= 0 && l <= k) {
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


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

int main()
{
    int orderTime = 0;

    int minMiddle = 10;
    for (int i = 0; i < 5; ++i)
    {
        int input;
        cin >> input;

        orderTime += ((input + 9) / 10) * 10;

        int singleMiddle = input % 10;

        if (singleMiddle != 0)
        {
            minMiddle = min(minMiddle, input % 10);
        }
    }

    orderTime = orderTime - 10 + minMiddle;

    cout << orderTime << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <functional>

using namespace std;

int main()
{
	int N;

	cin >> N;

	vector<long long> a(3 * N);
	for(int i = 0 ; i < 3 * N ; ++i)
		cin >> a[i];

	vector<long long> af(3 * N, -((long long)1) << 60);
	vector<long long> ab(3 * N, ((long long)1) << 60);

	long long ca;
	vector<long long> ha(N);
	for(int i = 0 ; i < N ; ++i)
		ha[i] = a[i];
	ca = accumulate(ha.begin(), ha.end(), (long long)0);
	make_heap(ha.begin(), ha.end(), greater<long long>());

	for(int i = N ; i < 3 * N ; ++i) {
		af[i] = ca;
		if(ha.front() < a[i]) {
			pop_heap(ha.begin(), ha.end(), greater<long long>());
			ca = ca - ha.back() + a[i];
			ha.back() = a[i];
			push_heap(ha.begin(), ha.end(), greater<long long>());
		}
	}

	for(int i = 0 ; i < N ; ++i)
		ha[i] = a[3*N-i-1];
	ca = accumulate(ha.begin(), ha.end(), (long long)0);
	make_heap(ha.begin(), ha.end());

	for(int i = N ; i < 3 * N ; ++i) {
		ab[3*N-i] = ca;
		if(ha.front() > a[3*N-i-1]) {
			pop_heap(ha.begin(), ha.end());
			ca = ca - ha.back() + a[3*N-i-1];
			ha.back() = a[3*N-i-1];
			push_heap(ha.begin(), ha.end());
		}
	}

	long long result = -(((long long)1) << 60);
	for(int i = 0 ; i < 3 * N ; ++i)
		result = max(result, af[i] - ab[i]);

	cout << result << endl;
}


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

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N), L(N);
    for (int i = 0; i < N; i++) cin >> P[i];
    for (int i = 0; i < N; i++) cin >> Q[i];
    for (int i = 0; i < N; i++) L[i] = i+1;

    int a = 0, b = 0;
    do { 
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (P[i] != L[i]) flag = false;
        }
        if (flag) break;
        a++;
    } while (next_permutation(L.begin(), L.end()));

    sort(L.begin(), L.end());
    do { 
        bool flag = true;
        for (int i = 0; i < N; i++) {
            if (Q[i] != L[i]) flag = false;
        }
        if (flag) break;
        b++;
    } while (next_permutation(L.begin(), L.end()));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
    return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  if(A > 12){
    cout << B << endl;
  }else if(A < 6){
    cout << 0 << endl;
  }else{
    cout << B / 2 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int k,a,b,i,c=0;
  cin>>k>>a>>b;
  for(i=a;i<=b;i++)
  {
    if(i%k==0)
      c++;
  }
  if(c>0)
    cout<<"OK";
  else
    cout<<"NG";
  return 0;
}

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

using namespace std;

int n,i,j,a[100005],cnt[100005];

int main(){
	scanf("%d", &n);
	
	for(i = 0; i < n; i++){
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	
	sort(a, a + n);
	
	for(i = 0; i < n - 1; i++){
		if(a[i + 1] - a[i] > 1)
		return 0 * printf("No\n"); 
	}
	
	//ONLY ONE NUM
	if(a[0] == a[n - 1]){
		if(n >= a[0] * 2 || a[0] + 1 == n)
		return 0 * printf("Yes\n");
		else
		printf("No\n");
	}
	else{
		if(cnt[a[0]] <= a[0] && (n - cnt[a[0]]) >= 2 * (a[n - 1] - cnt[a[0]]))
		return 0 * printf("Yes\n");
		
		if(cnt[a[0]] == a[0])
		return 0 * printf("Yes\n");
		
		printf("No\n");
	}
}


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

int dp[100001];

int solve(int a[], int pos, int n)
{
    if (pos == n)
        return (dp[pos] = 0);
    if (dp[pos] != -1)
        return dp[pos];
    if (pos <= n - 2)
        return (dp[pos] = min(solve(a, pos + 1, n) + abs(a[pos] - a[pos - 1]), solve(a, pos + 2, n) + abs(a[pos - 1] - a[pos + 1])));
    else
        return (dp[pos] = abs(a[pos - 1] - a[n - 1]));
}

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

    int a[n];
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }

    cout<<solve(a, 1, n)<<endl;
    return 0;
}

Measured memory_bytes: 8304
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int dist = abs(a - b);
    cout << (dist % 2 == 0 ?  "Alice" : "Borys") << endl;
    
    return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int h,w;
	vector<string> v;

	cin >> h >> w;
	v.resize(h);
	for(int i = 0; i < h; i++)
		cin >> v[i];

	for(int i = -1; i <= h; i++)
		if(i == -1 || i == h)
			cout << string(w+2,'#') << endl;
		else
			cout << "#" << v[i] << "#" << endl;

	return 0;
}

Measured memory_bytes: 256
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);Yo sé que algunas cosas están mal, pero precisamente ese toque de prohibido o de rareza, es lo que logra lo que estoy buscando en ese momento, placer.
#else
    fastIO;
#endif
    ll n, T;
    cin >> n >> T;
    vector<ll> t(n);
    forn(i, n) cin >> t[i];
    ll ans = 0;
    forn(i, n - 1) {
        ans += min(t[i] + T, t[i + 1]) - t[i];
    }
    cout << ans + T << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<vector>
//#include<string>

using namespace std;

void elem_swap(int &a,int &b){
  int temp=a;
  a=b;
  b=temp;
}

int bubbleSort(vector<int> &vec,int size){
  bool flag=true;
  int count=0;
  for(int i=0;i<size-1;i++){
    for(int j=0;j<size-1-i;j++){
      if(vec.at(j)>vec.at(j+1)){
        elem_swap(vec.at(j),vec.at(j+1));
        flag=false;
        count++;
      }
    }
    if(flag) break;
  }
  return count;
}

int main(void){
  int size,count;
  cin>>size;
  vector<int> vec(size);
  for(int i=0;i<size;i++) cin>>vec.at(i);
  count=bubbleSort(vec,size);
  for(int i=0;i<size-1;i++) cout<<vec.at(i)<<" ";
  cout<<vec.at(size-1)<<endl;
  cout<<count<<endl;

}



Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
using namespace std;
signed main(){
	int n,a=0,b,ma=0;
	cin>>n;
	f(i,n){
		cin>>b;
		a+=b;
		ma=max(ma,b);
	}
	if(a>ma*2) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
/// 2222 by 1 february, thx

#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long n, m;
long long dp[102][100002];
bool viz[102][100002];
struct str
{
    long long weight, value;
};
str v[102];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> v[i].weight >> v[i].value;
    viz[0][0] = 1;
    long long ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 0; j <= m; ++j)
            if(viz[i-1][j])
            {
                if(j + v[i].weight <= m)
                {
                    viz[i][j + v[i].weight] = 1;
                    dp[i][j + v[i].weight] = max(dp[i][j + v[i].weight], dp[i-1][j] + v[i].value);
                    ans = max(ans, dp[i][j + v[i].weight]);
                }
                viz[i][j] = 1;
                dp[i][j] = max(dp[i][j], dp[i-1][j]);
            }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 88576
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include <string.h>
using namespace std;

int main() {
	int			N;
	unsigned long long	A, sum = 1;
	long long	l[100000];

	cin >> N;

	for (int ii = 0; ii < N; ii++) {
		cin >> A;
		if (A == 0) {
			cout << 0 << endl;
			return 0;
		}
		l[ii] = A;
	}

	for (int ii = 0; ii < N; ii++) {
		if (sum * l[ii] == 0 || sum * l[ii] > 1000000000000000000) {
			cout << -1 << endl;
			return 0;
		}
		else {
			if (sum * l[ii] / l[ii] == sum) {
				sum = sum * l[ii];
			}
			else {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << sum << endl;
	return 0;
}

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

// ABC-084-D

// 累積和
struct cumulative_sum {
    using lint = long long int;
    int sz;
    // data[i]:元の数列
    vector<lint> data;
    // cum[i]:[0,i)の和
    vector<lint> sum;
    // 要素数を指定して初期化
    cumulative_sum(const int _sz) : sz(_sz) {
        data.assign(sz, 0);
        sum.assign(sz + 1, 0);
    }
    lint& operator[](const int k) {
        return data[k];
    }
    // dataに基づいてsumを構築
    void build() {
        for (int i = 0; i < sz; i++) sum[i + 1] = sum[i] + data[i];
    }
    // [a,b)の和を求める
    lint query(const int a, const int b) {
        return sum[b] - sum[a];
    }
};

int q;
vector<int> l, r;

//エラトステネスの篩
vector<bool> eratosthenes_sieve(int n) {
    vector<bool> res(n + 1, true);
    res[0] = res[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (res[i]) {
            for (int j = i; i * j <= n; j++) res[i * j] = false;
        }
    }
    return res;
}

int main() {
    vector<bool> p = eratosthenes_sieve(1e+5);
    cumulative_sum cum(1e+5 + 1);
    for (int i = 0; i <= 1e+5; i++) {
        if (i % 2 == 1 && p[i] && p[(i + 1) / 2]) {
            cum[i] = 1;
        } else {
            cum[i] = 0;
        }
    }
    cum.build();
    cin >> q;
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        r++;
        cout << cum.query(l, r) << endl;
    }
}

Measured memory_bytes: 2176
#include <iostream>

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

using namespace std;

int main(void)
{
  int A, B, ans;

  cin >> A >> B;

  if((ans = A + B) >= 10)
    cout << "error" << endl;
  else
    cout << ans << endl;
  return 0;
}


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


int main()
{int N, Q, a;
 long long K;
 int C[Q];
 cin >> N >> K >> Q;
 rep(i, Q){
   cin >> a;
   C[a-1]++;}
 rep(a, N){
   if(C[a]>=Q-K+1)
     cout << "Yes" << endl;
   else cout << "No" << endl;
 }
     
   
     
}

Measured memory_bytes: 3072
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"


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

	int n,m;
	cin>>n>>m;
	int t=0,c=1;
	rep(i,n){
		int a;cin>>a;
		t+=a;
		if(t<=m)c++;
	}
	cout<<c<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
      	int y = Integer.parseInt(sc.next());
      	int k = (x+y)/3;
      	int ans = 0;
      	if((x+y)%3==0 && x-k>=0 && y-k>=0){
          ans = modCombination(x+y-2*k,x-k,1000000007);
        }
      	System.out.print(ans);
        System.out.flush();
    }
    public static int modCombination(int n , int k , int div){
        long fact = 1;
        long inverse = 1;
        for(int i=n;i>=n-k+1;i--){
            fact = (fact*i)%div;
            inverse = (inverse*(i-n+k))%div;
        }

        return (int)((fact*pow(inverse,div-2,div))%div);
    }
    //xのn乗をmodで割ったあまりを返す
    public static long pow(long x,int n,int div){
        long ans = 1;
        while(n>0){
            if((n & 1)==1){
                ans = (ans*x)%div;
            }
            x = (x*x)%div;
            n>>=1;
        }
        return ans;
    }
}

Measured memory_bytes: 23124
use proconio::input;
use std::cmp::{max, min};

const MAX_L: u32 = 100_000;
const BASE_SIZE: usize = 1 << 11;

fn main() {
    input! {
        n: usize,
        vw: [(u32, u32); n],
        q: usize,
        vl: [(usize, u32); q],
    }
    let dp = make_dp(&vw);
    for vlq in vl {
        println!("{}", calc(&vw, vlq.0 - 1, vlq.1, &dp));
    }
}

fn make_dp(vw: &Vec<(u32, u32)>) -> Vec<Vec<u32>> {
    let mut dp = Vec::<Vec<u32>>::new();

    dp.push(
        (0..=MAX_L)
        .map(|i| if i < vw[0].1 { 0 } else { vw[0].0 })
        .collect()
    );

    let n = min(vw.len(), BASE_SIZE - 1);
    for c in 1..n {
        let p = (c - 1) / 2;
        dp.push(
            (0..=MAX_L)
            .map(|i| {
                let w = vw[c].1;
                let v = if i < w { 0 } else { dp[p][(i - w) as usize] + vw[c].0 };
                max(dp[p][i as usize], v)
            })
            .collect()
        );
    }

    dp
}

fn calc(
    vw: &Vec<(u32, u32)>,
    u: usize, 
    l: u32,
    dp: &Vec<Vec<u32>>
) -> u32 {
    if u < dp.len() {
        dp[u][l as usize]
    } else {
        let p = (u - 1) / 2;
        let w = vw[u].1;
        let pv1 = calc(vw, p, l, dp);
        let pv2 = if l < w { 0 } else { calc(vw, p, l - w, dp) + vw[u].0 };
        max(pv1, pv2)
    }
}


Measured memory_bytes: 813304
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;

int main() {
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
    ll k = (a1 - b1) * t1 + (a2 - b2) * t2;
    if (k == 0) {
        cout << "infinity" << endl;
        return 0;
    }

    if (a1 < b1) {
        swap(a1, b1);
        swap(a2, b2);
        k = -k;
    }

    if (k > 0) {
        cout << 0 << endl;
        return 0;
    }

    if (a1 - b1 > 0) {
        if (a2 - b2 > 0) {
            cout << 0 << endl;
            return 0;
        }
        else {
            ll m = (a1 - b1) * t1;
            //cout << m << " " << k << endl;
            cout << (2 * ((m - 1) / -k) + 1 + (m % (-k) == 0)) << endl;
        }
    }
    else {
        cout << 0 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <set>
#include <string>
#include <math.h>
#include <map>
#include <climits>
#include <iomanip>


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

#define ll long long

using namespace std;

void A();
void B();
void C();
void D();
void E();
void F();

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

	B();


}

void A() {
	string s;
	cin >> s;

	cout << (s == "ABC" ? "ARC" : "ABC") << '\n';

}

void B() {
	int N, K;
	cin >> N >> K;

	set<int> have;

	forn(k, K) {

		int d;
		cin >> d;

		forn(dd, d) {

			int sn;
			cin >> sn;
			have.insert(sn);

		}
	}

	int c = 0;
	forn(i, N) {
		if (have.find(i+1) == have.end()) c++;
	}

	cout << c;

}

void C() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {

		int N;
		cin >> N;


		int result = 0;

		cout << "Case #" << t << ": ";

		cout << result << endl;

	}
}

void D() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {

		int N;
		cin >> N;


		int result = 0;

		cout << "Case #" << t << ": ";

		cout << result << endl;

	}
}

void E() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {

		int N;
		cin >> N;


		int result = 0;

		cout << "Case #" << t << ": ";

		cout << result << endl;

	}
}

void F() {
	int T;
	cin >> T;
	for (int t = 1; t <= T; t++) {

		int N;
		cin >> N;


		int result = 0;

		cout << "Case #" << t << ": ";

		cout << result << endl;

	}
}



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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}
int sum(vector<int> arr){int cnt = 0;rep(i,0,arr.size()){cnt += arr[i];}return cnt;}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}

//main------------------------------------------------------------------------------------------



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

    
    string s = raw_input();

    int i = 0;
    while(i < s.size()){
        if(i % 2 == 0) cout << s[i];
        i++;
    }
    cout << endl;


}

Measured memory_bytes: 592
require 'pp'

def gets; ARGF.gets; end

class Solver

  def main
    n = gets.chomp.to_i

    nums = gets.chomp.split.map(&:to_i)

    min_a = 1000000001
    nums.reverse.each do |a|
      if min_a + 1 < a
        puts "No"
        return
      end

      min_a = a if a < min_a
    end

    puts "Yes"
  end
end

if __FILE__ == $0
  Solver.new.main
end


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

const int INF = 1e9;

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

	vector<int> c;
	int dp[111111];

	c.push_back(1);
	for (int i = 6; i <= N; i *= 6) c.push_back(i);
	for (int i = 9; i <= N; i *= 9) c.push_back(i);

	fill(dp, dp + N + 1, INF);
	dp[0] = 0;

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j<c.size(); j++) {
			if (i >= c[j]) {
				dp[i] = min(dp[i], dp[i - c[j]] + 1);
			}
		}
	}

	cout << dp[N] << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

	while(true){
        String W1;
        int m = 0,h=0;
        
        String W = sc.next();
        if(W.equals("-"))
           break;
        
        m = sc.nextInt();;
        for(int i=0 ; i<m;i++){
        	h = sc.nextInt();
        	W1= "";
        	W1+=W.substring(h,(W.length()));
       		W1+=W.substring(0,h);
            W=W1;
		}
        System.out.println(W);
    }
        
    
	}
}


Measured memory_bytes: 26572