akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
	    int[] arr = new int[n];
	    int flag =0;
	    for(int i=0;i<n;i++){
	    	arr[i]=sc.nextInt();
	    }
	    	Arrays.sort(arr);
	    	boolean[] vis = new boolean[arr[n-1]+1];
	    	Arrays.fill(vis,true);
	    	int[] count = new int[arr[n-1]+1];
	    	for(int i=0;i<n;i++){
	    		count[arr[i]]++;
	    	}
	    	for(int i=0;i<n;i++){
	    		if(vis[arr[i]]==true){
	    			for(int j=2*arr[i];j<=arr[n-1];j+=arr[i]){
	    				//System.out.println(j);
	    				vis[j]=false;
	    			}
	    		}
	    	}
	    	int ans=0;
	    	for(int i=0;i<n;i++){
	    		if(vis[arr[i]]==true && count[arr[i]]==1){
	    			ans++;
	    		}
	    	}
	    	System.out.println(ans);

	}
	
}

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

UL N,K;
const ULL M=1000000007;
ULL F[1001];
ULL I[1001];
ULL iF[1001];
ULL Pow[1001][1001];
ULL dp[1001];

ULL C(UL n,UL r){return F[n]*iF[r]%M*iF[n-r]%M;}

int main() {
 cin>>N>>K;
 F[0]=I[1]=iF[0]=1;
 for(UL i=1;i<=1000;i++) F[i]=F[i-1]*i%M;
 for(UL i=2;i<=1000;i++) I[i]=M-M/i*I[M%i]%M;
 for(UL i=1;i<=1000;i++) iF[i]=iF[i-1]*I[i]%M;
 for(UL k=0;k<=K;k++) {
  Pow[k][0]=1;
  for(UL n=1;n<=N;n++) Pow[k][n]=Pow[k][n-1]*k%M;
 }
 dp[0]=0;
 for(UL k=1;k<=K;k++){
  dp[k]=Pow[k][N];
  rep(j,k) dp[k]+=(M-C(k,j)*dp[j]%M);
  dp[k]%=M;
 }
 rep(k,K+1) dp[k]=dp[k]*iF[k]%M;
 cout<<dp[K]<<endl;
 return 0;
}



Measured memory_bytes: 10936
N, M = map(int, input().split())
Map = [[int(1e18) for _ in range(N)] for __ in range(N)]
Path = [[[] for _ in range(N)] for __ in range(N)]
D = {}
for i in range(M):
  a, b, c = map(int, input().split())
  Map[a-1][b-1] = c
  Map[b-1][a-1] = c
  Path[a-1][b-1] = [a-1, b-1]
  Path[b-1][a-1] = [b-1, a-1]
  D[(a-1)*N+b-1] = 0
  D[(b-1)*N+a-1] = 0
for i in range(N):
  Map[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      if Map[i][j] > Map[i][k] + Map[k][j]:
        Map[i][j] = Map[i][k] + Map[k][j]
        Path[i][j] = Path[i][k][:] + Path[k][j][1:]
        
for i in range(N):
  for j in range(N):
    X = Path[i][j][:]
    n = len(X)
    for k in range(n-1):
      l = X[k] * N + X[k+1]
      r = X[k+1] * N + X[k]
      if l in D:
        D[l] = 1
      if r in D:
        D[r] = 1
SUM41 = 0
for i in D:
  if D[i] == 0:
    SUM41 += 1
print(SUM41 // 2)

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

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int L = Integer.parseInt(in.next());
            int R = Integer.parseInt(in.next());
            long ans = Long.MAX_VALUE;

            if (R - L + 1 >= 2019) {
                ans = 0;
            } else {

                for (int i = L; i <= R; i++) {
                    for (int j = i + 1; j <= R; j++) {
                        ans = Math.min(((i % 2019) * (j % 2019)) % 2019, ans);
                        if (ans == 0) break;
                    }
                }
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21844
#include<iostream>
#include<bits/stdc++.h>
#define MAX_N 500000 
#define limit 2000000000
using namespace std; 
int L[MAX_N/2+2],R[MAX_N/2+2],cnt;
void mergesort(int * A,int l,int r);
void merge(int *A,int l,int r,int mid);
int main(void){
	int A[MAX_N],n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",A+i);
	cnt=0;
	mergesort(A,0,n);
	for(int i=0;i<n;i++) printf("%s%d",i==0? "":" ",A[i]);
	printf("\n%d\n",cnt);
}
void mergesort(int * A,int l,int r){
	if(l+1<r){
		int mid=(l+r)/2;
		mergesort(A,l,mid);
		mergesort(A,mid,r);
		merge(A,l,r,mid);
	}
}
void merge(int *A,int l,int r,int mid){
	int lenl,lenr,i,j,k;
	lenl=mid-l,lenr=r-mid;
	for(i=0;i<lenl;i++) L[i]=A[i+l];
	for(i=0;i<lenr;i++) R[i]=A[i+mid];
	L[lenl]=limit,R[lenr]=limit;
	i=0,j=0;
	for(k=l;k<r;k++){
		cnt++;
		if(L[j]<=R[i]){
			A[k]=L[j];
			j++;
		}
		else {
			A[k]=R[i];
			i++;
		}
	}
}


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

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

    int a=0, w=0, t=0, r=0;
    string s;
    for(int i=0; i<n; i++){
        cin >> s;
        if(s=="AC"){
            a++;
        } else if(s=="WA") {
            w++;
        } else if(s=="TLE") {
            t++;
        } else {
            r++;
        }
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int dp[101][10001];
int n;
int v[101],w[101];
int dfs(int now,int nw){
  if(dp[now][nw]>=0){
    return dp[now][nw];
  }
  int res;
  if(now==n){
    res=0;
  }else if(nw<w[now]){
    res=dfs(now+1,nw);
  }else{
    res=max(dfs(now+1,nw),dfs(now+1,nw-w[now])+v[now]);
  }
  return dp[now][nw]=res;
}
int main(){
  int W;
  memset(dp,-1,sizeof(dp));
  cin >> n >> W;
  for(int i=0;i<n;i++){
    cin >> v[i] >> w[i];
  }
  cout << dfs(0,W) <<endl;
  return(0);
}




Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int INT;
typedef unsigned long long LONG;
typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
#define FW freopen("data2.txt", "w", stdout);
//读入输出外挂，只适用于整数，使用时流同步打开，C语言不准关流
// getchar()<<cin(关流)<<scanf()<<cin
template <class T>
inline bool Read(T& ret)
{
    char c;
    int sgn;
    if (static_cast<void>(c = getchar()), c == EOF)
        return 0;
    while (c != '-' && (c < '0' || c > '9'))
        c = getchar();
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
        ret = ret * 10 + (c - '0');
    ret *= sgn;
    return 1;
}
//输出只能用于整数
template <class T>
inline void Write(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        Write(x / 10);
    putchar(x % 10 + '0');
}

void slove(int quetion_num)
{
  	int a,b,c;
  	cin>>a>>b>>c;
  	int ans=a/b;
  	if(a%b!=0) ans=(ans+1)*c;
  	else ans=ans*c;
    cout << ans << endl;
}
int main()
{
    int num = 1;
    // cin >> num;
    for (int i = 1; i <= num; ++i) {
        slove(num);
    }
    //system("pause");
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

int N;
int tt = 0;
vector< vector<int> > G;
vector<int> H, d, f;
int itrNum[100001];
stack<int> S;

void dfs(int u){
    S.push(u);
    H[u] = 0;

    while(!S.empty()){
        u = S.top();  // ?¨????????????????
        if(d[u] == 0) d[u] = ++tt;
        auto itr_v = next(G[u].begin(), itrNum[u]);
        if(itr_v != G[u].end()){
            itrNum[u]++;
            int v = *itr_v;
            if(H[v] == -1){
                H[v] = 0;
                S.push(v);
            }
        }else{
            S.pop();
            H[u] = 1;
            f[u] = ++tt;
        }
    }
}

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

    cin >> N;
    G = vector<vector<int> >(N);
    H = vector<int>(N, -1);
    d = vector<int>(N, 0);
    f = vector<int>(N, 0);
    memset(itrNum, 0, sizeof(itrNum));
    REP(i, N){
        int u,k;
        cin >> u >> k;
        u--;
        REP(j ,k){
            int v;
            cin >> v;
            v--;
            G[u].pb(v);
        }
    }

    REP(i, N) if(H[i] == -1) dfs(i);
    REP(i, N){
        cout << i+1 << " " << d[i] << " " << f[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define fr(i,a,b) for(ll i=a;i < b;i++)
#define fe(i,a,b) for(ll i=a;i <= b;i++)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fir first
#define sec second
#define tr(it,x) for(auto it = x.begin();it != x.end();it++)
#define mp make_pair
#define sz(x) (ll)x.size()
#define rep(i,n) for(ll i=0;i<n;i++)
#define double long double
#define accuracy ll precision = numeric_limits<double>::digits10
#define pll pair<ll,ll>
#define MAXN 100005
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define case(x) cout<<"Case #"<<x+1<<": "
#define endl "\n"
#define preturn(X) cout<<(X)<<endl; return 0
const int MOD = 1e9+7;
ll powmod(ll a,ll b,ll m=MOD){ll r=1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}
ll power(ll a,ll b){ll r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
ll gcd(ll a,ll b){if(!b)return a;return gcd(b,a%b);}
ll inv(ll a, ll m = MOD){return powmod(a,m-2,m);}
ll lcm(ll a,ll b){return(a*b)/gcd(a,b);}

int32_t main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h[i];
    vector<int> cost(n);
    if(n==1){
        cout<<0<<endl;return 0;
    }
    if(n==2){
        cout<<abs(h[1] - h[0])<<endl;return 0;
    }
    cost[0] = 0;
    cost[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
        cost[i] = min(cost[i-2] + abs(h[i] - h[i-2]),cost[i-1] + abs(h[i] - h[i-1]));
    }
    cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W, N; cin >> H >> W >> N;
    int a[N];
    for(int i = 0; i < N; i++) cin >> a[i];
    int x = 0, y = 0;
    int c[H][W];
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < a[i]; j++)
        {
            c[x][y] = i+1;
            if(x % 2 == 0) y++;
            else y--;
            if(y == W || y < 0) {
                x++;
                if(y == W) y = W-1;
                else y = 0;
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << c[i][j];
            if(j != W-1) cout << " ";
        }
        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<ll> que;
    REP(i,n){
        que.push(in());
    }
    REP(i,m){
        ll x = que.top();
        que.pop();
        que.push(x / 2);
    }
    ll ans = 0;
    REP(i,n){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;

int sum[maxn];
char s[maxn];
int n,q;
int main(){
	  ios_base::sync_with_stdio(false);
	  cin.tie(0);

	  cin >> n >> q;
	  for(int i = 1; i <= n; i++) cin >> s[i];
	  for(int i = 1; i <= n; i++){
	  	sum[i] = sum[i - 1];
	  	if(s[i] == 'C'&&  s[i - 1] == 'A'){
	  		++sum[i];
	  	}
	  }

	  while(q--){
	  	int l,r;
	  	cin >> l >> r;
	  	cout << sum[r] - sum[l] << endl;
	  }
	  return 0;
}

Measured memory_bytes: 1280
import math
t = int(input())
a = list(map(int,input().split()))
highest = a.index(max(a))
ans=0
for i in range(1,highest):
    if a[i]<a[i-1]:

        ans+= (a[i-1]-a[i])
        a[i] = a[i-1]
for i in range(highest+1,len(a)):
    if a[i]<a[i-1]:
        ans+=(a[i-1]-a[i])
        a[i]=a[i-1]
print(ans)

Measured memory_bytes: 32996
#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
#define N 201000
using namespace std;
void U(ll &x,ll y){x=x*y%mod;}
void V(ll &x,ll y){x=(x+y)%mod;}
ll K(ll x,int y){ll t=1;for(;y;y>>=1,U(x,x))if(y&1)U(t,x);return t;}
ll jc[N<<1],inv[N<<1],ans=0,fl;
ll C(int x,int y){return x<y?0:jc[x] *inv[y]%mod *inv[x-y]%mod;}
void pre(int mx){jc[0]=1; for (int i=1;i<=mx;i++) jc[i]=jc[i-1]*i%mod;
	inv[mx]=K(jc[mx],mod-2); for (int i=mx;i>0;i--) inv[i-1]=inv[i]*i%mod;}


ll cal(int x,int y,int z){
	return !x? y+z==0: C(x+y+z-1,x-1);
}
void doit(int n,int m,char l[],char r[],char u[],char d[]){
	ll tmp; int cl=0,cr=0,cu=0,cd=0,nowu=0,nowd=0,uu,dd;
	for (int i=1;i<=n;i++) cl+=l[i]-'0',cr+=r[i]-'0';
	for (int i=1;i<=m;i++) cu+=u[i]-'0',cd+=d[i]-'0';
	fl=!cl&!cr&!cu&!cd;
	tmp=cal(cl,0,0);
	for (int i=1;i<=m;i++){
		nowu+=(uu=u[i]-'0'); nowd+=(dd=d[i]-'0');
		if (uu||dd){
			if (uu&&dd) U(tmp,2);
			V(ans,tmp*cal(cr,cu-nowu,cd-nowd));
			V(tmp,cal(cl,nowu,nowd));
		}
	}
}

char a[N],b[N],c[N],d[N];
int main(){
	pre(N*2-10); int n,m;
	scanf("%d%d%s%s%s%s",&n,&m,a+1,b+1,c+1,d+1);
	doit(n,m,a,b,c,d);
	doit(m,n,c,d,a,b);
	V(ans,fl);
	cout<<ans;
}

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

signed main() {
  int N; cin >> N;
  priority_queue<double, vector<double>, greater<double>> v;
  for(int i=0; i<N; i++) {int x; cin >> x; v.push(x);}

  while(v.size() > 1) {
    double x = v.top(); v.pop();
    double y = v.top(); v.pop();
    v.push((x+y)/2);
  }
  printf("%.6lf\n", v.top());
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,x,y,ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>s;
    if(s[0]!='A'||s[1]<'a'){
        cout<<"WA"<<endl;
    }else{
        for(int i=2;i<s.size()-1;i++){
            if(s[i]=='C'){
                cnt++;
            }
        }
        if(cnt!=1){
            cout<<"WA"<<endl;
            return 0;
        }
        for(int i=2;i<s.size()-1;i++){
            if(s[i]!='C'&&s[i]<'a'){
                cout<<"WA"<<endl;
                return 0;
            }
        }
        if(s[s.size()-1]<'a'){
            cout<<"WA"<<endl;
            return 0;
        }
        cout<<"AC"<<endl;
    }
}

Measured memory_bytes: 10412
io = STDIN
$n,m=io.gets.split.map(&:to_i)
$con=Hash.new{|h,k|h[k]=[]}
m.times do
  a,b=io.gets.chomp.split
  $con[a]<<b
  $con[b]<<a
end
def dfs(n,hist)
  return 1 if hist.size==$n
  ans=0
  $con[n].each do |to|
    ans += dfs(to,hist+[to]) unless hist.include?(to)
  end
  ans
end
puts dfs("1",["1"])

Measured memory_bytes: 1916
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<vector>
using namespace std;
double  i,j,k,h,w,a,b,c,d,x,y,z,t,ret;
int main(void){
  cin>>t>>x;
  cout<<t/x;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

const int mod=1000000007;
struct mint{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const{return mint(-x);}
  mint& operator+=(const mint a){
    if((x+=a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x+=mod-a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=mod;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a=pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }

  // for prime mod
  mint inv() const{
    return pow(mod-2);
  }
  mint& operator/=(const mint a){
    return (*this)*=a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

struct Eratosthenes{
  int n;
  vector<int> f,primes;
  Eratosthenes(int n=1):n(n),f(n+1){
    f[0]=f[1]=-1;
    for(ll i=2;i<=n;++i){
      if(f[i]) continue;
      primes.push_back(i);
      f[i]=i;
      for(ll j=i*i;j<=n;j+=i){
        if(!f[j]) f[j]=i;
      }
    }
  }
  bool isPrime(int x){return f[x]==x;}
  vector<int> factorList(int x){
    vector<int> res;
    while (x!=1){
      res.push_back(f[x]);
      x/=f[x];
    }
    return res;
  }
  vector<i_i> factor(int x){
    if(x<=0) return {};
    vector<int> fl=factorList(x);
    if(fl.size()==0) return {};
    vector<i_i> res(1,i_i(fl[0],0));
    for(int p:fl){
      if(res.back().first==p){
        res.back().second++;
      } else{
        res.emplace_back(p,1);
      }
    }
    return res;
  }
};

int main(){
  int N; cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  Eratosthenes sieve(1e6);
  map<int,int> mp;
  rep(i,N){
    vector<i_i> f=sieve.factor(a[i]);
    for(auto c:f){
      mp[c.first]=max(c.second,mp[c.first]);
    }
  }
  mint lcm=1;
  for(auto c:mp){
    rep(i,c.second){
      lcm*=c.first;
    }
  }
  mint ans=0;
  rep(i,N){
    ans+=lcm/a[i];
  }
  cout << ans.x << endl;
}

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

using namespace std;

#define rep0(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repU(i,bottom,ceiling) for(int (i)=(bottom);(i)<=(ceiling);(i)++)
#define repD(i,ceiling,bottom) for(int (i)=(ceiling);(i)>=(bottom);(i)--)
#define V vector
#define Vi vector<int>
#define VVi vector<vector<int>>
#define Vdb vector<double>
#define VVdb vector<vector<double>>
#define pub push_back
#define pob pop_back
#define pf printf
#define sf scanf
#define ci(a) cin>>a
#define lco(a) cout<<a<<endl
#define co(a) cout<<a
#define Vci(v) for(int i=0;i<v.size();i++) cin>>v[i]
#define Vco(v) for(int i=0;i<v.size();i++){ cout<<v[i]<<' '; } cout<<endl
#define P pair
#define Pii pair<int,int>
#define mP make_pair
#define fir first
#define sec second
#define Re return 

typedef long long ll;
typedef double db;

const string alphabet("abcdefghijklmnopqrstuvwxyz");
const vector<pair<int,int>> dir={{0,0},{1,0},{1,1},{0,1},{-1,1},{0,-1},{-1,-1},{0,-1},{1,-1}};
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const int Inf=(int)2e9+1e8;
const int Mod=(int)1e9+7;

template <typename T,typename U>                                                   
pair<T,U> operator+(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir+r.fir,l.sec+r.sec};                                    
} 

template <typename T,typename U> 
pair<T,U> operator-(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir-r.fir,l.sec-r.sec};                                    
} 

template <typename T,typename U>                                                   
pair<T,U> operator*(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir*r.fir,l.sec*r.sec};                                    
}

template <typename T,typename U>                                                   
pair<T,U> operator/(const pair<T,U> & l,const pair<T,U> & r) {   
    return {l.fir/r.fir,l.sec/r.sec};                                    
}

template <typename T> void Swap(T *x,T *y){ T tem=*x; *x=*y; *y=tem; }

long long int rem(long long int n,long long int m){
	if(!m) return 0;
	return (n<0?(n%m)+m:(n%m));
}
             
/*The main code follows below*/

int main(){
	ll n,now=0,M;
	char s[300005];
	ci(n>>s);
	rep1(i,n-1){
		now+=(s[i]=='E');
		M=now;
	}
	rep1(i,n-1){
		now+=((s[i-1]=='W')-(s[i]=='E'));
		M=min(M,now);
	}
   lco(M);
	return 0;
}

Measured memory_bytes: 512
N = int(input())
s = []
for i in range(N-1):
    C,S,F = map(int,input().split(" "))
    s.append([C,S,F])
for i in range(N):
    if i == N-1:
        print(0)
    else:
        time = 0
        for j in range(i,N-1):
            C,S,F = s[j]
            if time < S:
                time = S + C
            else:
                if (time-S)%F == 0:
                    time += C
                else:
                    time += (F - (time-S)%F)
                    time += C
        print(time)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);


		int N = sc.nextInt();
		int D = sc.nextInt();
		int ans;


		if(N/2 <= D) {
			ans = 1;
		}else if(N%(2*D+1) == 0){
			ans = N/(2*D+1);
		}else {
			ans = N/(2*D+1) + 1;
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 21716
n=int(input())
A=[]
for i in range(n):
    A.append(int(input()))

ans=0
for i in range(n-1):
    ans+=A[i]//2
    A[i]%=2
    if A[i]==1 and A[i+1]>0:
        ans+=1
        A[i+1]-=1

ans+=A[-1]//2
print(ans)

Measured memory_bytes: 12964
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int n;
int a[MAXN];
int X[2];
int H[2][MAXN];

int main()
{
	
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
	{
		scanf("%d", &a[i]);
		H[i%2][a[i]] ++;
	}
	int X[2], Y[2];
	for (int k = 0; k < 2; ++ k)
	{
		X[k] = Y[k] = 0;
		for (int i = 1; i <= 100000; ++ i)
		{
			if (H[k][i] > H[k][X[k]])
			{
				Y[k] = X[k];
				X[k] = i;
			}
			else if (H[k][i] > H[k][Y[k]])
				Y[k] = i;
		}
	}
	if (X[0] != X[1])
		cout << n/2-H[0][X[0]]+n/2-H[1][X[1]] << endl;
	else
		cout << min(n/2-H[0][X[0]]+n/2-H[1][Y[1]], n/2-H[0][Y[0]]+n/2-H[1][X[1]]) << endl;
	
	return 0;
}


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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    short c;
    cin >>c;
    bool cards[4][13];
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 13; j++){
            cards[i][j]=false;
        }
    }
    for (int i = 0; i < c; i++){
        char k;
        int n;
        cin >> k >> n;
        if(k=='S')cards[0][n-1]=true;
        else if(k=='H')cards[1][n-1]=true;
        else if(k=='C')cards[2][n-1]=true;
        else cards[3][n-1]=true;
    }
    for (int i = 0; i < 4; i++){
        for (int j = 1; j <= 13; j++){
            if(cards[i][j-1]==false){
                if(i==0)cout<<'S'<<' '<<j<<'\n';
                else if(i==1)cout<<'H'<<' '<<j<<'\n';
                else if(i==2)cout<<'C'<<' '<<j<<'\n';
                else cout<<'D'<<' '<<j<<'\n';
            }
        }
    }
}


Measured memory_bytes: 3124
n = int(input())
*l, = map(int,input().split())
suml = sum(l)
suml2 = sum([i**2 for i in l])
ave1 = suml//n 
ave2 = -(-suml//n)
ans1 = suml2 - 2*suml*ave1 + n*ave1*ave1
ans2 = suml2 - 2*suml*ave2 + n*ave2*ave2
print(min([ans1,ans2]))

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

n,x=intinput()
l=list(intinput())
d=[0]
for i in range(n):
    d.append(d[i]+l[i])
print([d[i]<=x for i in range(n+1)].count(True))

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

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

  int count = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '+') {
      count++;
    }
    else if (str.at(i) == '-'){
      count--;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) {
    cin >> a[i];
  }
  int tmp = 1;
  int cnt = 0;
  REP(i, n) {
    if (a[i] == tmp) {
      cnt++;
      tmp++;
    }
  }
  if (cnt == 0) {
    cout << - 1 << endl;
    return;
  }
  cout << n - cnt << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 1024
inf = float('inf')
# ベルマンフォード法
# 計算量O(VE) V:頂点数, E:辺の数
# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点
# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか
def bellmanford(n : int, edges : list, start : int, goal : int) -> (list, bool):
    dist = [inf] * n
    dist[start] = 0
    exist_negative_cycle = True

    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む
    for _ in range(N-1):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w


    # (1)グラフに負閉路が含まれるときの検出
    # N回目で更新があったとき、グラフは負閉路を含む
    # for v, nv, w in edges:
    #     if dist[nv] > dist[v] + w:
    #         is_cycle = False

    # (2)startとgoalのパスに負閉路が含まれるときの検出
    is_updated = [False] * n
    for _ in range(N):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                is_updated[nv] = True
            if is_updated[v] is True:
                is_updated[nv] = True

    exist_negative_cycle = is_updated[goal]

    return dist, exist_negative_cycle

N, M, P = map(int,input().split())
edges = []
for _ in range(M):
    A, B, C = map(int,input().split())
    A -= 1; B -= 1
    C = C - P
    edges.append((A, B, -C))

dist, exist_negative_cycle = bellmanford(N, edges, 0, N-1)

if exist_negative_cycle is True:
    ans = -1
else:
    ans = max(-dist[N-1], 0)

print(ans)

Measured memory_bytes: 48472
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

template<typename T> inline void chmax(T& t, T f){if(t < f)t = f;}

vector<string> split(const string& input, char delimiter){
    istringstream stream(input);
    string field;
    vector<string> result;
    while(getline(stream, field, delimiter))result.push_back(field);
    return result;
}

int main(){
    int n;
    while(cin >> n, n){
        typedef pair<vector<string>, vector<string> > Time;
        vector<Time> table;
        rep(i, n){
            string s, t;
            cin >> s >> t;
            table.emplace_back(split(s, ':'), split(t, ':'));
        }
        sort(all(table));
        int ans = 1;
        rep(i, n){
            chmax(ans, 1 + (int)count_if(table.begin(), table.begin() + i,
                        [&](Time& t){return table[i].first < t.second;}));
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 5320
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        double W = sc.nextDouble();
        Double H = sc.nextDouble();
        Double x = sc.nextDouble();
        Double y = sc.nextDouble();

        if(x==W/2 && y==H/2){
            System.out.println(W * H / 2 + " " + 1);
        }
        else{
            System.out.println(W * H / 2 + " " + 0);
        }
    }
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v{a, b, c};
  sort(v.begin(), v.end());
  if(v[0]+v[1] == v[2]) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[3];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  fill(a, a + 3, 0);
  REP(i, n) {
    int b;
    cin >> b;
    int sum = 0;
    while (b % 2 == 0 && b / 2) {
      b /= 2;
      sum++;
      if(sum >= 2) break;
    }

    a[sum]++;
  }

  bool f = false;
  if(a[1] > 0) {
    if(a[2] >= a[0]) f = true;
  } else {
    if(a[2] + 1 >= a[0]) f = true;
  }

  cout << (f ? "Yes" : "No") << endl;
}


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

int f(string x){
	int ret = 0;
	for(auto &c:x) ret += c - '0';
	return ret;
}

int main(){
	string x; cin>>x;
	cout<< (stoi(x) % f(x)? "No":"Yes") <<endl;
}


Measured memory_bytes: 3632
#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<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
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;
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 pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	char a, b; cin >> a >> b;
	if (a < b)cout << "<" << endl;
	else if (a > b)cout << ">" << endl;
	else cout << "=" << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
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 debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}
// multimap
// mmap.emplace(key,value);
// auto ngw = list.equal_range("");
// for(auto e = ngw.first; it != ngw.second ; ++e)

struct SegmentTree{
private:
    ll unit = 0;
    ll op(ll a,ll b){return a ^ b;}
    ll n;
    vector<ll> node;

public:
SegmentTree(vector<ll> v){
    ll sz = (ll)v.size();
    n = 1;while(n<sz) n *= 2;
    node.resize(2*n-1,unit);
    for(ll i=0;i<sz;i++) node[i+n-1]=v[i];
    for(ll i=n-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
}

    void update(ll x,ll val){
        x += n-1;
        node[x] += val;
        while(x>0){
            x = (x-1)/2;
            node[x] = op(node[2*x+1],node[2*x+2]);
        }
    }

    ll query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
        if (r<0) r = n;
        if (r<=a || b<=l) return unit;
        if (a<=l && r<=b) return node[k];
        ll vl = query(a,b,2*k+1,l,(l+r)/2);
        ll vr = query(a,b,2*k+2,(l+r)/2,r);
        return op(vl,vr);
    }
};
vl s(200005,0);
ll vq(ll l, ll r){
    return s[r] - s[l];
}
int main(){
    ll N; cin >> N;
    vl a(N); rdv(a);
    rep(i,N){
        s[i+1] = s[i] + a[i];
    }
    ll ans = 0; 
    SegmentTree t(a);
    ll l = 0, r = 1;
    while(r < N+1){
        if(t.query(l,r) == vq(l,r)){
            ans += r-l;
            ++r;
        }else{
            ++l;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <cstdio>
#include <algorithm>
#define max(a,b)a>b?a:b

int ans[100070];
int R(){
	int x=0;char ch;
	do{ch=getchar();}while(ch>57||ch<48);
	do{x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}while(ch>=48&&ch<=57);
	return x;
}
void W(int c){
	if(c>9)W(c/10);
	putchar('0'+c%10);
}

char ch[1000000];

signed main(){
	int n=R(),m=R(),p,i,now;
	scanf("%s",ch);
	now=n;
	i=n;
	p=m;
	while(i>m){
		
		while(ch[i-p]=='1'){
			p--;
			if(p==0)
				break;
		}
		if(p==0)
			break;
		ans[now--]=p;
		i-=p;
		p=m;
	}
	if(p==0){
		printf("-1");
	}
	else{
		printf("%d ",i);
		for(int i=now+1;i<=n;i++){
			printf("%d ",ans[i]);
		}
	}
}

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



void solve() {
    int n;
    cin >> n;
    while (1) {
        int flg = 0;
        int nn = n;
        int ans = nn % 10;
        // cout << "ans " << nn << " " << ans << endl;
        nn /= 10;
        while (nn) {
            if (ans != nn % 10) {
                // cout << nn << endl;
                flg = 1; break;
            }
            nn /= 10;
        }
        if (flg == 0) {
            cout << n << endl;
            return;
        }
        n++;
    }
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}




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

int main()
{
	int N;
	scanf("%d", &N);

	int i, j, count, result;
	for (i = N, result = 0; i > 0; i--) {
		if (i % 2 == 0)
			continue;
		for (j = N, count = 0; j > 0; j--) {
			if (i % j == 0)
				count++;
		}
		if (count == 8)
			result++;
	}

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

	return 0;
}


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  double n;
  cin >> n;
  cout << ceil(n / 111) * 111 << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    int x,y,w,h,r;
    cin >> w >> h >> x >> y >> r;
     
    if((x<=w-r)&&(x>=r)&&(y<=h-r)&&(y>=r )) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3100
while True:
    v = input().split()
   
    if v[1] == "?": break
    if v[1] == "+":
        print(int(v[0]) + int(v[2]))
    if v[1] == "-":
        print(int(v[0]) - int(v[2]))
    if v[1] == "*":
        print(int(v[0]) * int(v[2]))
    if v[1] == "/":
        print(int(v[0]) // int(v[2]))

Measured memory_bytes: 7684
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

double dp[301][301][301];
int N;

double rec(int i,int j,int k) {
    if(dp[i][j][k] >= 0)
        return dp[i][j][k];

    if(i == 0 && j == 0 && k == 0)
        return 0.0;

    double res = 0.0;
    if(i > 0)
        res += rec(i-1,j,k)*i;
    if(j > 0)
        res += rec(i+1,j-1,k)*j;
    if(k > 0)
        res += rec(i,j+1,k-1)*k;

    res +=  N;
    res *= 1.0 / (i+j+k);

    return dp[i][j][k] = res;
}

int main(void) {
    cin>>N;

    int one,two,three;
    one = 0;
    two = 0;
    three = 0;

    for(int i = 0;i < N;i++) {
        int a;
        cin>>a;
        if(a == 1)
            one++;
        else if(a == 2)
            two++;
        else
            three++;
    }

    memset(dp,-1,sizeof(dp));

    cout<<fixed<<setprecision(10)<<rec(one,two,three)<<endl;

    return 0;
}

    



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

int main(){
  int N;
  cin >> N;
  int x;
  if(N%2==0)x = N/2;
  if(N%2==1)x = N/2+1;
  cout << fixed << setprecision(10) << (double)x/N << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=310;
ll a[N][N],mark[N],freq[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    ll ans = N;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(ll k=1;k<=m;k++){
        memset(freq,0,sizeof(freq));
        for(ll i=1;i<=n;i++){
            ll j=1;
            for(;mark[a[i][j]]==1;j++);
            freq[a[i][j]]++;
        }
        ll maxx=0,maxi;
        for(ll i=1;i<=m;i++){
            if(freq[i]>maxx){
                maxx=freq[i];
                maxi=i;
            }
        }

        ans=min(ans , maxx);
        mark[maxi]=1;
    }

    cout<<ans;
}



Measured memory_bytes: 1024
N, M = (int(x) for x in input().split())
Lmax = -1
Rmin = N + 1
for i in range(M):
    L, R = (int(x) for x in input().split())
    if Lmax < L:
        Lmax = L
    if Rmin > R:
        Rmin = R
if (Rmin - Lmax) >= 0:
    print(Rmin - Lmax + 1)
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K,N;
  cin >>K>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int max=0;
  for(int i=1;i<N;i++){
    if(A.at(i)-A.at(i-1)>max)
      max=A.at(i)-A.at(i-1);
  }
  if(A.at(0)-A.at(N-1)+K>max)
    max=A.at(0)-A.at(N-1)+K;
  cout << K-max << endl;
}
    
    

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#define MAX 44

int main(){
  int n;
  int F[50];
  F[0] = F[1] = 1;
  
  cin >> n;

  for(int i=2;i<n+1;i++){
    F[i]=F[i-1]+F[i-2];
  }

  cout << F[n] << endl;

  return 0;
}



Measured memory_bytes: 3084
// Range Sum Query

#include <iostream>
#include <algorithm>

using namespace std;

int n, q, sum[1 << 20];

void add(int t, int l, int r, int p, int x) {
	sum[t] += x;
	if (l == r)
		return;
	int mid = (l + r) / 2;
	if (p <= mid)
		add(t << 1, l, mid, p, x);
	else
		add(t << 1 | 1, mid + 1, r, p, x);
}

int getsum(int t, int l, int r, int x, int y) {
	if (x <= l && r <= y)
		return sum[t];
	if (x > r || y < l)
		return 0;
	int mid = (l + r) / 2;
	return
		getsum(t << 1, l, mid, x, y) + 
		getsum(t << 1 | 1, mid + 1, r, x, y);
}

int main() {
	cin >> n >> q;
	for (int i = 0; i < q; ++i) {
		int k, x, y;
		cin >> k >> x >> y;
		if (k == 0)
			add(1, 1, n, x, y);
		else
			cout << getsum(1, 1, n, x, y) << endl;
	}
	return 0;
}


Measured memory_bytes: 4132
#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

signed main()
{
   faster;
  // #ifndef ONLINE_JUDGE
    // freopen("ip.txt", "r", stdin);
    // freopen("op.txt", "w", stdout);
   //#endif
     //int t;cin>>t;
     //while(t--)
     {
          int n;
          cin>>n;
          int a[n],b[n],c[n];
          for (int i=0;i<n;i++)
               cin>>a[i]>>b[i]>>c[i];
          int dp[n][3];
          dp[0][0]=a[0];
          dp[0][1]=b[0];
          dp[0][2]=c[0];
          for (int i=1;i<n;i++)
          {
               dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
               dp[i][1]=max(dp[i-1][2],dp[i-1][0])+b[i];
               dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
          }
          cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
     }
}

Measured memory_bytes: 2560