akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> PIII;

int main(void) {
    int n;
    int m;
    cin >> n >> m;
    VI score(n, 0);
    VI target(m);
    for (int i = 0; i < m; i++) {
        cin >> target[i];
        target[i]--;
    }
    int simei;
    int hazure;
    for (int i = 0; i < m; i++) {
        hazure = 0;
        for (int j = 0; j < n; j++) {
            cin >> simei;
            simei--;
            if (simei == target[i]) {
                score[j]++;
            } else {
                hazure++;
            }
        }
        score[target[i]] += hazure;
    }

    for (int j = 0; j < n; j++) {
        cout << score[j] << endl;
    }

}

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

using namespace std;
int n,a[200005],b[200005],i;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    if(n%2==1)
        cout<<b[n/2+1]-a[n/2+1]+1;
    else {
        int x=(a[n/2]+a[n/2+1]);
        int y=(b[n/2]+b[n/2+1]);
        cout<<y-x+1;
    }
    return 0;
}


Measured memory_bytes: 5140
#include<cstdio>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int ma=1e5;
char s[ma];
int a,b;
int max(int a,int b){return a>b?a:b;}
main()
{
    scanf("%d%d%s",&a,&b,s);
    vector<pair<int,bool> >v(a);
    int i=0,j=0;
    int ans=0;
    while(j<a)
    {
        while(j<a&&s[j]=='1')++j;
        ans=max(ans,j-i);
        while(j<a&&s[j]=='0')j++;
        b--;
        if(b<0)
        {
            while(i<a&&s[i]=='1')++i;
            while(i<a&&s[i]=='0')++i;
        }
        ans=max(ans,j-i);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        while(true){
            int n = scan.nextInt();
            if(n == 0)break;
            int scores[] = new int[n];
            int sum = 0;
            for(int i = 0;i < n;i++){
                int j = scan.nextInt();
                sum += j;
                scores[i] = j;
            }
            double average = (double)sum / n;
            double bunsan = 0;
            for(int i = 0;i < n;i++)bunsan += (scores[i] - average)*(scores[i] - average);
            bunsan /= n;            
            double hensa = Math.sqrt(bunsan);
            System.out.printf("%.8f\n", hensa);
        
        }
        scan.close();
    }

    

}


Measured memory_bytes: 31532
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
using namespace std;
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

char mp[10][10] = {};
string s;

signed main() {

  while (cin >> s) {
    if (s == "#") break;
    int a[4];
    rep(i, 4) cin >> a[i], a[i]--;
    int x = 0, y = 0, len = 0;
    while (s[x] != '/') {
      if (isdigit(s[x])) {
        len += s[x] - '0';
      } else
        len++;
      x++;
    }
    x = 0;
    rep(i, s.size()) {
      if (s[i] == '/')
        y++, x = 0;
      else if (isdigit(s[i])) {
        int width = s[i] - '0';
        rep(j, width) mp[y][x] = '.', x++;
      } else {
        mp[y][x] = s[i];
        x++;
      }
    }
    // cout << "tate" << y + 1 << ' ' << "yoko" << len << endl;
    // rep(i, y + 1) {
    //   rep(j, len) cout << mp[i][j];
    //   cout << endl;
    // }
    swap(mp[a[0]][a[1]], mp[a[2]][a[3]]);
    // cout << endl;
    // rep(i, y + 1) {
    //   rep(j, len) cout << mp[i][j];
    //   cout << endl;
    // }
    string ans = "";
    rep(i, y + 1) {
      rep(j, len) {
        if (isalpha(mp[i][j])) {
          ans += mp[i][j];
        } else {
          int num = 0;
          while (j < len && mp[i][j] == '.') {
            num++;
            j++;
          }
          j--;
          ans += to_string(num);
        }
      }
      if (i < y) ans += '/';
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3268
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;

bitset<16080> p[2];
char S[8080];

int main()
{
	scanf ("%s",S);
	int d = -1, l = 0, x, s[2] = {0,};
	p[1][0] = 1;
	for (int i=0;;i++){
		if (S[i] == 'T' || S[i] == 0){
			if (d == -1){
				d = 0;
				p[0][2*l] = 1;
			}
			else p[d] |= p[d] << (2*l);
			s[d] += l;
			l = 0;
			d = !d;

			if (S[i] == 0) break;
		}
		else l++;
	}

	int X,Y; scanf ("%d %d",&X,&Y);
	X += s[0], Y += s[1];
	if (0 <= X && p[0][X] && 0 <= Y && p[1][Y]) puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 128
/*B - Popular Vote*/

#include <bits/stdc++.h>

using namespace std;

int main(){
	
	int tam;
	double M;

	cin >> tam >> M;

	vector <double> arr(tam);

	double frac = 4.0 * M;
	double total = 0.0;
	int ans = 0;
	for (int i = 0; i < tam; ++i)
	{
		cin >> arr[i];
		total += arr[i];
	}

	frac = total / frac;

	for (int i = 0; i < tam; ++i)
	{
		if(arr[i] >= frac){
			ans++;
		}
	}

	if(ans >= M){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T>
T sq(T x){
  return x * x;
}

signed main (){
  ll A;
  long double B;
cin >> A >> B;
  ll ans = floor(A * B);
  cout << ans << endl;  
  return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	vector<int> A(n);
	for (int i = 0; i < n; ++i)
		cin >> A[i];
	sort(all(A));
	int ans = 0;
	int tmp = A[0];
	int cnt = 1;
	for (int i = 1; i < n; ++i)
	{
		if (A[i] == tmp)
			++cnt;
		else
		{
			if (cnt % 2 == 1)
				++ans;
			tmp = A[i];
			cnt = 1;
		}
	}
	if (cnt % 2 == 1)
		++ans;
	cout << ans << endl;
}



Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;
int main() {
	int n;
	double a[100], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ans += 1 / a[i];
	}
	cout << 1 / ans << endl;
	return 0;
}

Measured memory_bytes: 256
/**-------------------------
|--------From A.R.A--------|
-------------------------**/

#include <bits/stdc++.h>

#define ll            long long int
#define pb            push_back
#define ull           unsigned long long int
#define endl          "\n"
#define sz(c)         (c).size()
#define sall(c)       sort((c).begin(),(c).end())
#define rsall(c)      sort((c).rbegin(),(c).rend())
#define rev(c)        reverse((c).begin(),(c).end())
#define FOR(i,n)      for(ll i=0;i<n;i++)
#define max3(a,b,c)   max(max(a,b),c)
#define min3(a,b,c)   min(min(a,b),c)
#define input(a,i,n)  for(ll i=0;i<n;i++){      cin>>a[i];}
#define output(a,i,n) for(ll i=0;i<n;i++){cout<<a[i]<<" ";}

using namespace std;
int main()
{
    int64_t k,res=0;
    cin>>k;
    for(int i=1,x=0;i<=k;i++){
        cin>>x;
        if(x%2==1 && i%2==1){res++;}
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3576
#include<stdio.h>
main(){
  int H,W,c,d;
  while(1){
    scanf("%d %d",&H,&W);
    if(H==0 && W==0)break;
    for(c=0;c<H;c++){
      for(d=0;d<W;d++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        if(A[i] > i){
            cout << -1 << endl;
            return 0;
        } 
    }
    rep(i,N-1){
        if(A[i+1] - A[i] > 1){
            cout << -1 << endl;
            return 0;
        }
    }
    map<ll,ll> mp;
    rep(i,N){
        B[i] = i-A[i];
        mp[B[i]] = A[i];
    }
    rep(i,N-1){
        if(B[i+1] < B[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    for(auto& e:mp){
        ans += e.second;
    }
    cout << ans
     << endl;
}

Measured memory_bytes: 17408
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
struct P {
	int x, y;
};
bool operator<(P a, P b) {
	if (a.x < b.x) return true;
	else if (a.x > b.x) return false;
	else {
		if (a.y < b.y) return true;
		else return false;
	}
}
P a[200];
P b[1000];
int main() {
	int n, m;
	while (cin >> n&&n != 0) {
		P simi;
		for (int i = 0; i < n; i++) {
			cin >> simi.x >> simi.y;
			a[i] = simi;
		}
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> simi.x >> simi.y;
			b[i] = simi;
		}
		sort(a, a + n);
		sort(b, b + m);
		for (int i = 0; i < m; i++) {
			int c = b[i].x - a[0].x;
			int d = b[i].y - a[0].y;
			bool l = true;
			for (int j = 1; j < n; j++) {
				int s = 0, e = m - 1, t;
				while (e - s > 1) {
					t = ceil((e + s) / 2.0);
					if (b[t].x < a[j].x+c) s = t;
					else if (b[t].x > a[j].x+c) e = t;
					else {
						if (b[t].y < a[j].y+d) s = t;
						else if (b[t].y >= a[j].y+d) e = t;
					}
				}
				if (!((b[s].x == a[j].x + c&&b[s].y == a[j].y + d) || (b[e].x == a[j].x + c&&b[e].y == a[j].y + d))) {
					l = false;
					break;
				}
			}
			if (l) {
				cout << c << " " << d << endl;
			}
		}
	}
}

Measured memory_bytes: 3028
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll ans;
int main() {
	ll m, d;
	cin >> m >> d;
	REPO(i, m) {
		REPO(j, d) {
			if (j % 10 >= 2 and j / 10 >= 2) {
				if ((j % 10) * (j / 10) == i) ans++;
			}
		}
	}
	cout << ans << endl;
}
	


Measured memory_bytes: 256
N = int(input())
Flag = True
x_bef = 0
y_bef = 0
t_bef = 0
for _ in range(N):
    t_now,x_now,y_now = map(int,input().split())
    t = t_now - t_bef
    x = abs(x_now - x_bef)
    y = abs(y_now - y_bef)
    if t - x - y < 0 :
        Flag = False
        break
    elif (t - x - y)%2 != 0:
        Flag = False
        break
print('Yes' if Flag else 'No')

Measured memory_bytes: 3064
#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 ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

ll BLOCK_SZ;
bool cmp(pair<ii, ll> &x, pair<ii,ll> &y){
  if(x.ff.ff/BLOCK_SZ != y.ff.ff/BLOCK_SZ){
    return x.ff.ff<y.ff.ff;
  }
  else return ((x.ff.ff/BLOCK_SZ)&1?x.ff.ss>y.ff.ss:x.ff.ss<y.ff.ss);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll n,q;
        cin>>n>>q;

        ll c[n];
        rep(i,n) cin>>c[i];
        ll l,r;

        BLOCK_SZ = (ll)sqrt(n)+1;

        vector<pair<ii, ll> > qr;
        rep(i,q){
            cin>>l>>r;
            qr.pb(mp(mp(l-1, r-1), i));
        }

        sort(all(qr), cmp);

        //rep(i,q) cout<<qr[i].ff.ff<<" "<<qr[i].ff.ss<<" "<<qr[i].ss<<el;

        l=0, r=-1;
        ll cnt[n+1]={0}, z=0;
        ll ans[q];

        rep(i,q){
            while(r<qr[i].ff.ss){
                r++;
                cnt[c[r]]++;
                if(cnt[c[r]]==1) z++;
            }
            while(l>qr[i].ff.ff){
                l--;
                cnt[c[l]]++;
                if(cnt[c[l]]==1) z++;
            }
            while(r>qr[i].ff.ss){
                cnt[c[r]]--;
                if(cnt[c[r]]==0) z--;
                r--;
            }
            while(l<qr[i].ff.ff){
                cnt[c[l]]--;
                if(cnt[c[l]]==0) z--;
                l++;
            }
            ans[qr[i].ss]=z;
        }
        rep(i,q) cout<<ans[i]<<el;



    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, M, D, tmp=0;
vector<ll> A;

signed main(){
    cin >> N >> M >> D;
    double ans;
    if(D==0) {
        ans = ((double)M-1.0)/(double)N;
    }
    else {
        ans = 2.0*((double)M-1.0)*(1.0-(double)D/(double)N)/(double)N;
    }
    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}

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

#pragma comment(linker, "/STACK:102400000,102400000")
#define __m int mid=(l+r)>>1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1 
template<class T>
inline bool rd(T &num) {
    char in;
    bool IsN = false;
    while(in = getchar(), in != '-' && (in < '0' || in > '9'))if(in == EOF)return false;
    in == '-' ? (IsN = true, num = 0) : num = in - '0';
    while(in = getchar(), in >= '0' && in <= '9')num = num * 10 + in - '0';
    return IsN ? num = -num : num, true;
}

#define rep(i,a,b) for(register int i = (a); i< (b); i++)
#define per(i,a,b) for(register int i = (a); i> (b); i--)
#define clr(a) memset(a,0,sizeof(a));
#define inf(a) memset(a,0x3f,sizeof(a));
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define rd2(a,b) rd(a)&&rd(b)
#define rd3(a,b,c) rd(a)&&rd(b)&&rd(c)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

string nico;
#ifdef LOCAL
#define bug(x) cout<<#x<<" : "<<x<<endl
#define infile(x) freopen(x,"r",stdin)
#define outfile(x) freopen(x,"w",stdout)
#else
#define bug(x)
#define infile(x)
#define outfile(x)
#endif

const int maxn = 1e5 + 7;
const int inf  = 0x3f3f3f3f;
const LL linf  = (LL)inf << 32 | inf;
const int mod  = 1e9 + 7;

int n,m;
vector<int>road[maxn];
set<int>edge[maxn];
set<int>::iterator p;
set<int>ans;
int tot=0;
void dfs(int u,int f){
	rep(i,0,road[u].size()){
		int v=road[u][i];
		if(v==f)
			continue;
		dfs(v,u);
		if(edge[v].size()>edge[u].size())
			swap(edge[u],edge[v]);
		for(p=edge[v].begin();p!=edge[v].end();p++){
			if(edge[u].find(*p)!=edge[u].end()){
				ans.insert(u);
				break;
			} else {
				edge[u].insert(*p);
			}
		}
	}
	if(ans.count(u)){
		edge[u].clear();
	}
}
int main(){
	IO;
	cin>>n>>m;
	rep(i,1,n+1)
		road[i].pb(i+1);
	rep(i,1,m+1){
		int a,b;
		cin>>a>>b;
        if(a+1 == b){
            ans.insert(a+1);
            continue;
        }
		edge[a+1].insert(i);
		edge[b].insert(i);
	}
	dfs(1,0);
	cout<<ans.size()<<endl;
    return 0;
}


Measured memory_bytes: 26624
N, M = map(int, input().split())

inList = list([])

for indx in range(M):
    inList.append(list(map(int, input().split())))

flag = 0

for indx in range(M):
    if (((N > 1) and (inList[indx][0] == 1) and (inList[indx][1] == 0)) or
        ((inList[indx][0] > N))):
        flag = -1
    
    for inside_indx in range(indx, M):
        if ((inList[indx][0] == inList[inside_indx][0]) and (inList[indx][1] != inList[inside_indx][1])):
            flag = -1

if flag == -1:
    print(-1)
elif ((flag != -1) and (N == 1) and (M == 0)):
    print("0")
else:
    mystr = "1" + ("0" * (N-1))
    mystr = list(mystr)

    for indx in range(M):
        mystr[(inList[indx][0] - 1)] = str(inList[indx][1])
    
    print("".join(mystr))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int a,b;
    cin>>a>>b;
    cout<<6-a-b;
}

Measured memory_bytes: 3608
n,k,s=map(int,input().split())
ans=[]
for i in range(k):
  ans.append(s)
if s<10**9:
  for i in range(n-k):
    ans.append(s+1)
else:
  for i in range(n-k):
    ans.append(s-1)
print(*ans)

Measured memory_bytes: 9708
/*
AizuOnline A1124
Title When Can We Meet?
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int N,Q,M,D;
char date_table[100];
//
main()
{
  int i,j,maxmem,maxdat;

  while(EOF!=scanf("%d %d ",&N,&Q) && (N||Q))
    {
      memset(date_table,0,sizeof(date_table));
      for(i=0;i<N;i++)
	{
	  scanf("%d",&M);
	  //printf("M:%d\n",M);
	  for(j=0;j<M;j++)
	    {
	      scanf("%d ",&D);
	      date_table[D]++;
	    }
	}
      maxmem=0;maxdat=0;
      for(i=1;i<=sizeof(date_table);i++)
	if(date_table[i]>=Q && date_table[i]>maxmem)
	  {
	    maxdat=i;
	    maxmem=date_table[i];	 
	  }
      if(maxdat>0)
	printf("%d\n",maxdat);
      else
	printf("0\n");
    NEXT:
      ;
    }
return(0);
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	map<int, bool> m;
	for (int i = 0; i < N; i++) m[A[i]] = true;
	int ans = m.size();
	if (ans % 2 == 0) ans--;
	cout << ans << endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define int long long
map<string,map<string,int> > ma;
signed main(){
  int n;
  string s;
  cin>>n>>s;
  string s2;
  for(int i=0;i<n;i++)s2+=s[i+n];
  for(int i=0;i<(1<<n);i++){
    string t1,t2;
    for(int j=0;j<n;j++){
      if(i>>j&1)t1+=s2[j];
      else t2+=s2[j];
    }
    reverse(t1.begin(),t1.end());
    reverse(t2.begin(),t2.end());
    ma[t1][t2]++;
  }
  int ans=0;

  for(int i=0;i<(1<<n);i++){
    string t1,t2;
    for(int j=0;j<n;j++){
      if(i>>j&1)t1+=s[j];
      else t2+=s[j];
    }
    ans+=ma[t1][t2];
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    
    string s; int Q;
    cin >> s >> Q;
    
    list<char> lst;
    for (int i = 0; i < s.size(); ++i) {
        lst.push_back(s[i]);
    }
    
    bool front = true;
    for (int i = 0; i < Q; ++i) {
        int t; cin >> t;
        if (t == 2) {
            int f; char c;
            cin >> f >> c;
            if (f == 1) {
                if (front) lst.push_front(c);
                else lst.push_back(c);
            } else {
                if (front) lst.push_back(c);
                else lst.push_front(c);
            }
        }  else {
            front = not front;
        }     
    } 
    string ans;
    if (not front) lst.reverse();
    for (auto it = lst.begin(); it != lst.end(); ++it) {
        ans += *it;
    }
    cout << ans << endl;
}


Measured memory_bytes: 10452
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int64_t k;
  cin>>n>>k;
  int p=1000000007;
  vector<int> b;
  while(k>1){
    b.push_back(k%2);
    k/=2;
  }
  reverse(b.begin(),b.end());
  vector<vector<map<int64_t,int64_t>>> dp(n,vector<map<int64_t,int64_t>>(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>dp[i][j][1];
  for(int d:b){
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        for(int x=0;x<n;x++)
          dp[i][j][k*2]=(dp[i][j][k*2]+dp[i][x][k]*dp[x][j][k])%p;
    k*=2;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        for(int x=0;x<n;x++)
          dp[i][j][k+d]=(dp[i][j][k+d]+dp[i][x][k]*dp[x][j][d])%p;
    k+=d;
  }
  int64_t s=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      s=(s+dp[i][j][k])%p;
  cout<<s<<endl;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int cnt = 0;
    while(a>0 && c>0){
        if(!(cnt%2)) c -= b;
        else a -= d;
        ++cnt;
    }

    if(cnt%2) cout << "Yes\n";
    else cout << "No\n";

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;

int Minus(int a)
{
	return 2 - a;
}

int Mul(int a,int b)
{
	if(a == 0 || b == 0)
		return 0;
	if(a == 1 || b == 1)
		return 1;
	return 2;
}

int Add(int a,int b)
{
	if(a == 2 || b == 2)
		return 2;
	if(a == 1 || b == 1)
		return 1;
	return 0;
}

int p,q,r;

int GetNum(char c)
{
	if(c == 'P') return p;
	else if(c == 'Q') return q;
	else return r;
}

int calc(vector<char>& num);

int GetArg(vector<char>& num){
	char c = num.back(); num.pop_back();
	if(c == '-' || c == '+' || c == '*'){
		num.push_back(c);
		return calc(num);
	} else if(c == 'P' || c == 'Q' || c == 'R')
		return GetNum(c);
	else return c - '0';
}

int calc(vector<char>& num)
{
	char c = num.back(); num.pop_back();
	switch(c){
		case '-':
			return Minus(GetArg(num));
		case '*':
			return Mul(GetArg(num),GetArg(num));
		case '+':
			return Add(GetArg(num),GetArg(num));
		default:
			num.push_back(c);
			return GetArg(num);
	}
}

void solve(string& str)
{
	vector<char>ope,num; //ZqAlpX^bN
	for(unsigned int i = 0; i < str.size(); i++){
		char c = str[i];
		switch(c){
			case '(':
				ope.push_back(c);
				break;
			case ')':
				while(ope.back() != '('){
					num.push_back(ope.back()); ope.pop_back();
				}
				ope.pop_back(); //')'àí
				break;
			case '-':
				ope.push_back(c);
				break;
			case '*':
			case '+':
				while(!ope.empty() && ope.back() != '('){
					num.push_back(ope.back()); ope.pop_back();
				}
				ope.push_back(c);
				break;
			default:
				num.push_back(c);
		}
	}

	while(!ope.empty()){
		num.push_back(ope.back()); ope.pop_back();
	}
	
	int count = 0;
	for(p = 0; p < 3; p++)
		for(q = 0; q < 3; q++)
			for(r = 0; r < 3; r++){
				vector<char> tmp(num.begin(),num.end()); //Rs[
				if(calc(tmp) == 2)
					count++;
			}

	cout << count << endl;
}


int main()
{
	string str;
	while(cin >> str,str[0] != '.'){
		solve(str);
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
#include <utility>

constexpr long long MOD = 1000000007;
std::vector<int> edges[100000];

std::pair<long long, long long> dfs(int index, int prev = -1)
{
  long long a = 1;
  long long b = 1;
  for (auto e : edges[index])
  {
    if (e == prev) continue;
    auto r = dfs(e, index);
    a = a * r.first % MOD;
    b = b * r.second % MOD;
  }
  return std::make_pair((a + b) % MOD, a);
}

int main()
{
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    edges[a].emplace_back(b);
    edges[b].emplace_back(a);
  }
  
  printf("%lld\n", dfs(0).first);
  return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

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

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a){
	
	if(a[index]>key){
		return true;
	}
	
	return false;
}

ll bin_search(ll key, vector<ll> &a){
	
	ll l=-1;
	ll r=a.size();

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}

const ll MOD=1000000007;

void solve(){
	
	ll n;
	cin>>n;

	vector<string> s(n);
	for(ll i=0;i<n;i++){
		cin>>s[i];
	}

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

	ll ans=0;
	for(ll i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			ans++;
		}
	}
	ans++;

	cout<<ans<<endl;
}


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


Measured memory_bytes: 9604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std ;

int m , d , ans ;

int main() {
	scanf("%d%d", &m , &d );
	for( int i = 1 ; i <= m ; ++ i ) {
		for( int j = 22 ; j <= d ; ++ j ) {
			int a = j%10 , b = j/10%10 ;
			if( a < 2 || b < 2 )
				continue ;
			if( a*b == i )
				ans ++ ;
		}
	}
	printf("%d", ans );
}

Measured memory_bytes: 256
n, m = map(int, input().split())
cards = [list(map(int, input().split())) for _ in range(m)]
cards = sorted(cards, key=lambda x: x[0])[::-1]
cost = 0
for card in cards[:-1]:
    if card[0] < n:
        cost += n - card[0]

print(cost)


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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

int n;

void dfs(string s, char c){
    if(s.size()==n){
        cout << s << endl;
        return;
    }

    for(char i='a'; i<=c; i++){
        dfs(s+i, (i==c) ? (c+1) : c);
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cin>>n;
    dfs("", 'a');
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl

const int MAXV = 100005;
int P[MAXV];
int Find(int A) {
  if(P[A] < 0) return A;
  return Find(P[A]);
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }

  reverse(all(a));
  reverse(all(b));
  rep(j, n) P[j] = -1;

  vector<ll> ans(m);
  ans[0] = (ll)n * (n - 1) / 2;
  rep(i, m - 1) {
    ans[i + 1] = ans[i];
    int pa = Find(a[i]), pb = Find(b[i]);
    if(pa != pb) {
      ans[i + 1] -= (ll)P[pa] * P[pb];
      if(P[pa] > P[pb]) swap(pa, pb);
      P[pa] += P[pb];
      P[pb] = pa;
    }
  }

  reverse(all(ans));
  rep(i, m) printf("%lld\n", ans[i]);
  return 0;
}


Measured memory_bytes: 3328
while True:
    n, x = map(int, input().split())
    count = 0
    if n == x == 0:
        break
    else:
        for i in range(1, n+1):
            for j in range(i+1, n+1):
                for k in range(j+1, n+1):
                    
                    if i+j+k == x:
                        count += 1
        print(count)



Measured memory_bytes: 5592
import heapq

n,m=map(int,input().split())
A=[int(i)*(-1) for i in input().split()]
heapq.heapify(A)

for i in range(m):
  M=heapq.heappop(A)
  heapq.heappush(A,-((-M)//2))
  
ans=-sum(A)
print(ans)


Measured memory_bytes: 14180
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
static const int giga = pow(10,9);

int main(void){
  int n;
  cin >> n;
  int x = 800*n;
  int y = (n/15)*200;
  cout << x-y << endl;

  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m;
    cin>>n>>m;
    ll dist[n+1];
    ll a[m],b[m],c[m];
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        c[i]=-c[i];
    }
    for(int i=1;i<=n;i++){
        dist[i]=inf;
    }
    dist[1]=0;

    for(int t=0;t<n-1;t++){
        for(int i=0;i<m;i++){
            if(dist[a[i]]==inf)
                continue;
            if(dist[b[i]]>dist[a[i]]+c[i]){
                dist[b[i]]=dist[a[i]]+c[i];
            }
        }
    }

    ll ans=dist[n];

    bool negative[n+1];
    for(int i=1;i<=n;i++){
        negative[i]=false;
    }

   
        for(int i=0;i<m;i++){
            if(dist[a[i]]==inf)
                continue;
            if(dist[b[i]]>dist[a[i]]+c[i]){
                dist[b[i]]=dist[a[i]]+c[i];
                negative[b[i]]=true;
            }
            if(negative[a[i]]==true)
                negative[b[i]]=true;
        }
    

    if(negative[n])
        cout<<"inf"<<endl;
    else
        cout<<-ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;

vector<Pll> ans;

void solve(ll x, ll y, ll k) {
    ll xy = x+y;

    if(xy % k == 0) {
        ll xx = 0;
        for(;xx<=x-k;xx+=k) ans.emplace_back(xx+k, 0);
        ll yy = 0;
        if(xx != x) {
            ans.emplace_back(x, k-(x-xx));
            yy += k-(x-xx);
        }
        for(;yy<=y-k;yy+=k) ans.emplace_back(x, yy+k);
        return;
    }

    if(xy < k) {
        if(k % 2 == 1 && xy % 2 == 1) {
            ans.emplace_back(x, -(k-x));
            ans.emplace_back(x+(k+x-y)/2, -(k-x)+(k-x+y)/2);
            ans.emplace_back(x, y);
        } else {
            ans.emplace_back(k-(2*k-x-y)/2, -(2*k-x-y)/2);
            ans.emplace_back(x, y);
        }
        return;
    }

    // xy > k
    ans.emplace_back(0, 0);
    ll n = (xy+k-1)/k;
    if(((k * n) % 2) ^ (xy % 2)) ++n;
    // (k*n-x-y)/2 + x = (k*n+x-y)/2 >= (2k+x-y)/2 >= k は x >= y という条件のもとで成り立つ
    // (これが成り立ってないと解説 pdf のタイプ A が使えない)
    ll d = (k*n-x-y) / 2, dd = 0;
    for(;dd<=d-k;dd+=k) ans.emplace_back(0, ans.back().second-k);
    // k-(k*n-x-y)/2 <= x は，
    // k-(k*n-x-y)/2 = ((2-n)k+x+y)/2 <= (x+y)/2 および x/2 >= y/2 より成り立つ
    // (これが成り立っていないと解説 pdf のタイプ A が使えない)
    ll xx = 0;
    if(dd != d) {
        ans.emplace_back(ans.back().first + k-(d-dd), ans.back().second - (d-dd));
        xx += k-(d-dd);
    }
    for(;xx<=x-k;xx+=k) ans.emplace_back(ans.back().first + k, ans.back().second);
    ll yy = 0;
    if(xx != x) {
        ans.emplace_back(ans.back().first + x-xx, ans.back().second + k-(x-xx));
        yy += k-(x-xx);
    }
    for(;yy<y+d;yy+=k) ans.emplace_back(ans.back().first, ans.back().second + k);

    ans.erase(ans.begin());
    return;
}

int main() {
    ll  K, X, Y;
    cin >> K >> X >> Y;

    ll abs_X = abs(X);
    ll abs_Y = abs(Y);

    if(K % 2 == 0 && (abs_X+abs_Y) % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    if(abs_X < abs_Y) {
        solve(abs_Y, abs_X, K);
        cout << ans.size() << endl;
        for(Pll p: ans) {
            if(Y < 0) p.first *= -1;
            if(X < 0) p.second *= -1;
            cout << p.second << " " << p.first << endl;
        }
    } else {
        solve(abs_X, abs_Y, K);
        cout << ans.size() << endl;
        for(Pll p: ans) {
            if(X < 0) p.first *= -1;
            if(Y < 0) p.second *= -1;
            cout << p.first << " " << p.second << endl;
        }
    }
}

Measured memory_bytes: 6512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// 最大公約数
ll GCD(ll a, ll b)
{
    if (a < 0)
        a = -a;
    if (b < 0)
        b = -b;
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

// 最小公倍数
ll LCM(ll a, ll b)
{
    ll g = GCD(a, b);
    return a / g * b;
}

int main()
{
    string in;
    cin >> in;
    int ret = 0;
    if (in[0] != 'C')
    {
        ret++;
    }
    if (in[1] != 'O')
    {
        ret++;
    }
    if (in[2] != 'D')
    {
        ret++;
    }
    if (in[3] != 'E')
    {
        ret++;
    }
    if (in[4] != 'F')
    {
        ret++;
    }
    if (in[5] != 'E')
    {
        ret++;
    }
    if (in[6] != 'S')
    {
        ret++;
    }
    if (in[7] != 'T')
    {
        ret++;
    }
    if (in[8] != 'I')
    {
        ret++;
    }
    if (in[9] != 'V')
    {
        ret++;
    }
    if (in[10] != 'A')
    {
        ret++;
    }
    if (in[11] != 'L')
    {
        ret++;
    }
    if (in[12] != '2')
    {
        ret++;
    }
    if (in[13] != '0')
    {
        ret++;
    }
    if (in[14] != '1')
    {
        ret++;
    }
    if (in[15] != '6')
    {
        ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"Yes":"No")
#define binom2(n) ((n)*(n-1)/2)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

char dir[]={'N','W','S','E'};

int main() {
  string s; cin >>s;
  int n=s.size();
  int d[]={0,0,0,0};
  rep(i,n) rep(j,4) if(s[i]==dir[j]) d[j]|=1;
  yn(!((d[0]^d[2]) or (d[1]^d[3])));
}


Measured memory_bytes: 3592
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int X = in.nextInt();
            int[] L = new int[N + 1];
            for (int i = 0; i < N; i++) {
                L[i] = in.nextInt();
            }

            int current = 0;
            int count = 0;
            for (int n : L) {
                if (current <= X) {
                    count++;
                }
                current += n;
            }
            out.println(count);
        }

    }
}



Measured memory_bytes: 23764
while True:
    try: ipt = input()
    except: break

    c = list(map(float, ipt.split(',')))
    x, y = c[::2], c[1::2]

    A_1 = (x[3]-x[1])*(y[2]-y[1]) - (y[3]-y[1])*(x[2]-x[1])
    A_2 = (x[0]-x[1])*(y[2]-y[1]) - (y[0]-y[1])*(x[2]-x[1])
    A = A_1 / A_2

    B_1 = (-(x[3]-x[1])*(y[0]-y[1])) + (y[3]-y[1])*(x[0]-x[1])
    B_2 = (x[0]-x[1])*(y[2]-y[1]) - (y[0]-y[1])*(x[2]-x[1])
    B = B_1 / B_2
    
    if A >= 0 and B >= 0 and A+B >= 1:
        print('YES')
    else:
        print('NO')



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for( int i=a; i<b; i++)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<pii>vpi;

vector<vector<double>> dp(3000,vector<double>(3000,-1));

double sol(vector<double> &P,ll n,ll heads){
    if(n == 0){
        if(heads==0){
            return 1;
        }
        else{
            return 0;
        }
    }
    if(heads < 0){
        return 0;
    }
    if(dp[n][heads]<0){
        return dp[n][heads] = P[n-1]*sol(P,n-1,heads-1)+(1-P[n-1])*sol(P,n-1,heads);
    }
    return dp[n][heads];
}
void solve(){
    ll n;
    cin>>n;
    vector<double> P(n);
    for(ll i =0;i<n;i++){
        cin>>P[i];
    }
    double ans=0;
    ll tails;
    for(ll heads = 0; heads<=n;heads++){
        tails = n-heads;
        if(heads>tails){
            ans+=sol(P,n,heads);
        }
    }
    printf("%.9lf",ans);
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t;
    t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 74452
#include<stdio.h>
int main(void){
	int i,n;
	int array[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	for(i=n-1;i>=0;i--){
		if(i!=0){
			printf("%d ",array[i]);
		}else {
			printf("%d\n",array[i]);
		}
	}
	
	return 0;
}

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

namespace ConsoleApp61 {
    class Program {
        static void Main(string[] args) {
            int s = int.Parse(Console.ReadLine());

            var ansList = new List<int>();
            ansList.Add(s);

            int cnt = 1;

            while (true) {
                if (s % 2 == 0) {
                    s /= 2;
                } else {
                    s = 3 * s + 1;
                }
                cnt++;

                if (ansList.Contains(s)) {
                    Console.WriteLine(cnt);
                    return;
                }

                ansList.Add(s);

            }


        }
    }
}


Measured memory_bytes: 13148
#include <stdio.h>
#include <string.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
int a[20010];
int l[20010];
int r[20010];
int d[20010];

char s[20010];
int ans[20010],cnt,sum;

int main(){
	scanf("%s",s);
	int n=strlen(s);
	for(int i=0;i<n;i++)a[i+1]=a[i]+(s[i]=='\\'?-1:s[i]=='/');
	l[0]=a[0];
	for(int i=0;i<n;i++)l[i+1]=max(l[i],a[i+1]);
	r[n]=a[n];
	for(int i=n;i>0;i--)r[i-1]=max(r[i],a[i-1]);
	for(int i=0;i<=n;i++)d[i]=min(l[i],r[i])-a[i];
	int temp=0;
	for(int i=0;i<=n;i++){
		if(d[i]==0){
			if(temp!=0){
				ans[cnt++]=temp;
				sum+=temp;
				temp=0;
			}
		}else temp+=d[i];
	}
	printf("%d\n%d%c",sum,cnt,cnt?32:10);
	for(int i=0;i<cnt;i++)printf("%d%c",ans[i],i==cnt-1?10:32);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
 
int N;
int x[10], y[10];
 
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    double ans = sum / (double)Factorial;
    printf("%.12lf\n",ans);
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 384
from collections import deque

def bfs(grid, start, wall, h, w):
    visited = [[False for _ in range(w+2)] for _ in range(h+2)]
    visited[start[0]][start[1]] = True

    queue = deque([])
    queue.append([start[0], start[1], 0])
    dxy = [(1,0), (-1,0), (0,1), (0,-1)]
    cost = 0
    while queue:
        y,x,cnt = queue.popleft()
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            if grid[y_][x_] == wall or visited[y_][x_]:
                continue
            queue.append([y_,x_,cnt+1])
            if cnt+1 > cost:
                cost = cnt+1
            visited[y_][x_] = True
    return cost

h,w = map(int, input().split())
wall = '#'
edges = [wall] * (w+2)
grid = [edges]
for i in range(h):
    s = input()
    grid.append([wall] + list(s) + [wall])
grid.append(edges)


cand = {2:[], 3:[], 4:[]}
dxy = [(1,0), (-1,0), (0,1), (0,-1)]
for y in range(1,h+1):
    for x in range(1,w+1):
        if grid[y][x] == wall:
            continue
        wl = 0
        for dy, dx in dxy:
            y_,x_ = y+dy,x+dx
            if grid[y_][x_] == wall:
                wl += 1
        if wl > 1:
            cand[wl].append((y,x))

ans = 0
starts = []
for i in [4,3,2]:
    if cand[i] != []:
        starts = cand[i]
        break
for start in starts:
    cnt = bfs(grid, start, wall, h, w)
    if cnt > ans:
        ans = cnt
print(ans)


Measured memory_bytes: 41712
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String[] arr = br.readLine().split(" ");
        int N = Integer.parseInt(arr[0]);
        int M = Integer.parseInt(arr[1]);
        List<Integer> list = Arrays.stream(br.readLine().split(" "))
            .map(Integer::parseInt)
            .sorted(Comparator.naturalOrder())
            .collect(Collectors.toList());
        long ans = 0;
        if (N < M) {
            List<Integer> list2 = new ArrayList<>();
            for (int i = 0; i < M - 1; i++) {
                list2.add(list.get(i + 1) - list.get(i));
            }
            list2.sort(Comparator.naturalOrder());
            for (int i = 0; i < M - N; i++) {
                ans += (long)list2.get(i);
            }
        }
        out.println(ans);
        out.close();
    }
}


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

using namespace std;

int n;

bool solve(){
    int i,j;
    string str;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<pair<int,int> > ct;
    ct.push_back(make_pair(a[0],1));
    for(i = 1;i < n;i++){
        if(a[i] == a[i-1]) ct[ct.size()-1].second+=1;
        else ct.push_back(make_pair(a[i],1));
    }
    if(ct.size() == 3 && n%3 == 0){
        if(ct[0].second == ct[1].second && ct[1].second == ct[2].second && (ct[0].first ^ ct[1].first) == ct[2].first) return true;
    }
    if(ct.size() == 2 && n%3 == 0){
        if(ct[0].second*2 == ct[1].second && ct[0].first == 0) return true;
    }
    if(ct.size() == 1 && ct[0].first == 0) return true;
    return false;
}

int main(){
    if(solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1656
#include <iostream>

using namespace std;

int main()
{
    int t;
    cin>>t;
    int x=0;
    char a;
    int M=0;
    while(t--)
    {
        cin>>a;
        if(a=='I')
        {
            x++;
            if(x>M) M=x;
        }
        else if(a=='D')
            x--;
    }
    cout<<M<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string.h>

using namespace std;

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

int main() {

	char S[100], a[] = "AKIHABARA";
	scanf("%s", S);

	int j = 0;
	int ac = 0;
	for (int i = 0; j < 10; j++) {
		if (S[i] != a[j] && a[j] != 'A' && ac == 1) {
			printf("NO\n");
			return 0;
		}
		else if (S[i] == a[j]) {
			i++;
		}
		else if(a[j] == 'A'){
			ac++;
		}
		else {
			printf("NO\n");
			return 0;			
		}
	}

	printf("YES\n");

	return 0;
}

Measured memory_bytes: 128