akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

#define INF 210000000
#define int long long

static long long gcd(long long a, long long b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

static long long lcm(long long a, long long b) { return a * b / gcd(a, b); }

signed main() {
    string s;
    cin >> s;
    if(s.find("a") != string::npos && s.find("b") != string::npos && s.find("c") != string::npos){
        cout << "Yes";
    }else{
        cout << "No";
    }
}



Measured memory_bytes: 256
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>

typedef long long ll;
using namespace std;

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

    long double ans = 0;
    if (N >= K) {
        ans += double(N - K + 1) / double(N);
    }

    int right;

    for (int i = 1; i <= min(K-1, N); i++) {
        double tmp = 1.0 / double(N);
        double l = log2(double(K)/double(i));
        if (l - int(l) > 0) l = int(l) + 1;
        else l = int(l);
        tmp /= pow(2, l);

        ans += tmp;
    }

    cout << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
S=input()
l=len(S)
s1=S[:l//2]
if l%2==0:
    s2=S[l//2::]
else:
    s2=S[l//2+1::]
s2=s2[::-1]
sum=0
for i in range(len(s1)):
    if s1[i]!=s2[i]:
        sum+=1
print(sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt=0

for i in range(N):
    for j in range(N):
        for k in range(N):
            a=[]
            if A[i]!=A[j] and A[i]!=A[k] and A[j]!=A[k]:
                if i<j and j<k:
                    a.append(A[i])
                    a.append(A[j])
                    a.append(A[k])
                    a.sort()
                    
                    if a[1]-a[0]<a[2] and a[2]<a[0]+a[1]:
                        cnt+=1
print(cnt)


Measured memory_bytes: 9148
#include <stdio.h>

int main(void)
{
    int n, i;

    for (i = 1; i <= 10000; i++)
    {
        scanf("%d", &n);
        if (n == 0)
        {
            break;
        }
        printf("Case %d: %d\n", i, n);
    }

    return 0;
}


Measured memory_bytes: 2740
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (2 * B >= A)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << A - 2 * B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,count_1=0,count_2=0;
  for(i=0;i<s.size();i++){
    if(s.at(i)=='1'){
      count_2++;
    }else{
      count_1++;
    }
  }
  cout << 2*min(count_1,count_2);
}


Measured memory_bytes: 512
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma -(big+1)
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define mt make_tuple
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define inv2 500000004
#define MOD 998244353 
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{

	string s;

	cin>>s;

	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes\n";
	else
		cout<<"No\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

vector<int> sieve(int n) {
  vector<int> p(n);
  REP(i,2,n) p[i]=i;
  for(int i=2; i*i<n; i++) {
    if(p[i]) {
      for(int j=i*i; j<n; j+=i) p[j]=0;
    }
  }
  p.erase(remove(all(p),0),p.end());
  return p;
}

void Main() {
  vector<int> p=sieve(33000);
  int n;
  while(R n && n) {
    int ans=0;
    rep(i,p.size()) {
      REP(j,i,p.size()) {
        if(p[i]+p[j]>n) break;
        if(n==p[i]+p[j]) ans++;
      }
    }
    pr(ans);
  }
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 1268
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int X = int.Parse(input[1]);
            int[] L = new int[N];
            string[] input2 = Console.ReadLine().Split(' ');
            for (int i = 0; i < N; i++)
            {
                L[i] = int.Parse(input2[i]);
            }
            int count = 1;
            int dist = 0;
            for (int i = 0; i < N; i++)
            {
                dist += L[i];
                if (dist <= X) count++;
                else break;
            }
            Console.WriteLine(count.ToString());
        }
    }
}


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

int main(){
  vector<int> d = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k; cin >> k;
  
  cout << d.at(k-1) << endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>   
using namespace std;
 
int main(){
	int i;
	cin >> i;
	int a[i][3],b = 0;
	while(b < i){
		cin >> a[b][0] >> a[b][1] >> a[b][2];
		b++;
	}
	b = 0;
	string j[i];
	while(b < i){
		j[b] = "NO";
		if(a[b][0]*a[b][0] + a[b][1]*a[b][1] == a[b][2]*a[b][2]){
			j[b] = "YES";
		}
		if(a[b][0]*a[b][0] + a[b][2]*a[b][2] == a[b][1]*a[b][1]){
			j[b] = "YES";
		}		
		if(a[b][1]*a[b][1] + a[b][2]*a[b][2] == a[b][0]*a[b][0]){
			j[b] = "YES";
		}
	cout << j[b] << endl;	
	b++;	
	}	


}

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

int main(){
	long long T1,T2,A1,A2,B1,B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	
	if((T1*A1+T2*A2)==(T1*B1+T2*B2)){
		cout << "infinity" << endl;
		return 0;
	}
	
	if((T1*A1+T2*A2)<(T1*B1+T2*B2)){
		swap(A1,B1);
		swap(A2,B2);
	}
	
	long long diff1=T1*(B1-A1);
	long long diff2=T2*(A2-B2);
	long long diff=diff2-diff1;
	
	if(diff1<0){
		cout << "0" << endl;
		return 0;
	}
	
	long long ans=diff1/diff*2;
	if(diff1%diff>0)ans++;
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

template<typename T>
struct segtree {
	ll n;
	vector<T> value;

	segtree<T>(vector<T> leaves): n(sz(leaves)) {
		value.resize(2*n);
		copy(all(leaves),begin(value)+n);
		FORD(i,1,n) value[i] = value[2*i] + value[2*i+1];
	}
	
	void update(ll i, T v) {
		i += n;
		value[i] = v;
		for (i /= 2; i; i /= 2) value[i] = value[2*i] + value[2*i+1];
	}
	
	T query(ll i, ll j) {
		i += n, j += n;
		T resl, resr;
		for (; i < j; i /= 2, j /= 2) {
			if (i & 1) resl = resl + value[i++];
			if (j & 1) resr = value[--j] + resr;
		}
		return resl + resr;
	}
};

struct node {
	ll x = 0;
	node operator+(node n) { return {x+n.x}; }
};

struct query {
	ll a, b, i;
	bool operator<(const query&q) const { return b > q.b; };
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;
	
	vl a(n);
	FOR(i,0,n) cin >> a[i];

	map<ll,ll> next_occ;
	vl p(n);
	FORD(i,0,n) {
		ll x = a[i];
		p[i] = next_occ.count(x) ? next_occ[x] : n;
		next_occ[x] = i;
	}
	
	vector<query> queries(m);
	FOR(i,0,m) {
		ll a, b;
		cin >> a >> b;
		queries[i] = {a-1,b,i};
	}
	
	vector<pll> b(n);
	FOR(i,0,n) b[i] = {p[i],i};

	sort(all(queries));
	sort(all(b),greater<pll>());
	
	vector<node> leaves(n);
	segtree<node> S(leaves);

	ll i = 0;
	vl res(m);
	for (auto q: queries) {
		for(; i < n; i++) {
			auto [x,j] = b[i];
			if (x < q.b) break;
			S.update(j, {1});
		}
		res[q.i] = S.query(q.a,q.b).x;
	}
	
	FOR(i,0,m) cout << res[i] << '\n';
}



Measured memory_bytes: 78048
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
using ll=int long long;
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main(){
  int n;
  int ret;
  cin>>n;
  int A[MAX_N];
  for(int i=0;i<n-1;i++) cin>>A[i];
  cin>>ret;
  ll dp[101][21];
  dp[1][A[0]]=1;
  for(int i=2;i<n;i++){
    for(int j=0;j<=20;j++){
      if(j+A[i-1]<=20){
        dp[i][j]+=dp[i-1][j+A[i-1]];
      }
      if(j-A[i-1]>=0){
        dp[i][j]+=dp[i-1][j-A[i-1]];
      }
    }
  }
  cout<<dp[n-1][ret]<<endl;
}




Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] x = sc.nextLine().split(" ");

        int ans = 0;
        for (int i = 0; i < x.length; i++) {
            if (x[i].equals("0")) ans = i + 1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35796
n = int(input())
p = [0, 0]
time = 0

for _ in range(n):
    t, x, y = map(int, input().split())
    dist = abs(x-p[0]) + abs(y-p[1])
    if dist > t-time:
        print('No')
        exit()
    else:
        if (t-time)%dist==0:
            time += dist
            p = [x, y]
        else:
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    char s[10];
    scanf("%s",s);
    if(s[0]=='S')
        printf("Cloudy\n");
    else if(s[0]=='C')
        printf("Rainy\n");
    else if(s[0]=='R')
        printf("Sunny\n");
    return 0;
}


Measured memory_bytes: 128
import itertools
import numpy as np
def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))

    x = [sum(a[i:j+1]) for i in range(n) for j in range(i,n)]
    x.sort()
    x = x[::-1]

    MAX = x[0]
    two = 1
    POW = 1
    while(MAX>=two*2):
        two*=2
        POW+=1

#MAXBITソート
    for p in range(POW)[::-1]:
        C = list(filter(lambda y:y>=two,x))
        if len(C)>=k:
            break
        else:
            two//=2

    POW = p+1

    for p in range(POW):
        D = list(filter(lambda x:(x//two)%2==1,C))
        LEN = len(D)
        if LEN>=k:
            C = D[:]
            if LEN==k:break
        two//=2

    ans = C[0]
    for c in C[1:k]:
        ans &= c

    print(ans)

if __name__ == "__main__":
    main()

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

template <class T>
T root(std::vector<T>& p, T x) {
    if (p[x] == x) return x;
    else return p[x] = root(p, p[x]);
}

template <class T>
bool same(std::vector<T>& p, T x, T y) { return root(p, x) == root(p, y); }

template <class T>
void unite(std::vector<T>& p, T x, T y) {
    x = root(p, x);
    y = root(p, y);
    if (x == y) return;
    p[x] = y;
}

int main() {
    long long n, k, l, p, q;
    std::cin >> n >> k >> l;
    std::vector<long long> para(n), parb(n);
    for (int i = 0; i < n; i++) para[i] = i, parb[i] = i;
    for (int i = 0; i < k; i++) {
        std::cin >> p >> q; p--; q--;
        unite(para, p, q);
    }
    for (int i = 0; i < l; i++) {
        std::cin >> p >> q; p--; q--;
        unite(parb, p, q);
    }

    std::vector<std::pair<long long, long long>> v(n);
    std::map<std::pair<long long, long long>, long long> m;
    for (auto i = 0ll; i < n; i++) {
        v[i] = std::make_pair(root(para, i), root(parb, i));
        m[v[i]]++;
    }
    for (auto el : v) std::cout <<  m[el] << " ";
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 18048
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n;
int p[501][501];
int sum[502][502];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			scanf("%d",&p[j][i]);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			sum[j+1][i]=sum[j][i]+p[j][i];
		}
	}
	int res=-1001;
	for(int l=0;l<n;l++){
		for(int r=l+1;r<=n;r++){
			int now=sum[r][0]-sum[l][0];
			res=max(res,now);
			for(int i=1;i<n;i++){
				res=max(res,now+sum[r][i]-sum[l][i]);
				int next=sum[r][i]-sum[r-1][i]+sum[l+1][i]-sum[l][i];
				if(r==l+1)next=sum[r][i]-sum[r-1][i];
				now=max(now+next,sum[r][i]-sum[l][i]);
			}
		}
	}
	printf("%d\n",res);
	return 0;
}

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

int main ()
{
	long long q,h,s,d,n,i,m;
	cin>>q>>h>>s>>d;
	cin>>n;
	m=s;
	if(q*4<m)
		m=4*q;
	if(h*2<m)
		m=2*h;
	if(m*2<=d)
		cout<<n*m<<endl;
	else
	{
		if(n%2==1)
			cout<<m+n/2*d<<endl;
		else
			cout<<n/2*d<<endl;
	}
} 

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];
    if(a == b){
        cout << "Yes" << endl;
        return;
    }
    ll cnt = 0, suma = 0, sumb = 0;
    rep(i, N){
        suma += a[i];
        sumb += b[i];
        if(a[i] < b[i]) cnt += (b[i]-a[i]+1)/2;
    }
    if(sumb <= suma){
        cout << "No" << endl;
        return;
    }
    if(cnt <= (sumb-suma)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

string S;
vector<int> ans;

int main () {
  cin >> S;
  int N = S.size();
  ans.resize(N, 0);

  int i = 0;
  while(i < N) {
    int j = i;
    while(S[j] == 'R') j++;

    while(i < j) {
      if((j - i) % 2 == 0) {
        ans[j]++;
      } else {
        ans[j-1]++;
      }
      i++;
    }

    while(i < N && S[i] == 'L') {
      if((j - i) % 2 == 0) {
        ans[j]++;
      } else {
        ans[j-1]++;
      }
      i++;
    }
  }

  rep(i,N) {
    if(i != 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;

  return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define fr(i, a, b) for (ll i = a; i < b; i++)

int main() {
    ios::sync_with_stdio(false);
    #ifdef CODE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;
    string s;
    cin >> s;
    int red = 0, white = 0;
    fr(i, 0, n) {
        if (s[i] == 'R') red++;
        else white++;
    }
    int ans = 0;
    fr(i, 0, red) {
        if (s[i] == 'W') ans++;
    }
    int temp = 0;
    for (int i = n - 1; i >= n - 1 - white; i--) {
        if (s[i] == 'R') temp++;
    }
    cout << min(ans, temp);

    return 0;
}

Measured memory_bytes: 3776
n,k = map(int,input().split())
a = list(map(int,input().split()))
sun = sum(a)
cd = []
rcd = []
for i in range(1,int(sun**0.5)+1):
  if sun % i == 0:
    cd.append(i)
    rcd.append(sun//i)
rcd.reverse()
if cd[-1] == rcd[0]:
  del cd[-1]
gcd = cd + rcd
gcd.reverse()
count = 0
while True:
  g = gcd[count]
  b = list(map(lambda x: x%g, a))
  moon = sum(b) // g
  b.sort()
  luna = sum(b[:n-moon])
  if luna <= k:
    print(g)
    break
  count += 1

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n, c, k;
int t[100005];

int cmp(const void *x, const void *y);

int main()
{
	scanf("%d %d %d", &n, &c, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &t[i]);
	}
	t[n] = INT_MAX;

	qsort(t, n, sizeof(int), cmp);

	int ans = 0;
	int indx = 0;
	while (indx < n) {
		ans++;
		int tlim = t[indx] + k;
		int cnt = 0;

		while (cnt < c && t[indx] <= tlim) {
			indx++;
			cnt++;
		}
	}

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

	return 0;
}

int cmp(const void *x, const void *y)
{
	if (*(int *)x > *(int *)y) {
		return 1;
	} else if (*(int *)x == *(int *)y) {
		return 0;
	} else {
		return -1;
	}
}


Measured memory_bytes: 892
#include <stdio.h>

#define M 100

void insertion_Sort(int [], int);
void Print(int [], int);

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

//順番を入れ替える、入れ替えたら、print関数で出力
void insertion_Sort(int A[],int N)
{
  int v;
  int i,j;

    
  for(i=1;i<N;i++)
    {
      v=A[i];
      //insert A[i] into the sorted sequence A[0,...,j-1]
      j=i-1;
      while(j >= 0 && A[j] >v)
        {
	  A[j+1]=A[j];
	  j--;
        }
      A[j+1]=v;
      Print(A,N);
    }
}

//出力
void Print(int A[],int N){
  int i;

  for(i=0;i<N;i++)
    {
      printf("%d",A[i]);
      if(i!=N-1) printf(" ");
    }
  printf("\n");
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int64_t i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    vector<int> ans;
    bool escape=false;
    rep(h,1,3501){
        rep(n,h,3501){
            int64_t v1=h*n*N, v2=4*h*n-n*N-h*N;
            if(v2>0 && v1%v2==0){
                int64_t w=v1/v2;
                ans.push_back(h);
                ans.push_back(n);
                ans.push_back(w);
                escape=true;
                break;
            }
                
            if(escape) break;
        }
        if(escape) break;
    }

    for(auto a:ans) cout<<a<<" ";
    cout<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
int id[100000];
int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int A;
		cin >> A;
		id[A - 1] = i;
	}
	for (int i = 0; i < N; i++) {
		cout << id[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
#define per(i,n) for ((i)=n;(i)>=(1);(i)--)
using namespace std;


int n;
int i,j,a[100005],ans;
int sgn(int x){
	return x/abs(x);
}
int main(){
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
		if(i>1&&a[i]==a[i-1]){
			i--;n--;
		} 
	}
	for(i=1;i<=n;i=j+1){
		j=i+1;ans++;
		while(j<n&&sgn(a[j+1]-a[j])==sgn(a[i+1]-a[i])) j++;
	}
	cout<<ans<<endl;
	return 0;
}

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

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

  vector<int> a1(n);
  vector<int> a2(n);
  int sum1 = 0;
  int sum2 = 0;

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

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

  int max = 0;
  for(int i = 0; i < n; i++){

    int sum = 0;
    for(int j = 0; j < n; j++){
      if(j == i) sum += (a1[j] + a2[j]);
      else if(j < i) sum += a1[j];
      else if(j > i) sum += a2[j];
    }

    if(sum > max) max = sum;
  }

  cout << max << endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 2000003;
const int MOD = 1000000007;

//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

        signed main() {
    cout<<fixed<<setprecision(10);
        int n;
        cin>>n;
        int a[n],b[n];
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<n;i++)cin>>b[i];
        for(int i=1;i<n;i++)a[i]=a[i-1]+a[i];
        for(int i=n-2;i>=0;i--)b[i]=b[i+1]+b[i];
        int ans=a[0]+b[0];
        for(int i=1;i<n;i++)ans=max(ans,a[i]+b[i]);
        cout<<ans;
       

        }


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

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
	long long N;
	char S[200] = {0};
	char A[200] = {0};

	cin >> N;

	long long n = N;
	int i=0;
	while(true){
		if(n%2==0){
			S[i] = '0';
		}
		else{
			S[i] = '1';
			n = n -1;
		}
		n = n/(-2);
		if(n==0) break;
		i++;
	}

	int len = strlen(S);
	for(int i=0; i<len; i++){
		A[i] = S[len-1-i];
	}
	printf("%s\n", A);
	return 0;

}

Measured memory_bytes: 256
N, M = map(int, input().split())
li = [[] for _ in range(N+1)]
for i in range(M):
    p, y = map(int, input().split())
    li[p].append([i, y])
ans = [0 for _ in range(M)]
for i in range(1, N+1):
    iy = li[i]
    iy.sort(key=lambda x: x[1])
    for j in range(len(iy)):
        ans[iy[j][0]] = (i, j+1)
for shi in ans:
    print('{:06d}{:06d}'.format(shi[0], shi[1]))

Measured memory_bytes: 42292
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


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

    rep(i,0,sz(s)){
	if(i&1){
	    if(s[i] == 'R'){
		No;
		ret 0;
	    }
	}else{
	    if(s[i] == 'L'){
		No;
		ret 0;
	    }
	}
    }
    Yes;
    return  0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 500000
#define INFTY 2000000000

int L[N / 2 + 2];
int R[N / 2 + 2];
int count = 0;

void merge(int*,int,int,int,int);
void mergeSort(int*,int,int,int);


int main() {
  int S[N];
  int i,x;

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

  mergeSort(S,x,0,x);

  for(i = 0; i < x; i++) {
    printf("%d",S[i]);
    if(i != x - 1) {
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}

void merge(int A[],int n,int left,int mid,int right) {
  int i,j,k,n1,n2;
  
  n1 = mid - left;
  n2 = right - mid;

  for( i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for( i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++) {
    count++;
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i =  i + 1;
    }else{ 
      A[k] = R[j];
      j = j + 1;
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left + 1 < right) {
    mid = (left + right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left, mid, right);
  }
}



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

int main() {

  int N;
  cin >> N;

  map<int, int> m;
  int a;

  for(int i = 2; i <= N; i++){
    cin >> a;
    m[a]++;
  }

  for (int i = 1; i <= N; i++){
    if(m.find(i) != m.end()){
      cout << m[i] << endl;
    }else{
      cout << 0 << endl;
    }
  }
}

Measured memory_bytes: 12796
#include <iostream>

int main()
{
	int n;
	long long a[] = { 2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123, 199, 322, 521, 843, 1364, 2207, 3571, 5778, 9349, 15127, 24476, 39603, 64079, 103682, 167761, 271443, 439204, 710647, 1149851, 1860498, 3010349, 4870847, 7881196, 12752043, 20633239, 33385282, 54018521, 87403803, 141422324, 228826127, 370248451, 599074578, 969323029, 1568397607, 2537720636, 4106118243, 6643838879, 10749957122, 17393796001, 28143753123, 45537549124, 73681302247, 119218851371, 192900153618, 312119004989, 505019158607, 817138163596, 1322157322203, 2139295485799, 3461452808002, 5600748293801, 9062201101803, 14662949395604, 23725150497407, 38388099893011, 62113250390418, 100501350283429, 162614600673847, 263115950957276, 425730551631123, 688846502588399, 1114577054219522, 1803423556807921, 2918000611027443, 4721424167835364, 7639424778862807, 12360848946698171, 20000273725560978, 32361122672259149, 52361396397820127, 84722519070079276, 137083915467899403, 221806434537978679, 358890350005878082, 580696784543856761, 939587134549734843, 1520283919093591604, 2459871053643326447 };

	std::cin >> n;
	std::cout << a[n];
	return 0;
}

Measured memory_bytes: 256
def s2n(dice):
    aft_dice = [dice[1],dice[5],dice[2],dice[3],dice[0],dice[4]]
    return aft_dice

def w2e(dice):
    aft_dice = [dice[3],dice[1],dice[0],dice[5],dice[4],dice[2]]
    return aft_dice

def rspin(dice):
    aft_dice = [dice[0],dice[2],dice[4],dice[1],dice[3],dice[5]]
    return aft_dice

def isd(dice1, dice2):
    if dice1 == dice2:
        return 1
    return 0

dice1 = map(int, raw_input().split())
dice2 = map(int, raw_input().split())

flag = 0

for i in xrange(4):
    for j in xrange(4):
        flag += isd(dice1, dice2);
        dice2 = rspin(dice2)
    dice2 = s2n(dice2)

dice2 = w2e(dice2)
for i in xrange(4):
    flag += isd(dice1, dice2)
    dice2 = rspin(dice2)

dice2 = w2e(dice2)
dice2 = w2e(dice2)
for i in xrange(4):
    flag += isd(dice1, dice2)
    dice2 = rspin(dice2)

if flag == 0:
    print "No"
else:
    print "Yes"

Measured memory_bytes: 6460
#include <iostream>
#include <map>

using namespace std;

int main() {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        map<char, char> conversion;
        char a, b;
        for (int i=0; i<n; ++i) {
            cin >> a >> b;
            conversion[a] = b;
        }

        int m;
        cin >> m;

        string ans = "";
        char c;
        for (int i=0; i<m; ++i) {
            cin >> c;
            if (conversion.count(c)) {
                ans += conversion[c];
            } else {
                ans += c;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<string, vector<int> > P;

void solve()
{
	vector<P> Vec;
	string str;
	while(cin >> str)
	{
		int n;
		cin >> n;
		bool existFlag = false;
		for(int i = 0; i < Vec.size(); ++i)
		{
			if(Vec[i].first == str)
			{
				Vec[i].second.push_back(n);
				existFlag = true;
				break;
			}
		}
		if(!existFlag)
		{
			vector<int> V;
			V.push_back(n);
			Vec.push_back(make_pair(str, V));
		}
	}
	sort(Vec.begin(), Vec.end());
	for(int i = 0; i < Vec.size(); ++i)
	{
		cout << Vec[i].first << endl;
		sort(Vec[i].second.begin(), Vec[i].second.end());
		for(int j = 0; j < Vec[i].second.size() - 1; ++j)
		{
			cout << Vec[i].second[j] << " ";
		}
		cout << Vec[i].second[Vec[i].second.size() - 1] << endl;
	}
}

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

Measured memory_bytes: 1252
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

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

}

Measured memory_bytes: 1156
while 1:
    W, H = list(map(int,input().split()))
    if W == 0:break

    C = [list(map(int, input().split())) for i in range(H) ]
    
    def work(x,y):
        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
        ay = [-1, -1, -1, 0, 0, 1, 1, 1]

        if C[y][x] != 1:return False
        stack = [(x,y)]

        while len(stack) > 0:
            s = stack.pop(-1)
            C[s[1]][s[0]] = -1 #mark

            for _x in [s[0] + _x for _x in ax]:
                for _y in [s[1] + _y for _y in ay]:
                    if 0 <= _x < W and 0 <= _y < H and C[_y][_x] == 1:
                        stack.append((_x, _y))
        return True
#    def work(x,y):
#        ax = [-1, 0, 1, -1, 1, -1, 0, 1]
#        ay = [-1, -1, -1, 0, 0, 1, 1, 1]
#
#        if C[y][x] != 1:return False
#        C[y][x] = -1 #mark
#
#        for _ax in ax:
#            for _ay in ay:
#                if 0 <= _ax + x < W and 0 <= _ay + y < H:
#                    work(_ax + x, _ay + y)
#        return True

    cnt = 0
    for x in range(W):
        for y in range(H):
            cnt += work(x,y)
    print(cnt)

Measured memory_bytes: 12988
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
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;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

    int n;
    while(cin >> n, n) {
        int ans = 0, cur = 5;
        while(cur <= n) {
            ans += n / cur;
            cur *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Rot.init(System.in);
		int N=Rot.nextInt();
		int M=Rot.nextInt();
				
		disj d=new disj(N);
		
		for(int x=0;x<M;x++) {
			int X=Rot.nextInt();
			int Y=Rot.nextInt();
			int Z=Rot.nextInt();
			
			d.union(X-1, Y-1);
		}
		
		int[] ans=new int[N];
		
		for(int g=0;g<N;g++) {
			ans[d.find(g)]=1;
		}
		
		int count=0;
		for(int h=0;h<N;h++) {
			count+=ans[h];
		}
		System.out.println(count);

	}

}

class elem{
	int data;
	int rank;
}

class disj{
	elem[] arr;
	
	disj(int n){
		arr=new elem[n];
		
		for(int i=0;i<n;i++) {
			arr[i]=new elem();
			arr[i].data=i;
			arr[i].rank=1;
		}
	}
	
	int find(int x) {
		if(arr[x].data==x) {
			return x;
		}
		else {
			return arr[x].data=find(arr[x].data);
		}
	}
	
	void union(int a,int b){
		unify(find(a),find(b));
	}
	
	void unify(int a,int b){
		if(arr[a].rank>arr[b].rank) {
			arr[b].data=a;
		}
		else {
			arr[a].data=b;
			
			if(arr[a].rank==arr[b].rank) {
				arr[b].rank+=1;
			}
		}
	}
}


/** Class for buffered reading int and double values */
class Rot {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	/** call this method to initialize reader for InputStream */
	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	/** get next word */
	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			// TODO add check for eof if necessary
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	
	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}
}




Measured memory_bytes: 45900
<?php

fscanf(STDIN, "%d", $n);

$counter = 0;
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d%d", $d1, $d2);
    if ($d1 === $d2) {
        ++$counter;
    } else {
        $counter = 0;
    }

    if ($counter === 3) {
        echo 'Yes';
        exit;
    }
}

echo 'No';


Measured memory_bytes: 16088
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
//const ll mod = 1000000007;
const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll dp[4040][4040];

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

  dp[0][0] = 1;

  string s;
  cin >> s;

  int n = s.length(), r = 0, b = 0, resr = 0, resb = 0;
  rep(i, n) {
    if (s[i] == '0') r += 2;
    else if (s[i] == '1') r++, b++;
    else b += 2;
  }
  FOR(i, 1, 2 * n + 1) {
    rep(j, i + 1) {
      int k = i - j;
      if (j > r || k > b) continue;
      if (j) dp[j][k] = (dp[j][k] + dp[j - 1][k]) % mod;
      if (k) dp[j][k] = (dp[j][k] + dp[j][k - 1]) % mod;
    }
    if (i <= n) continue;
    if (s[2 * n - i] == '0') resr += 2;
    else if (s[2 * n - i] == '1') resr++, resb++;
    else resb += 2;
    rep(j, resr) dp[j][i - j] = 0;
    rep(j, resb) dp[i - j][j] = 0;
  }
  cout << dp[r][b] << '\n';
  




  return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll modpow(ll a, int n)
{
  ll ret = 1;
  while (n > 0) {
    if (n & 1) {
      ret = (ret * a) % MOD;
    }
    a = (a * a) % MOD;
    n >>= 1;
  }
  return ret;
}

int main()
{
  int N; scanf("%d", &N);
  vector<int> freqs(N, 0);
  int a;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    ++freqs[a];
  }

  bool ok = true;
  if ((N & 1) and (freqs[0] != 1)) { ok = false; }
  if ((N & 1) == 0 and (freqs[0] != 0)) { ok = false; }

  for (int i = 1; ok and i < N; ++i) {
    if (N & 1) {
      if (i & 1) {
        if (freqs[i] != 0) { ok = false; }
      }
      else {
        if (freqs[i] != 2) { ok = false; }
      }
    }
    else {
      if (i & 1) {
        if (freqs[i] != 2) { ok = false; }
      }
      else {
        if (freqs[i] != 0) { ok = false; }
      }
    }
  }
  ll ans = ok ? modpow(2, N / 2) : 0;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define N 20
int main(void){
    int stk[N], sp=0;
    int n;
   
    while (scanf("%d", &n) != EOF){
        if (n==0 && sp!=0){
            printf("%d\n", stk[--sp]);
        } else {
            stk[sp++] = n;
        }
    }
    return 0;
}

Measured memory_bytes: 1028
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); ++itr)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

const int mn = 300;
bool isp[mn+1];
void init() {
	fill(isp + 2, isp + mn+1, true);
	Rep1(i, 2, mn) {
		if (!isp[i])continue;
		for (int j = 2 * i; j <= mn; j += i) {
			isp[j] = false;
		}
	}
}
bool testmincase(int n,int m) {
	if (isp[n])return false;
	vector<bool> used(n, false);
	queue<int> q; q.push(0); used[0] = true;
	rep(i, n) {
		if (isp[i + 1])used[i] = true;
	}
	while (!q.empty()) {
		int id = q.front(); q.pop();
		if (id%m) {
			if (!used[id - 1]) {
				used[id - 1] = true; q.push(id - 1);
			}
		}
		if ((id%m) < m - 1 && id < n - 1) {
			if (!used[id + 1]) {
				used[id + 1] = true; q.push(id + 1);
			}
		}
		if (id - m >= 0) {
			if (!used[id - m]) {
				used[id - m] = true; q.push(id - m);
			}
		}
		if (id + m < n) {
			if (!used[id + m]) {
				used[id + m] = true; q.push(id + m);
			}
		}
	}
	return used[n - 1];
}
struct zabuton {
	ll h, p;
	bool operator<(const zabuton &z)const {
		return h + p < z.h + z.p;
	}
};
void solve() {
	int n; cin >> n;
	vector<ll> dp(n+1,INF);
	dp[0] = 0;
	vector<zabuton> v(n);
	rep(i, n) {
		cin >> v[i].h >> v[i].p;
	}
	sort(v.begin(), v.end());
	rep(i, n) {
		per(j, i+1) {
			if(dp[j]<=v[i].h)dp[j + 1] = min(dp[j + 1], dp[j] + v[i].p);
		}
	}
	int ans = 0;
	rep(i, n + 1) {
		if (dp[i] != INF)ans = i;
	}
	cout << ans << endl;
}
int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const double PI=3.14159265358979323846;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,q;
  cin>>n>>q;
  vlong a(n);
  ll x;
  rep(i,n){
    cin>>a[i];
  }
  ll count=0;
  rep(i,q){
    cin>>x;
    count=0;
    ll right=0,sum=0;
    for(int left=0;left<n;++left){
      while(right<n && sum+a[right]<=x){
        sum+=a[right];
        ++right;
      }
      count+=right-left;
      if(right==left)
        right++;
      else
        sum-=a[left];
    }
    cout<<count<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3524