akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N,X;
    cin>>N>>X;
    int64 ans=0;
    vector<int64> L(N);
    for(int64 i=0;i<N;i++){
        cin>>L[i];
    }
    int64 pos=0;

    for(int64 i=0;pos<=X;i++){
        ans++;
        if(i>=N) break;
        pos+=L[i];
    }

    cout<<ans<<endl;

    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> Ans(N+1, 0);
  vector<int> A(M), B(M);
  for(int i=0; i<M; i++){
    cin >> A.at(i) >> B.at(i);
    Ans.at(A.at(i))++;
    Ans.at(B.at(i))++;
  }
  for(int i=1; i<=N; i++){
    cout << Ans.at(i) << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]+[0 for _ in range(2)]
dp = [float('inf') for _ in range(N+2)]

dp[0] = 0
for i in range(N-1):
  dp[i+1] = min(dp[i]+abs(h[i]-h[i+1]), dp[i+1])
  dp[i+2] = min(dp[i]+abs(h[i]-h[i+2]), dp[i+2])
print(dp[N-1])

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

int main(){
	string str;
	int f=1;
	cin>>str;
	int len=str.length();
	for(int i=0;i<len;i++){
		if(i%2){
			if(str[i]=='R'){
				f=0;
				cout<<"No"<<endl;;
				break;
			}
		}
		else{
			if(str[i]=='L'){
				f=0;
				cout<<"No"<<endl;
				break;
			}
		}
	}
	if(f==1)cout<<"Yes"<<endl;
	return 0;
}

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


void solve(long long N, long long M, std::vector<long long> H, std::vector<long long> A, std::vector<long long> B){
    vector<bool> good(N, true);
    for (int i = 0; i < M; i++) {
        if (H[A[i]-1] > H[B[i]-1]) {
            good[B[i]-1] = false;
        } else if (H[A[i]-1] == H[B[i]-1]) {
            good[A[i]-1] = false;
            good[B[i]-1] = false;
        } else {
            good[A[i]-1] = false;
        }
    }
    cout << count(good.begin(), good.end(), true) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(H), std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 510000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M >> S;
  Vec(P,lli,N,0);
  rep(i,0,N)P[i]=(int)(S[i]-'0');
  if(M!=2&&M!=5){
  Rev(P);
  A=10;P[0]%=M;
  rep(i,1,N){
  P[i]=(P[i]*A+P[i-1])%M;
  A*=10;A%=M;
  }
  P.pb(0);
  N++;
  map<lli,lli>map;
  rep(i,0,N)map[P[i]]++;
  for(auto v:map)if(v.second>1)num+=v.second*(v.second-1)/2;
  }
  else rep(i,0,N)if(P[i]%M==0)num+=i+1;
  Out(num);
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=k;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const ll inf=1001001001001001;
const int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    int n;cin>>n;
    ll s=0;
    vi v(n);rep(i,n)cin>>v[i];
    rep(i,n)s+=v[i];
    vvi dp(n,vi(s+1));
    dp[0][s]=1;
    dp[0][s-v[0]]=2;
    rep(i,n-1){
        rep(j,s+1){
                if(!dp[i][j])continue;
                dp[i+1][j-v[i+1]]+=dp[i][j]*2;
                dp[i+1][j-v[i+1]]%=mod;
                dp[i+1][j]+=dp[i][j];
                dp[i+1][j]%=mod;
        }
    }
 // rep(j,n*101)rep(k,n+1)if(dp[n-1][j][k])cout<<j<<' '<<k<<' '<<dp[n-1][j][k]<<endl;
    ll sum=0,ans=0;
    rep(i,n)sum+=v[i];
    sum=(sum-1)/2+1;
    REP(j,sum,s+1){
        ans=(dp[n-1][j]+ans)%mod;
    }
    //out(ans);
    vvi dp2(n,vi(s+1));
    dp2[0][0]=1;
    dp2[0][v[0]]=1;
    rep(i,n-1)rep(j,s+1){
        if(!dp2[i][j])continue;
        dp2[i+1][j+v[i+1]]+=dp2[i][j];
        dp2[i+1][j+v[i+1]]%=mod;
        dp2[i+1][j]+=dp2[i][j];
        dp2[i+1][j]%=mod;
    }
    REP(j,sum,s+1){
        ans-=2*dp2[n-1][j];
        ans%=mod;
    }
    ll t=1,k=1;
    rep(i,n){
        t*=3;
      k*=2;
      k%=mod;
        t%=mod;
    }
  t-=3*(k-1)%mod;
  t=t+mod;
    out((t-(ans+1)*3%mod+mod)%mod);
}


Measured memory_bytes: 422336
N = int(input())
end = False
for h in range(1, 3501):
    if end:
        break
    for n in range(1, 3501):
        if (4 * h * n - N * n - N * h):
            if (N * h * n) % (4 * h * n - N * n - N * h) == 0:
                w = (N * h * n) // (4 * h * n - N * n - N * h)
                if w > 0:
                    print(h, n, w)
                    end = True
                    break

Measured memory_bytes: 41836
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define MN 200005
using namespace std;
typedef unsigned long long ull;
int n,a[MN];
ull m,sum[MN];
int main(){
	scanf("%d%lld",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),sum[i]=sum[i-1]+a[i];
	ull ans=m*n+sum[n]*5;
	for(int i=1;i<n;i++){
		ull tmp=m*i;
		if(i*2<=n){
			tmp+=(sum[n]-sum[n-2*i])*5;
			int ttmp=7,pre=n-2*i;
			while(pre>=i){
				tmp+=(sum[pre]-sum[pre-i])*ttmp,ttmp+=2;pre-=i;
			}tmp+=(sum[pre])*ttmp;
		}else tmp+=sum[n]*5;
		ans=min(ans,tmp);
	}printf("%lld\n",ans+m*n);
}


Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";

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

  int n, m; cin >> n >> m;
  double a[1010] = {0};
  int sum = 0;
  rep(i, n){
     cin >> a[i];
     sum += a[i];
   }
  sort(a, a + n, greater<double>());
  if(a[m - 1] * m * 4 < sum){
    cout << NO << endl;
  }else{
    cout << YES << endl;
  }





  return 0;

}


Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
S = sys.stdin.readline()

right = S[1:].count("E")
left = 0
ans = [0]*N
ans[0] = right + left
for i in range(1, N):
    if S[i] == "E":
        right = right - 1
    if S[i-1] == "W":
        left = left + 1
    ans[i] = right+left

print(min(ans))

Measured memory_bytes: 15476
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;


int main()
{
    int d, g,ans=100000000;
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];

    for(int x = 0;x<(1<<d);x++){
        int sum=0,num=0,mx=-1;
        rep(i, d) {
            if ((x >> i) & 1){
                sum += 100*(i+1)*p[i] + c[i];
                num += p[i];
            }
            else mx = 1 + i;
        }
        if(sum<g){
            int need = (g - sum - 1 + 100 * mx) / (100*mx);
            if(need>=p[mx-1])
                continue;
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
   string s;cin >> s;
   if(s.at(0)=='S')cout << "Cloudy" << endl;
   else if(s.at(0) == 'C')cout << "Rainy" << endl;
   else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    ll x;
    cin>>x;
    ll m=(x+999)/1000;
    cout<<m*1000-x<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;




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

    vector<int>R(n,0);
    vector<int>G(n,0);
    vector<int>B(n,0);
    ll r=0;
    ll g=0;
    ll b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R'){
            r++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='G'){
            g++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
        if(s[i]=='B'){
            b++;
            R[i]=r;
            G[i]=g;
            B[i]=b;
        }
    }
    ll ans=0;


    for(ll j=1;j<n-1;j++){
        // cout<<"s["<<j<<"]=="<<s[j]<<endl;
        if(s[j]=='R'){
            ans+=(G[j-1] * (B[n-1]-B[j]));
            ans+=(B[j-1] * (G[n-1]-G[j]));
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='G') || (s[j-i]=='G' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='G'){
            ans+=(B[j-1] * (R[n-1]-R[j]));
            // cout<<B[j-1]<<" "<<R[n-1]-R[j]<<endl;
            ans+=(R[j-1] * (B[n-1]-B[j]));
            // cout<<R[j-1]<<" "<<B[n-1]-B[j]<<endl;
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='B' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='B')){
                    ans--;
                }
            }
        }

        if(s[j]=='B'){
            // cout<<"yes"<<endl;
            ans+=(R[j-1] * (G[n-1]-G[j]));
            // cout<<R[j-1]<<" "<<G[n-1]-G[j]<<endl;
            ans+=(G[j-1] * (R[n-1]-R[j]));
            // cout<<G[1]<<"AAAAA"<<endl;
            // cout<<G[j-1]<<" "<<R[n-1]-R[j]<<endl;
            for(ll i=1;i<=min(j,n-j-1);i++){
                if((s[j-i]=='G' && s[j+i]=='R') || (s[j-i]=='R' && s[j+i]=='G')){
                    ans--;
                }
            }
        }
        // cout<<"j="<<j<<" ans="<<ans<<endl;
    }

    cout<<ans<<endl;





    return 0;
}


Measured memory_bytes: 3668
import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
    dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
    if S[n] == T[m]:
        dp[n + 1][m + 1] += dp[n][m]
    dp[n + 1][m + 1] %= mod
print(dp[-1][-1])


Measured memory_bytes: 77532
import java.util.BitSet;
import java.util.Scanner;
import java.util.stream.IntStream;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] A  =IntStream.range(0,N).map(i->scan.nextInt()).toArray();
        BitSet bs = new BitSet(2000*N+1);
        bs.set(N*2000);
        int sum=0;
        for(int i=0;i<N;++i){
            bs.or(bs.get(A[i],2000*N+1));
            sum+=A[i];
        }
        int k = (sum+1)/2;
        int d = bs.previousSetBit(2000*N-k);
        System.out.println(2000*N-d);
    }
}

Measured memory_bytes: 275532
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

struct edge {
	int to, id;
};

int N, M, ednum[50];
vector<edge>v[50];
ll DP[1 << 20];

bool dfs(int x, int goal, int from, int t) {
	if (x == goal)return true;
	for (edge &e : v[x]) {
		if (e.to == from)continue;
		if (dfs(e.to, goal, x, t)) {
			ednum[e.id] += t;
			return true;
		}
	}
	return false;
}

void dfs2(int x, int from) {
	for (edge &e : v[x]) {
		if (e.to == from)continue;
		dfs2(e.to, x);
		for (int i = (1 << M) - 1; i >= 0; i--) {
			DP[i | ednum[e.id]] += DP[i];
		}
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		v[a].push_back({ b,i });
		v[b].push_back({ a,i });
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		int u, v;
		cin >> u >> v;
		dfs(u - 1, v - 1, -1, 1 << i);
	}
	DP[0] = 1;
	dfs2(0, -1);
	cout << DP[(1 << M) - 1] << endl;
}

Measured memory_bytes: 8448
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, t, tmp;
    vector<int> a, b;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        b.push_back(tmp);
    }

    if (a > b) swap(a, b);
    do {
        if (a == b) break;
        t++;
    } while (next_permutation(a.begin(), a.end()));
    cout << t;
}


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

int main() {
  int a,b,c,d,e,A,B,C,D,E;
  cin>>a>>b>>c>>d>>e;
  int sum=a+b+c+d+e;
  rep(i,65){
    if(10*i<a && a<=10*(i+1)){ A=10*(i+1)-a;}
    if(10*i<b && b<=10*(i+1)){ B=10*(i+1)-b;}
    if(10*i<c && c<=10*(i+1)){ C=10*(i+1)-c;}
    if(10*i<d && d<=10*(i+1)){ D=10*(i+1)-d;}
    if(10*i<e && e<=10*(i+1)){ E=10*(i+1)-e;}
  }
  int m=max(max(max(A,B),max(C,D)),E);
  cout<<sum+A+B+C+D+E-m<<endl;
  
  }

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int N, Q, A, last;
long long tag[524288], as[524288], ds[524288];
inline void down(int p)
{
	if (tag[p])
	{
		as[p << 1] += tag[p];
		ds[p << 1] += tag[p];
		tag[p << 1] += tag[p];
		as[p << 1 | 1] += tag[p];
		ds[p << 1 | 1] += tag[p];
		tag[p << 1 | 1] += tag[p];
		tag[p] = 0;
	}
}
inline void up(int p)
{
	as[p] = std::min(as[p << 1], as[p << 1 | 1]);
	ds[p] = std::min(ds[p << 1], ds[p << 1 | 1]);
}
void build(int p, int l, int r)
{
	if (l == r)
	{
		long long w = l == A ? 0 : 1LL << 60;
		as[p] = w + l;
		ds[p] = w - l;
		return;
	}
	int m = l + r >> 1;
	build(p << 1, l, m);
	build(p << 1 | 1, m + 1, r);
	as[p] = std::min(as[p << 1], as[p << 1 | 1]);
	ds[p] = std::min(ds[p << 1], ds[p << 1 | 1]);
}
inline int abs(int x)
{
	return x < 0 ? -x : x;
}
long long G(int p, int l, int r, int L, int R, long long *s)
{
	if (L <= l && r <= R)
		return s[p];
	int m = l + r >> 1;
	down(p);
	if (R <= m)
		return G(p << 1, l, m, L, R, s);
	if (L > m)
		return G(p << 1 | 1, m + 1, r, L, R, s);
	return std::min(G(p << 1, l, m, L, R, s), G(p << 1 | 1, m + 1, r, L, R, s));
}
void DFS(int p, int l, int r, long long &O)
{
	if (l == r)
	{
		O = std::min(O, ds[p] + l);
		return;
	}
	int m = l + r >> 1;
	down(p);
	DFS(p << 1, l, m, O);
	DFS(p << 1 | 1, m + 1, r, O);
}
int main()
{
	scanf("%d%d%d%d", &N, &Q, &A, &last);
	build(1, 1, N);
	for (int i = 1, x; i <= Q; i++)
	{
		scanf("%d", &x);
		long long ILoveYou = std::min(G(1, 1, N, 1, x, ds) + x, G(1, 1, N, x, N, as) - x);
		tag[1] += abs(last - x);
		int p = 1, l = 1, r = N;
		while (l < r)
		{
			int m = l + r >> 1;
			down(p);
			if (last <= m)
				p <<= 1, r = m;
			else
				p = p << 1 | 1, l = m + 1;
		}
		as[p] = ILoveYou + last;
		ds[p] = ILoveYou - last;
		while (p >>= 1)
			up(p);
		last = x;
	}
	long long O = 1LL << 60;
	DFS(1, 1, N, O);
	printf("%lld\n", O);
	return 0;
}


Measured memory_bytes: 12416
#include <iostream>

using namespace std;

int main(void) {
    int64_t H, W, x, y;
    cin >> H >> W >> x >> y;
    
    cout << H*W*0.5 << ' ';
    if(x*2 == H && y*2 == W) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int r,c,ans=0,pro;
    cin>>r>>c;
    if(r==1||c==1)
    {
        cout<<1<<endl;
        return 0;
    }
    pro=r*c;
    if(pro%2==0)
        ans=pro/2;
    else
        ans=(pro/2)+1;
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    char s[2000], t[2000];
    int i, ii, iii, l, ll, tmp, ans = 100000;
    scanf("%s%s", s, t);
    i = 0; ii = 0;
    while (s[i])
        i++;
    while (t[ii])
        ii++;
    l = i; ll = ii;
    ans = ll;
    for (i = 0; i <= l - ll; i++)
    {
        tmp = 0;
        for (ii = 0; ii < ll; ii++)
            if (s[i + ii] - t[ii])
                tmp++;
        if (ans > tmp)
            ans = tmp;
    }
    
    printf("%d", ans);
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

ll n,d;
void solve(){
  VI cnt[n];
  rep(i,n){
    int m;
    cin >> m ;
    cnt[i].push_back(0);
    rep(j,m){
      int x;
      cin >> x;
      x += cnt[i].back();
      cnt[i].push_back(x);
    }
  }

  vector<int> idx_array(n);
  rep(i,n) idx_array[i] = cnt[i].size() - 1;
  while(true){
    priority_queue<PII> que;
    rep(i,n){
      int idx = idx_array[i];
      que.push({cnt[i][idx],i});
    }
    bool flag = false;
    rep(i,n){
      int max_v = 0;
      if(que.top().second == i){
        PII p = que.top(); que.pop();
        max_v = que.top().first;
        que.push(p);
      }else{
        max_v = que.top().first;
      }
      int idx = lower_bound(all(cnt[i]), max_v - d ) - cnt[i].begin();
      if(idx_array[i] != idx){
        idx_array[i] = idx;
        flag = true;
        break;
      }
    }

    if(flag == false){
      if(que.top().first == 0){
        cout << "Yes" << "\n";
      }else{
        cout << "No" << "\n";
      }
      return;
    }
  }
  return;
}
int main(){
  while(true){
    cin >> n >> d;
    if(n == 0) break;
    solve();
  }

}



Measured memory_bytes: 3040
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S; cin >> S;
    int N = S.size();

    int cnt = 0;
    rep(i,N) {
        if (S[i] == '(') cnt++;
        else if (S[i] == ')') cnt--;
        else {
            cout << cnt << ln;
            return 0;
        }
    }
}



Measured memory_bytes: 3212
A=abs
_,*p=[list(map(int,t.split()))for t in open(0)]
for t in p:
 if t[2]:x,y,h=t
for I in range(10201):j,i=I//101,I%101;H=h+A(x-j)+A(y-i);print(*(j,i,H)*all(u==max(H-A(s-j)-A(t-i),0)for s,t,u in p))

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;

vector<ll> checklist;

string zero(string ume, ll keta)
{
  while (ume.length() < keta)
  {
    ume = "0" + ume;
  }
  return ume;
}

ll checktolist(ll hoge)
{
  for (int i = 0; i < checklist.size(); i++)
  {
    if (checklist[i] == hoge)
      return i;
  }
  return -1;
}

int main()
{
  while (1)
  {
    string a;
    ll b;
    ll count = 0;

    cin >> a >> b;

    if (a == "0" && b == 0)
      exit(0);

    checklist = {stoi(a)};

    // 0埋め
    string kazu = zero(a, b);

    while (1)
    {
      count++;

      // v: ソート用配列
      vector<char> v;

      // 文字列をvectorに
      for (int i = 0; i < b; i++)
        v.push_back(kazu[i]);

      // sortした
      sort(all(v));

      // 小さい数
      string nekazu;
      for (int i = 0; i < b; i++)
        nekazu += v[i];


      // reverse
      sort(rall(v));

      // 大きい数
      string rekazu;
      for (int i = 0; i < b; i++)
        rekazu += v[i];

      ll hoge = stoi(rekazu) - stoi(nekazu);

      // cout << stoi(rekazu) << " - " << stoi(nekazu) << " = " << hoge << endl;

      if (checktolist(hoge) != -1)
      {
        if (a == "0")
          cout << 0 << " ";
        else
          cout << checktolist(hoge) << " ";
        cout << hoge << " ";
        cout << count - checktolist(hoge) << endl;
        break;
      }

      checklist.push_back(hoge);

      kazu = zero(to_string(hoge), b);
    }
    // checklist = {-1};
  }
}



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

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; i++){
    if(i % 3 != 0 && i % 5 != 0){
      ans += i;
    }
  }
  cout << ans << endl;
}

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

bool is_palindrome(string s){
  string r = s;
  reverse(r.begin(), r.end());
  return s == r;
}
int main() {
  string s;
  cin >> s;
  int N = s.length();
  if(is_palindrome(s) and is_palindrome(s.substr(0,N/2)) and is_palindrome(s.substr(N/2+1))){
    puts("Yes");
  } else{
    puts("No");
  }
}

Measured memory_bytes: 3608
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val L = IntArray(N){0}
    for (i in 0 until N) {
        val l = sc.nextInt()
        L[i] = l
    }
    val max = L.max()!!
    if (max*2 < L.sum()) println("Yes")
    else println("No")
}

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

int main() {
  int N,Q;
  cin >> N >> Q;
  
  dsu UF = dsu(N);
  rep(i,Q) {
    int t,u,v;
    cin >> t >> u >> v;
    if (t == 0) {
      UF.merge(u,v); 
    } else {
      if (UF.same(u,v)){
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
  return 0; 
}

Measured memory_bytes: 3984
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[100];
	int n,i;
	scanf("%s", s);
	n=strlen(s);
	for(i=0; i<n; i++)
	{
		if(i%2==1&&s[i]=='R')
		{
			printf("No\n");
			break;
		}
		if(i%2==0&&s[i]=='L')
		{
			printf("No\n");
			break;
		}
		if(i==n-1)
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;
/*
ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		else a=a*a%MOD;
		b>>=1;
	}
	return res;
}
*/

int a[maxn];

int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];

	int ans=INF;
	for(int i=-100;i<=100;i++){
		int sum=0;
		REP(j,n) sum+=(a[j]-i)*(a[j]-i);
		ans=min(ans,sum);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int N,H,W;

    cin >> N >> H >> W;

    cout << (N+1-H) * (N+1-W) << endl;

}


Measured memory_bytes: 256
def main():
  n, m = map(int, input().split())
  lr = [tuple(map(int, input().split())) for _ in range(n)]
  BIT = [0 for _ in range(m+1)]

  def bit_add(a, w):
    x = a
    while x <= m:
      BIT[x] += w
      x += x&-x

  def bit_sum(a):
    ret = 0
    x = a
    while x > 0:
      ret += BIT[x]
      x -= x&-x
    return ret

  lr = list(sorted(lr, key=lambda x: x[1]-x[0]))
  i = 1
  for d in range(1, m+1):
    while i<=n and lr[i-1][1]-lr[i-1][0]+1==d:
      bit_add(lr[i-1][0], 1)
      bit_add(lr[i-1][1]+1, -1)
      i += 1
    ans = n - i + 1
    for j in range(d, m+1, d):
      ans += bit_sum(j)
    print(ans)


if __name__ == '__main__':
  main()


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

#define WHITE 0
#define BLACK 1

ll H, W, Ch, Cw, Dh, Dw;
vector<string> S;
vector<vector<ll>> col;

struct BFSDroplet {
    BFSDroplet(ll first, ll second, ll d)
        : first(first), second(second), d(d) {}
    ll first, second, d;
};

ll solve(ll Ch, ll Cw) {
    queue<BFSDroplet> QMotherList;
    QMotherList.push(BFSDroplet(Ch, Cw, 0));
    while (!QMotherList.empty()) {
        auto v = QMotherList.front();
        QMotherList.pop();
        if (col[v.first][v.second] == BLACK) continue;
        queue<BFSDroplet> QOngoingList;
        queue<BFSDroplet> QAfterList;
        QOngoingList.push(v);
        while (!QOngoingList.empty()) {
            auto u = QOngoingList.front();
            QOngoingList.pop();
            col[u.first][u.second] = BLACK;
            QAfterList.push(u);
            if (u.first + 1 < H) {
                if (col[u.first + 1][u.second] == WHITE &&
                    S[u.first + 1][u.second] == '.') {
                    col[u.first + 1][u.second] = BLACK;
                    QOngoingList.push(BFSDroplet(u.first + 1, u.second, u.d));
                }
            }
            if (u.second + 1 < W) {
                if (col[u.first][u.second + 1] == WHITE &&
                    S[u.first][u.second + 1] == '.') {
                    col[u.first][u.second + 1] = BLACK;
                    QOngoingList.push(BFSDroplet(u.first, u.second + 1, u.d));
                }
            }
            if (u.first - 1 >= 0) {
                if (col[u.first - 1][u.second] == WHITE &&
                    S[u.first - 1][u.second] == '.') {
                    col[u.first - 1][u.second] = BLACK;
                    QOngoingList.push(BFSDroplet(u.first - 1, u.second, u.d));
                }
            }
            if (u.second - 1 >= 0) {
                if (col[u.first][u.second - 1] == WHITE &&
                    S[u.first][u.second - 1] == '.') {
                    col[u.first][u.second -1] = BLACK;
                    QOngoingList.push(BFSDroplet(u.first, u.second - 1, u.d));
                }
            }
        }
        while (!QAfterList.empty()) {
            auto u = QAfterList.front();
            QAfterList.pop();
            if (u.first == Dh && u.second == Dw) {
                return u.d;
            }
            for (ll h = u.first - 2; h <= u.first + 2; h++) {
                if (h < 0 || h >= H) continue;
                for (ll w = u.second - 2; w <= u.second + 2; w++) {
                    if (w < 0 || w >= W) continue;
                    if (col[h][w] == WHITE && S[h][w] == '.') {
                        QMotherList.push(BFSDroplet(h, w, u.d + 1));
                    }
                }
            }
        }
    }
    return -1;
}

int main() {
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--;
    Cw--;
    Dh--;
    Dw--;
    S.resize(H);
    col.resize(H);
    for (ll h = 0; h < H; h++) {
        cin >> S[h];
        col[h].resize(W);
        for (ll w = 0; w < W; w++) {
            col[h][w] = WHITE;
        }
    }
    cout << solve(Ch, Cw) << endl;
    return 0;
}


Measured memory_bytes: 13844
#include <iostream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll N,M;
  ll n,m;
  cin>>N>>M>>n>>m;
  cout<<(N-n)*(M-m)<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int[] length = new int[3];
        for(int i = 0; i < 3; i++)
        {
            length[i] = int.Parse(input[i]);
        }
        Array.Sort(length);
        Console.WriteLine(length[0] * length[1] / 2);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll mod = 1e9+7;


int main(){
    int n; cin >> n;
  ll mod = 1e9+7;
    vector<ll> a(n);
    ll sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        }
    for(int i=0;i<60;i++){
    ll zc=0,oc=0;
    ll zosum = 0;  
    for(int j=0;j<n;j++){
        if(a[j]%2==0){
            zc++;}
        else{
            oc++;}
        a[j]/=2;
        }
    zosum = (((zc * oc)%mod) * ((1LL<<i)%mod))%mod;
    sum += zosum;
    sum %= mod;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;

  vector<Int> A(M);
  cin>>A;
  Int s = 0;
  for(Int a:A) s += a;

  if(s > N) cout<<-1<<endl;
  else cout<<N - s<<endl;


  return 0;
}


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

int main()
{
    vector<int>v;
    for(int i=0; i<5; i++){
        int a;
        cin>>a;
        v.push_back(a);
    }
    for(int i=0; i<v.size(); i++){
        if(v[i]==0){
            cout<<i+1<<endl;
        }
    }
}


Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(void)
{
  while(true)
    {
  int h,w;
  cin>>h;
  cin>>w;
  if(h==0 && w==0)break;
  for(int i=0;i<h;i++)
    {
      for(int j=0;j<w;j++)
	{
	  cout<<"#";
	}
      cout<<endl;
    }
  cout<<endl;
    }
  return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}
ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
}

template<class t>
istream& operator>>(istream& is, vector<t> &x){
    for(auto &i:x)is >> i;
    return is;
}

template<class t, class u>
istream& operator>>(istream& is, pair<t, u> x){
    is >> x.first >> x.second;
    return is;
}

class union_find{
public:
	int n;
	vector<int> parent;
	union_find(int _n):n(_n){
		parent.resize(n);
		rep(i, n){
			parent[i]=i;
		}
	}

	int get_parent(int x){
		if(parent[x]==x)return x;
		return parent[x] = get_parent(parent[x]);
	}

	bool is_same(int a, int b){
		int ap = get_parent(a);
		int bp = get_parent(b);
		return ap == bp;
	}

	void merge(int a, int b){
		int ap = get_parent(a);
		int bp = get_parent(b);
		if(ap==bp)return;
		parent[bp] = ap;
	}

    vector<int> solve(){
        vector<int> num(n,0);
        rep(i,n){
            int root = get_parent(i);
            ++num[root];
        }
        vector<int> res(n,0);

        rep(i,n){
            int root = get_parent(i);
            res[i] = num[root];
        }
        return res;
    }

};

int main(){
    int n = in();
    int m = in();
    int k = in();
    vector<int> friends(n,-1);
    union_find uf(n);
    rep(i,m){
        int a = in()-1;
        int b = in()-1;
        uf.merge(a,b);
        --friends[a];
        --friends[b];
    }

    rep(i,k){
        int a = in()-1;
        int b = in()-1;
        if(uf.is_same(a,b)){
            --friends[a];
            --friends[b];
        }
    }
    vector<int> ans = uf.solve();
    rep(i,n){
        output(ans[i]+friends[i]);
    }

    return 0;
}


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

int main()
{
  int64_t N, K, r, p, ans = 0, zero = 0, one = 1;
  cin >> N >> K;
  for (int b = 1; b <= N; b++)
  {
    ans += max(b - K, zero) * (N / b);
    ans += max((N % b) - max(one, K) + 1, zero);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  int fb=0, ea=0, n=0;
  string s;
  int ans = 0;
  rep(i, 0, N) {
    cin >> s;
    if(s[0] == 'B') {
      fb++;
    }
    if(s[s.size()-1] == 'A') {
      ea++;
    }
    if(s[s.size()-1] == 'A' || s[0] == 'B') {
      n++;
    }
    rep(j, 0, s.size()-1) {
      if(s[j] == 'A' && s[j+1] == 'B') ans++;
    }
  }
  int k=0;
  ans += min(min(fb, ea), max(k, n-1));
  cout << ans << endl;
      
}

Measured memory_bytes: 256
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
ans=list(range(0,102))
min_num=1000
for i in List:
    ans.remove(i)
for i in ans:
    if (abs(i-x)<abs(min_num-x)) or (abs(i-x)==abs(min_num-x) and i<min_num):
        min_num=i
print(min_num)

Measured memory_bytes: 9204
import math
n, d = map(int,input().split())
all_li = [list(map(int,input().split())) for _ in range(n)]
count = 0
for i,li in enumerate(all_li):
    if i == len(all_li) - 1:
        break
    for l in all_li[i+1:]:
        all_sum = 0
        for a,b in zip(li,l):
            all_sum += (a-b)**2
        if math.sqrt(all_sum) == int(math.sqrt(all_sum)):
            count += 1
print(count)

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

int main() {
  int64_t ans,n;
  ans=0;
cin>>n;
  vector<int64_t> vec(n);
for(int64_t i=0;i<n;i++){
cin>>vec.at(i);
}
  sort(vec.begin(), vec.end()); 
    reverse(vec.begin(), vec.end()); 
  ans=vec.at(0);  
  for(int64_t i=0;i<(n-2)/2;i++){ans+=(vec.at(i+1)*2);}
  if(n%2==1){ans+=vec.at((n-1)/2);}
  cout<<ans<<endl;
}

Measured memory_bytes: 4824
x = int(input())
a = list(map(int, input().split()))

b = sorted(a, reverse=True)

ans_Alice = 0
ans_Bob = 0

for i in range(x): 
    if i%2 ==0:
        ans_Alice += int(b[i])
    else:
        ans_Bob += int(b[i])

        
print(int(ans_Alice) - int(ans_Bob))


Measured memory_bytes: 9016
from collections import deque
h,w = map(int,input().split())
C = list(map(int,input().split()))
D = list(map(int,input().split()))
S = [[s for s in input()]for _ in range(h)]
que = deque([[C[0]-1,C[1]-1]])
que2 = deque([])
dd = [-1,1]
d1 = [-2,-1,0,1,2]
reach = [[False for _ in range(w)]for _ in range(h)]
added = [[False for _ in range(w)]for _ in range(h)]
reach[C[0]-1][C[1]-1]=True
added[C[0]-1][C[1]-1]=True
ans = 0
while que:
    u = que.popleft()
    x,y = u
    if not reach[x][y]:
        reach[x][y] = True
    for d in dd:
        xx = x+d
        yy = y+d
        if 0 <= xx < h:
            if S[xx][y] == '.':
                if not reach[xx][y]:
                    que.append([xx,y])
                    reach[xx][y] = True
                    added[xx][y] = True

        if 0 <= yy < w:
            if S[x][yy] =='.':
                if not reach[x][yy]:
                    que.append([x,yy])
                    reach[x][yy] = True
                    added[x][yy] = True 
    for i in d1:
        for j in d1:
            s,t = x+i,y+j
            if 0<=s<h and 0<=t<w:
                if S[s][t] == '.' and not added[s][t]:
                    que2.append([s,t]) 
                    added[s][t] = True

    if reach[D[0]-1][D[1]-1]:
        print(ans)
        exit()    
    if not que:
        que = que2
        que2 = deque([])
        ans += 1
print(-1)

Measured memory_bytes: 146276
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 1000000009
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll num = 1;
  ll first = 0;
  ll count = 0;
  ll ans = 0;
  rep(i,s.size()-1){
    if(s[i] == s[i + 1]){
      num++;
    }
    else{
      if(count == 0){
        first = num;
      }
      ans += num/2;
      count++;
      num = 1;
    }
  }
  ll a = 1;
  ll b = 1;
  for(int i = 1; i < s.size(); i++) {
    if(s[i] == s[0]){
      a ++;
    }
    else{
      break;
    }
  }
  for(int i = 1; i < s.size(); i++) {
    if(s[s.size() - i - 1] == s[s.size() - 1]){
      b++;
    }
    else{
      break;
    }
  }
  ans += num/2;
  if(count == 0){
    cout << num*k/2 << endl;
  }
  else if(s[0] != s[s.size()-1]){
    cout << ans*k << endl;
  }
  else{
    //cout << first << " " << num << endl;
    cout << ans * k + (k - 1) * ((a + b) / 2 - (a / 2) - (b / 2)) << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(),B=sc.nextInt();
		int temp = A+B;
		if(A-B > temp) temp = A-B;
		if(A*B > temp) temp = A*B;
		System.out.println(temp);
	}
}


Measured memory_bytes: 22228
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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;
}

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

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

//----------------------------------------------------------------

int main()
{
    map<string, int> dict;

    int n;
    cin >> n;
    vector<string> a(n);
    int ans = -INF;
    int i = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        dict[a[i]]++;
        chmax(ans, dict[a[i]]);
    }
    vector<string> out;
    int j = 0;
    for (int i = 0; i < n; i++)
    {
        if (dict[a[i]] == ans)
        {
            out.push_back(a[i]);
        }
    }
    sort(out.begin(), out.end());
    out.push_back("{{{{{");
    for (int i = 0; i < out.size()-1; i++)
    {
        if (out[i] != out[i + 1])
        {
            cout << out[i] << endl;
        }
    }
}

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

int counter(int n){
    int c = 0;
    for(int i=0;i<12;i++){
        if(n&1){
            c++;
        }
        n = n >> 1;
    }
    return c;
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<bool>> data(H, vector<bool>(W, false));

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            char c;
            cin >> c;
            data[i][j] = (c == '1');  // count the number of white
        }
    }
    // cout << "finish input" << endl;
    int ans = H*W;
    for(int sep=0;sep<(1<<10);sep++){
        int count = counter(sep);
        // cout << "count = " << count << endl;
        // separate vertically
        vector<vector<int>> sepData(H, vector<int>(W+1, 0));
        int t_count = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(data[i][j]) sepData[t_count][j]++;
            }
            // if separated increment
            if(sep>>i & 1) t_count++;
        }
        // check
        bool ok = true;
        int start_i = 0;
        vector<int> current(H, 0);
        for(int i=0;i<W;i++){
            if(start_i == i){
                int max_choco = 0;
                for(int j=0;j<H;j++){
                    max_choco = max(max_choco, sepData[j][i]);
                    current[j] = sepData[j][i];
                }
                if (max_choco > K){
                    ok = false;
                    break;
                }
            }
            // check need searation(change the start i)
            bool need_sep = false;
            // if sum is over k, need_sep is true
            for(int k=0;k<H;k++){
                // int choco_count = 0;
                current[k] += sepData[k][i+1];
                // for(int j=start_i;j<=i+1;j++){
                //     choco_count += sepData[k][j];
                // }
                if(current[k] > K) need_sep =  true;
            }
            if (need_sep) {
                start_i = i + 1;
                count++;
            }
        }
        if(!ok){
            continue;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a,b,c,d;
    a = n/1000;
    b = (n%1000)/100;
    c = (n%100)/10;
    d = (n%10)/10;
    string msg = "No";

    if(a == b && a == c || \
    a == b && a == d || \
    a == c && a == d ||\
    b == c && c == d){
        msg = "Yes";
    }
    cout << msg << endl;
    return 0;
}

Measured memory_bytes: 256