akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn get_adjacents_and_diagonal(x: usize, y: usize, w: usize, h: usize) -> Vec<(usize, usize)> {
    let mut adjacents = vec![];
    if x > 0 {
        if y > 0 {
            adjacents.push((x - 1, y - 1));
        }
        adjacents.push((x - 1, y));
        if y < h - 1 {
            adjacents.push((x - 1, y + 1));
        }
    }
    if y > 0 {
        adjacents.push((x, y - 1));
    }
    adjacents.push((x, y));
    if y < h - 1 {
        adjacents.push((x, y + 1));
    }
    if x < w - 1 {
        if y > 0 {
            adjacents.push((x + 1, y - 1));
        }
        adjacents.push((x + 1, y));
        if y < h - 1 {
            adjacents.push((x + 1, y + 1));
        }
    }
    adjacents
}

fn main() {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut grid = vec![];
    for i in 0..h {
        grid.push(read::<String>().chars().collect::<Vec<_>>());
    }
    for y in 0..h {
        for x in 0..w {
            if grid[y][x] == '#' {
                continue;
            }
            let adjacents = get_adjacents_and_diagonal(x, y, w, h);
            let mut count = 0;
            for (ax, ay) in adjacents {
                if grid[ay][ax] == '#' {
                    count += 1;
                }
            }
            grid[y][x] = std::char::from_digit(count, 36).unwrap();
        }
    }
    for y in 0..h {
        for x in 0..w {
            print!("{}", grid[y][x]);
        }
        println!("");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <limits.h>
#include <math.h>
#include <string>
#include <vector>
#include <map>
using namespace std;

int inf = 1e9 + 7;

int main(void){
    int n, m, a[1010], b[1010];
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    
    int x[1000010];
    for (int i = n * m; i > 0; i--) {
        int tat = inf, yok = inf;
        int tatx = 0, yokx = 0;
        int taty = 0, yoky = 0;
        for (int j = 0; j < n; j++) {
            if (a[j] == i) {
                tat = j;  taty++;
            }
            if (a[j] > i) tatx++;
        }
        for (int j = 0; j < m; j++) {
            if (b[j] == i) {
                yok = j;  yoky++;
            }
            if (b[j] > i) yokx++;
        }
        
        if (taty > 1 || yoky > 1) {
            cout << 0 << endl;
            return 0;
        }
        if (tat < inf && yok < inf) x[i] = 1;
        else if (tat < inf) {
            x[i] = yokx;
        }
        else if (yok < inf) {
            x[i] = tatx;
        }
        else {
            x[i] = tatx * yokx - (n * m - i);
        }
    }
    
    long long ans = 1;
    for (int i = 1; i <= n * m; i++) {
        ans *= x[i];
        if (ans >= inf) ans = ans % inf;
        //cout << i << " " << x[i] << " " << ans << endl;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 4096
#include<stdio.h>

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

  if(n==1){
    printf("Hello World\n");
    return 0;
  }
  else if(n==2){
    int a,b;
    scanf("%d", &a);
    scanf("%d", &b);
    printf("%d\n", a+b);
    return 0;
  }

  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

St = sum(A)
for T in range(0,N):
    if A[T]+A[T+1]<= B[T]:
        A[T] = 0
        A[T+1] = 0
    if A[T]<=B[T]<A[T]+A[T+1]:
        A[T+1] = A[T+1]-(B[T]-A[T])
        A[T] = 0
    if B[T]<A[T]:
        A[T] = A[T]-B[T] 
print(St-sum(A))

Measured memory_bytes: 25392
#include <stdio.h>

int main()
{
    int n, m;
    int k, a;
    int ans = 0;
    int dat[35] = {};

    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf("%d", &k);

        for (int j = 0; j < k; j++) {
            scanf("%d", &a);

            dat[a]++;

        }
    }

    for (int i = 1; i <= m; i++) {
        if (dat[i] == n) {
            ans++;
        }
    }

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


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,sum=0,a[1000];
    cin>>n;
    for(int i=0;i<n-1;i++)
        {

            cin>>a[i];

        }
        sum=sum+a[0]+a[n-2];
        for(int i=1;i<n-1;i++)
            sum=sum+min(a[i],a[i-1]);
        cout<<sum;

}


Measured memory_bytes: 256
mod = 10**9 + 7
n,m = map(int,input().split())
dp = [1] * (n+1)
for _ in range(m):
    a = int(input())
    dp[a] = 0
for i in range(0,n-1):
    dp[i+2] = dp[i+2] * (dp[i+1] + dp[i])%mod
print(dp[-1])


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

void we_r_done(){cout<<"NO"; exit(0);}

void debug(string mssg){cout<<mssg; exit(0);}

using minHeap = priority_queue< int, vector< int >, greater< int > >;



int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;

    int n;
    scn(n);
    int a[n+1];

    for(int i=1; i<=n; i++)scn(a[i]);

    lli cum[n+1];
    cum[0] = 0;

    for(int i=1; i<=n; i++) cum[i] = cum[i-1] + a[i];

    #define rsum(lo,hi) cum[hi]-cum[lo-1]
    lli dp[n+1][n+1];
    dp[0][0] = inf*1LL*inf;
    for(int L=1; L<=n; L++){

        for(int i=1 ; (i+L-1)<=n; i++){

            int j = i+L-1;

            if(L==1) dp[i][j] = 0;
            else{
                dp[i][j] = dp[0][0];
                for(int k=i ; k<j; k++) dp[i][j] = min(dp[i][j] ,dp[i][k]+dp[k+1][j]+rsum(i,k)+ rsum(k+1,j));
            }
        }
    }
    cout<<dp[1][n];
    return 0;

}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)
///using bs = bitset<MX>; // how many distinct number can be form?


Measured memory_bytes: 1536
#include <iostream>
#include <cstring>
using namespace std;
string s;
int main()
{
    getline(cin,s);
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='C')
        {
            for(int j=i+1;j<s.size();j++)
            {
                if(s[j]=='F')
                {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace _0584
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] a = new string[n];
            int[] ret = new int[] { int.MaxValue,int.MaxValue,int.MaxValue };
            for (int i = 0; i < n; i++) a[i] = Console.ReadLine();
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    if (i == j) continue;
                    int x = int.Parse(a[i] + a[j]);
                    if (ret[2] > x) ret[2] = x;
                    if (ret[1] > x)
                    {
                        ret[2] = ret[1];
                        ret[1] = x;
                    }
                    if (ret[0] > x)
                    {
                        ret[1] = ret[0];
                        ret[0] = x;
                    }
                }
            }
            Console.WriteLine(ret[2]);
        }
    }
}


Measured memory_bytes: 9744
#include <bits/stdc++.h>
using namespace std;
int main(void){
    double x1,y1,x2,y2,a,b;
    double c;
    cin >> x1 >> y1 >> x2 >> y2;
    a = x2 - x1;
    b = y2 - y1;
    c = sqrt(a*a + b*b);
    printf("%.8f",c);
}



Measured memory_bytes: 3180
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<iostream>
#include<string>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define REP(i,x) for (int i=0;i<x;i++)
#define REPP(i,x,y) for (int i=x;i<=y;i++)
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define MX3(x,y,z) max(x,max(y,z))
#define MX4(x,y,z,p) max(x,max(y,max(z,p)))
#define MX5(x,y,z,p,q) max(x,max(y,max(z,max(p,q))))
#define MN3(x,y,z) min(x,min(y,z))
#define MN4(x,y,z,p) min(x,min(y,min(z,p)))
#define MN5(x,y,z,p,q) min(x,min(y,min(z,min(p,q))))
#define amax(x,y) x=max(x,y)
#define amin(x,y) x=min(x,y)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef tuple<int,int,int> ti;
typedef tuple<ll,ll,ll> tl;
// #####################################################################

int tb[10] = {0,2,5,5,4,5,6,3,7,6};

void solve() {

    int n, m;
    SI(n); SI(m);
    vi rec(m);
    REP(i, m) {
        SI(rec[i]);
    }
    sort(rec.begin(), rec.end());
    vi dp(n+1, 0);
    vi val(n+1, 0);
    for(auto t: rec) {
        REPP(i, 0, n-tb[t]) {
            if(i==0 || dp[i]>0) {
                int ss = dp[i]+1;
                int yy = t;
                if(ss == dp[i+tb[t]]) val[i+tb[t]] = max(val[i+tb[t]], yy);
                else if(ss > dp[i+tb[t]]) {
                    dp[i+tb[t]] = ss;
                    val[i+tb[t]] = yy;
                }
            }
        }
    }
    string recover = "";
    int tmp = n;
    while(tmp > 0) {
        recover += val[tmp] + '0';
        tmp -= tb[val[tmp]];
    }
    sort(recover.begin(), recover.end(), greater<char>());
    cout << recover << endl;
}

void init() {
    


}

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




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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k, q;
  cin >> k >> q;
  
  vector<int> d(k);
  for(int i = 0; i < k; i++) cin >> d.at(i);
  
  for(int i = 0; i < q; i++){
    int n, x, m;
    cin >> n >> x >> m;
    
    vector<int> v(k);
    for(int j = 0; j < k; j++) v.at(j) = d.at(j) % m;
    
    int ans = n - 1;
    int full = (n - 1) / k, res = (n - 1) % k;
    
    int eq = 0;
    for(int j = 0; j < k; j++){
      if(v.at(j) == 0) eq++;
    }
    eq *= full;
    for(int j = 0; j < res; j++){
      if(v.at(j) == 0) eq++;
    }
    
    long long sum = 0;
    for(int j = 0; j < k; j++) sum += v.at(j);
    sum *= full;
    for(int j = 0; j < res; j++) sum += v.at(j);
    sum += x;
    int dim = (sum / m) - (x / m);
    
    ans -= eq + dim;
    cout << ans << '\n';
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>//"lower_bound(it,it,v)", "next_permutation(a,a+n)"
using namespace std;
#define pb push_back//Can be used for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.
typedef pair<pii,pii> ppp;

#define INF 300000

template<class M>
struct MonoidSegTree {
  int n;
  int size;
  vector<M> seg;

  MonoidSegTree(const vector<M> A) {
    n = A.size();
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size);
    fill(seg.begin(),seg.end(),mp(INF,INF));
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size*2);
    fill(seg.begin()+size+n,seg.end(),mp(INF,INF));
    for (int i=size-1; i>0; --i){
    	if(seg[i*2].fi<seg[i*2+1].fi) seg[i]=seg[i*2];
    	else seg[i]=seg[i*2+1];
    }
  }

  void Update(int k, const M v) {
    k += size;
    seg[k] = v;
    while (k > 1) {
      k /= 2;
	  if(seg[k*2].fi<seg[k*2+1].fi) seg[k]=seg[k*2];
      else seg[k]=seg[k*2+1];
    }
  }

  M Get(int l, int r) {//半開区間
    M retl = mp(INF,INF);
    M retr = mp(INF,INF);
    l += size;
    r += size;
    for (; l < r;l>>=1,r>>=1) {
      if (r & 1) if(seg[--r].fi<retr.fi) retr=seg[r];
      if (l & 1){
      	if(seg[l].fi<retl.fi) retl=seg[l];
      	++l;
      }
    }
    if(retl.fi<retr.fi) return retl;
    else return retr;
  }

  M At(int k) {
    return seg[k+size];
  }
};

struct cmp{
	bool operator()(const ppp& p,const ppp& q) const{
		return p.sc.fi>q.sc.fi;
	}
};

int main(){
	int n;
	cin>>n;
	vector<pii> ep(n),op(n);
	for(int i=0;i<n;++i){
		if(i&1){
			ep[i].fi=INF;
			cin>>op[i].fi;
		}else{
			cin>>ep[i].fi;
			op[i].fi=INF;
		}
		ep[i].sc=i;
		op[i].sc=i;
	}
	MonoidSegTree<pii> eseg(ep),oseg(op);
	priority_queue<ppp,vector<ppp>,cmp> q;
	q.push(mp(mp(0,n),eseg.Get(0,n)));
	for(int i=0;i<n/2;++i){
		cout<<q.top().sc.fi<<" ";
		pii s=q.top().fi;
		int j=q.top().sc.sc;
		q.pop();
		if(s.fi!=j){
			if(j&1) q.push(mp(mp(s.fi,j),oseg.Get(s.fi,j)));
			else q.push(mp(mp(s.fi,j),eseg.Get(s.fi,j)));
		}
		pii v;
		if(j&1) v=eseg.Get(j+1,s.sc);
		else v=oseg.Get(j+1,s.sc);
		cout<<v.fi;
		if(i!=n/2) cout<<" ";
		int k=v.sc;
		if(j+1!=k){
			if(j&1) q.push(mp(mp(j+1,k),eseg.Get(j+1,k)));
			else q.push(mp(mp(j+1,k),oseg.Get(j+1,k)));
		}
		if(k+1!=s.sc){
			if(k&1) q.push(mp(mp(k+1,s.sc),eseg.Get(k+1,s.sc)));
			else q.push(mp(mp(k+1,s.sc),oseg.Get(k+1,s.sc)));
		}
	}
	cout<<endl;
}

Measured memory_bytes: 16484
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)

typedef vector<ll> vec;
typedef vector<vec> mat;

const ll MOD = 1000000009ll;

mat mul(mat &A,mat &B)
{
	mat C(A.size(),vec(B[0].size()));
	for(int i=0;i<A.size();i++)
	{
		for(int k=0;k<B.size();k++)
		{
			for(int j=0;j<B[0].size();j++)
			{
				C[i][j]=(C[i][j]+A[i][k]*B[k][j])%MOD;
			}
		}
	}
	return C;
}

mat pow(mat A, ll n)
{
	mat B(A.size(),vec(A.size()));
	for(int i=0;i<A.size();i++)
	{
		B[i][i]=1ll;
	}
	while(n>0)
	{
		if(n&1)B = mul(B,A);
		A = mul(A,A);
		n >>= 1;
	}
	return B;
}
P obs[40];
void print(mat A)
{
	/*for(int i=0;i<A.size();i++)
	{
		for(int j=0;j<A[0].size();j++)
		{
			cout << A[i][j] << ' ';
		}
		cout << endl;
	}*/
	cout << A.size() << ' ' << A[0].size() << endl;
	cout << endl;
}
int main()
{
	int t = 0;
	while(1)
	{
		int W,N;
		ll H;
		scanf("%d %lld %d",&W,&H,&N);
		if(W==0&&H==0ll&&N==0)break;
		for(int i=0;i<N;i++)scanf("%d %lld",&obs[i].sec,&obs[i].fi);
		sort(obs,obs+N);
		mat A(W,vec(W));
		for(int i=0;i<W;i++)
		{
			int l = i-1,r = l+3;
			l = max(0,l);
			r = min(r,W);
			for(int j=l;j<r;j++)A[i][j]=1;
		}
		//print(A);
		mat cur(1,vec(W));
		cur[0][0]=1ll;
		vector<ll> v;
		for(int i=0;i<N;i++)v.pb(obs[i].fi);
		v.pb(H);
		ll curh = 1ll;
		//print(cur);
		for(int i=0;i<v.size();i++)
		{
			mat k = pow(A,v[i]-curh);
			//print(k);
			cur = mul(cur,k);
			//print(cur);
			curh = v[i];
			if(i<N)cur[0][obs[i].sec-1]=0ll;
		}
		printf("Case %d: %lld\n",++t,cur[0][W-1]);
	}
	return 0;
}

Measured memory_bytes: 1392
#include<stdio.h> 
int main(void){ int a,b,c,i; scanf("%d%d%d",&a,&b,&c); if(a>b){ i=a; a=b; b=i; } if(b>c){ i=b; b=c; c=i; } if(a>b){ i=a; a=b; b=i; } printf("%d %d %d\n",a,b,c); return 0; } 




 



Measured memory_bytes: 2048
import math
def fib(number):
    a, b = 0, 1
    for _ in range(number):
        a, b = b, a + b
    return b
N, M = map(int, input().split())
a = []
ans = 1
tmp = 0
for _ in range(M):
    a.append(int(input()))
for i in a:
    number = i-tmp
    if i == 1:
        tmp = 2
        continue
    else:
        if number<1:
            print(0)
            exit()
        else:
            ans *= fib(number-1)
            tmp = i+1
print((ans*fib(N-tmp))%1000000007)


Measured memory_bytes: 7080
#include<stdio.h>
int main(){
 int n,moto;
 int i,min=10000,count=0,donut;
 scanf("%d %d",&n,&moto);
 for(i=1;i<=n;i++){
  scanf("%d",&donut);
  moto-=donut;
  if(donut<min) min=donut;
count++;
}
while(moto>=min){
 count++;
 moto-=min;
}
printf("%d",count);
 return 0;
}


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

int main(){ 
    string s;cin>>s;
    int c0=0,c1=0;
    for(auto e:s){
        if(e=='0')c0++;
        else c1++;
    }
    int ans = min(c0,c1);
    cout << ans*2 << endl;
    return 0;
}

Measured memory_bytes: 1020
import sys
n = int(input())
a = list(map(int, input().split()))


for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] %5 == 0:
            pass
        else:
            print('DENIED')
            sys.exit()
    else:
        pass

print('APPROVED')

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

int main() { 
    long long int h, ans = 0;
    cin >> h;
    long long int i = 1;
    while(h > 0) {
        h /= 2;
        ans += i;
        i *= 2; 
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
const int N = 2e3+ 2, mod = 998244353;


void solve() {
     ll n, x, m;
     cin >> n >> x >> m;
     vector<int> cnt(m);
     ll ans = 0;
     vector<int> b;
     ll l = 0;
     for(int i = 0; i < n; i++) {
          if(cnt[x] != 0) {
               break;
          } else {
               b.push_back(x);
               cnt[x]++;
          }
          ans += x;
          // cout << x << ' ';
          l++;
          x = (x*x)%m;
     }
     // ans += x;
     // cout << x << '\n';
     ll sz = b.size();
     vector<ll> a;
     ll s = 0;
     int id = sz;
     for(int i = 0; i < sz; i++) {
          if(b[i] == x) {
               id = i;
               break;
          }
     }
     for(int i = id; i < sz; i++) {
          s += b[i];
          // cout << s << " ";
          a.push_back(s);
     }
     sz = a.size();
     if(!sz) {
          cout << ans << '\n';
          return;
     }
     n -= l;
     ans += (n/sz)*s;
     int y = (n % sz) - 1;
     if(y >= 0) {
          ans += a[y];
     }
     cout << ans << '\n';
}    


int main() {
	int tt = 1;
	// cin >> tt;
	for (int tc = 1; tc <= tt; tc++) {
		// cout << "Case #:" << tc << " ";
		solve();
	}
}

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


int main(){
	
	int h,a;
	cin>>h>>a;
	int x;
	int total=0;
	for(int i=0;i<a;i++){
		cin>>x;
		total += x;
		if(total>=h){
			cout<<"Yes";
			return 0;
		}
		
	}

	cout<<"No";

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n,k;
    cin >> n >> k;
    int r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int dp[n+1][3]={0};
    for (int i=0;i<n;i++){
        //得点を考えずに前回の最大値を入れる
        for (int j=0;j<3;j++){
            int nax;
            nax=max(dp[i][0],dp[i][1]);
            nax=max(nax,dp[i][2]);
            dp[i+1][j] = nax;
        }
        
        //チョキのとき
        if(t.at(i) == 's') {

            if(i-k>=0 && t.at(i-k)=='s') {
                t.at(i)='x';
                continue;
            }
            dp[i+1][1]=dp[i+1][1]+r;
        }
        //パーのとき
        if(t.at(i) == 'p' ) {
            if(i-k>=0 && t.at(i-k)=='p') {
                t.at(i)='x';
                continue;
            }
            dp[i+1][2]=dp[i+1][2]+s;
        }
        //グーのとき
        if(t.at(i) == 'r'){
            if(i-k>=0 && t.at(i-k)=='r') {
                t.at(i)='x';
                continue;
            }
            dp[i+1][0]=dp[i+1][0]+p;
        }
    }
    int nax =-INF;
    for (int i=0;i<3;i++){
        nax = max(nax,dp[n][i]);
        // cout << dp[i][0] << dp[i][1] << dp[i][2] << endl;
    }
    cout <<  nax << endl;
    return 0;
}

Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,x;
  cin>>n>>x;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];
  int ans=1;
  int sum=0;
  rep(i,n){
    sum += vec[i];
    if(sum<=x) ans++;
    else break;
  }
    
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;

using Graph = vector<vector<int>>;
int N;
Graph G;

void rec(int v, int p, int c, vector<int> &one, vector<int> &two) {
    if (c == 0) one.push_back(v);
    else two.push_back(v);
    for (auto ch: G[v]) {
        if (ch == p) continue;
        rec(ch, v, 1-c, one, two);
    }
}
vector<int> solve() {
    vector<int> one, two;
    rec(0, -1, 0, one, two);

    vector<int> res(N, -1);
    if (one.size() > (N/3) && two.size() > (N/3)) {
        for (int i = 0; i < one.size(); ++i) if (i < (N+2)/3) res[one[i]] = i*3+1;
        for (int i = 0; i < two.size(); ++i) if (i < (N+1)/3) res[two[i]] = i*3+2;
        int cur = 3;
        for (int i = 0; i < N; ++i) if (res[i] == -1) res[i] = cur, cur += 3;
        return res;
    } else {
        int num_one = 0, num_two = 0, num_three = 0;
        if (one.size() <= (N/3)) {
            for (int i = 0; i < one.size(); ++i) {
                res[one[i]] = (num_three++) * 3 + 3;
            }

        } else {
            for (int i = 0; i < two.size(); ++i) {
                res[two[i]] = (num_three++) * 3 + 3;
            }
        }

        for (int i = 0; i < N; ++i) {
            if (res[i] != -1) continue;
            if (num_one < (N+2)/3) res[i] = (num_one++) * 3 + 1;
            else if (num_two < (N+1)/3) res[i] = (num_two++) *3 + 2;
            else res[i] = (num_three++) * 3 + 3;
        }


        return res;

    }
}



int main(){
    while (cin >> N) {
        G.assign(N, vector<int>());
        for (int i = 0; i < N-1; ++i) {
            int a, b; cin >> a >> b; --a; --b;
            G[a].push_back(b), G[b].push_back(a);
        }

        const auto& res = solve();
        for (auto v: res) cout << v << " ";
        cout << endl;
    }
}

Measured memory_bytes: 22300
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int tmp = n;
		int sum = 0;
		while ( tmp > 0) {
			sum += tmp % 10;
			tmp /= 10;
		}
		if ( n % sum == 0 ) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define rem(i,n,x) for(int i=(n);i>=(x);--i)
#define SORT(x) sort(x.begin(),x.end())
#define pb push_back
using ll = long long;

vector <ll> divisor(ll n) {
	vector<ll> ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.pb(i);
			if (i * i != n) ret.pb(n / i);
		}
	}
	SORT(ret);
	return ret;
}

int main() {
	ll a, b; cin >> a >> b;

	vector<ll> div = divisor(min(a, b));
	vector<ll> ans;
	rep(i, 0, div.size()) {
		if (max(a, b) % div[i] == 0) ans.pb(div[i]);
	}
	vector<ll> p; p.pb(ans[0]);
	if (ans.size() > 1)p.pb(ans[1]);
	bool f = true;
	rep(i, 1, ans.size()) {
		rep(j, 1, p.size()) {
			if (ans[i] % p[j] == 0) {
				f = false;
				break;
			}
		}
		if (f) p.pb(ans[i]);
      	f = true;
	}

	cout << p.size() << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define N 100010
using namespace std;
using Int = long long;
Int n,m,A[N];

Int calcL(Int x,Int l,Int s){return max(1LL,x-abs(l-s));}

Int calc(Int x){
  Int level = 1;
  Int res = 0;
  while(1){
    //    cout<<level<<endl;
    res++;
    if(level+x>A[n-1]) return res;
    Int a = lower_bound(A,A+n,level) - A;
    Int b = a - 1;
    Int nlevel = -1;
    //Int win = 0;
    if(a<n && level+x > A[a]) nlevel = level+calcL(x,level,A[a]);
    if(b >= 0) nlevel = max(nlevel,level+calcL(x,level,A[b]));
    //if(nlevel == -1) return -1;
    assert(nlevel != -1);
    //if((a == n-1 && win ) || b == n-1) return res;
    level = nlevel;
  }
}

Int search(){
  Int L=A[0],M=0,R =1e12;
  if(calc(L)<m) return -1;
  while(L+1<R){
    M = (L+R)/2;
    //cout<<m<<":"<<M<<":"<<calc(M)<<endl;
    if(calc(M) < m) R = M;
    else L = M;
  }
  return L;
}

signed main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    for(Int i=0;i<n;i++) cin>>A[i];
    //cout<<calc(2)<<endl;
    //cout<<calc(3)<<endl;
    //cout<<endl;
    cout<<search()<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 3836
import itertools

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
L = []
ans = float('inf')
for i in range(M):
    L.append(list(map(int,input().split())))
cost = []
for i in range(N):
    T = [float('inf') for j in range(N)]
    cost.append(T)
for i in range(M):
    cost[L[i][0]-1][L[i][1]-1] = L[i][2]
    cost[L[i][1]-1][L[i][0]-1] = L[i][2]
for l in range(N):
    for k in range(N):
        for m in range(N):
            cost[k][m] = min(cost[k][l]+cost[l][m], cost[k][m])

junretu = list(itertools.permutations(r))
for i in range(len(junretu)):
    temp = 0
    for j in range(len(r)-1):
        c = junretu[i][j]
        d = junretu[i][j+1]
        temp += cost[c-1][d-1]
    ans = min(ans,temp)
print(ans)

Measured memory_bytes: 79064
import copy
siken_kazu=int(input())
junbido=[int(i) for i in input().split(" ")]
goukakudo=[int(i) for i in input().split(" ")]
yoyudo=[junbido[i]-goukakudo[i] for i in range(siken_kazu)]
counter=0
shakkin=0
tyokin=0
if sum(junbido)<sum(goukakudo):
    counter=-1
else:
    for i in yoyudo:
        if i<0:
            counter+=1
            shakkin-=i
    yoyudo=sorted(yoyudo,reverse=True)
    for i in yoyudo:
        if tyokin>=shakkin:
            break
        else:
            tyokin+=i
            counter+=1
print(counter)

Measured memory_bytes: 19700
#include<bits/stdc++.h>
using namespace std;
#define mo 998244353
long long n,m,i,j,ans,zz[100005],x,y;
long long zzz(long long z){
	if(zz[z]==z) return z;
	return zz[z]=zzz(zz[z]);
}
struct nyh{
	long long a,b;
}o[100005];
bool cmp(nyh u,nyh v){
	return u.b>v.b||u.b==v.b&&u.a<v.a;
}
long long read(){
	long long xx=0,flag2=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
	if(ch=='-'){
		flag2=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return flag2*xx;
}
int main(){
	n=read();m=read();
	for(i=1;i<=n;i++){
		o[i].a=read();
		o[i].b=read();
	}
	sort(o+1,o+n+1,cmp);
	for(i=1;i<=m;i++)
		zz[i]=i;
	for(i=1;i<=n;i++){
		x=m-o[i].a+1;
		if(x>=0){
			x=zzz(x);
			if(x!=0){
				zz[x]=x-1;
				ans+=o[i].b;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import bisect
a, b, q = map(int, input().split())
inf = 10**18
s = [-inf] + [int(input()) for i in range(a)] + [inf]
t = [-inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = inf
  for S in [s[b-1], s[b]]:
    for T in [t[d-1], t[d]]:
      d1, d2 = abs(S-x) + abs(T-S), abs(T-x) + abs(S-T)
      res = min(d1, d2, res)
  print(res)


Measured memory_bytes: 14340
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-22 19:45:37
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int n; cin >> n;
  string s, t; cin >> s >> t;
  string res = "";

  for (int i = 0; i < n; ++i) {
    res += s[i];
    res += t[i];
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  if(n < 1200){
    cout<<"ABC"<<endl;
  }
  else if(n < 2800){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"AGC"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  size_t N;  
  string S;  
  cin >> N >> S;
 
 
  size_t result = 0;  
  vector<size_t> z;  // [0, z[i])  [i, i+z[i])
  for (size_t l1 = 0; l1 < N - 1; ++l1) {
   
    z.clear();
    z.resize(N - l1, 0);
 
    // Z-Algorithm
    size_t beg = 0, end = 0;  // [l1, l1+(end-beg))     [beg, end)
    for (size_t i = 1; i < z.size(); ++i) {
      if (i + z[i - beg] < end) {
       
        z[i] = z[i - beg];
      }
      else {
       
        const size_t l2 = l1 + i;
        size_t len = i < end ? (end - i) : 0;  
        for (; l2 + len < N; ++len) {
          if (S[l1 + len] != S[l2 + len]) break;
        }
        z[i] = len;
        beg = i;
        end = i + len;
      }
 
     
      result = max(result, min(i, z[i]));
    }
  }
 
  cout << result;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a[110];
    memset(a,0,sizeof(a));
    int x,n;
    cin>>x>>n;
    int i;
    for(i=0; i<n; i++)
    {
        int p;
        cin>>p;
        a[p]=1;
    }
    if(n==0)
        cout<<x;
    else
    {
        for(i=0; i<110; i++)
        {
            if(x-i<0)
            {
                cout<<x-i;
                break;
            }
            else
            {
                if(a[x-i]==0)
                {
                    cout<<x-i;
                    break;
                }

                else if(a[x+i]==0)
                {
                    cout<<x+i;
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3632
package main
 
import (
	"fmt"
)
 
func main() {
	var n, a int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &a)
	remand := n % 500
	if remand <= a {
		fmt.Printf("%s", "Yes")
	} else {
		fmt.Printf("%s", "No")
	}
}

Measured memory_bytes: 1832
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main(){
	set<int> a;
	int N;
	cin>>N;
	while(N--){
		int inp;
		cin>>inp;
		a.insert(inp);
	}
	
	cout<<a.size()<<"\n";
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    ll ans=0;
    if (a+b == 3){
        ans=3;
    } else if (a+b == 4){
        ans=2;
    } else if (a+b == 5){
        ans=1;
    }

    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        long n=fsc.nextLong();
        fsc.close();
        for(long h=1;h<=3500;h++){
            for(long w=1;w<=3500;w++){
                long r=n*w*h;
                long l=h*w*4-n*(w+h);
                if(l>0 && r%l==0){
                    System.out.println(h+" "+w+" "+r/l);
                    return;
                }
            }
        }
    }
    

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


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

int main(){
  int64_t a, b, k;
  std::cin >>  a >> b >> k;
  if(a <= k){
    k = k - a;
    if (b <= k) {
      std::cout << 0 << ' ' << 0 << '\n';
    }
    else{
      b = b - k;
      std::cout << 0 << ' ' << b << '\n';
    }
  }
  else{
    a = a - k;
    std::cout << a << ' ' << b << '\n';
  }
  
  return 0;
}

Measured memory_bytes: 256
mod = 10**9+7
N,X,Y,Z = map(int, input().split())
num = 1<<(X+Y+Z-1)
ng = ((((1<<X)+1)<<Y)+1)<<(Z-1)

dp = [[0]*num for i in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(1,11):
        for k in range(num):
            K = (k*2+1)<<(j-1)
            if K&ng != ng:
                K &= num-1
                dp[i+1][K] += dp[i][k]
                dp[i+1][K] %= mod

print((10**N%mod-sum(dp[N])%mod)%mod)

Measured memory_bytes: 64348
n = int(input())
A = [int(i) for i in input().split()]
 
q = int(input())
m = [int(i) for i in input().split()]
 
def dfs(idx, s, target):
    if s == target:
        return 1
     
    if s > target or idx == n:
        return 0
    if s + sum(A[idx:]) < target:
        return 0
 
    return dfs(idx+1, s, target) or dfs(idx+1, s + A[idx], target)
 
for target in m:
    ans = 'yes' if dfs(0, 0, target) else 'no'
    print(ans)


Measured memory_bytes: 5628
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    for(auto&& i : a){
        cin >> i;
    }
    sort(begin(a), end(a));
    vector<pair<long long, long long>> ans;
    int i = 1;
    for(; i < n - 1 && a[i] <= 0; i++){
        ans.push_back(make_pair(a[n - 1], a[i]));
        a[n - 1] -= a[i];
    }
    for(; i < n - 1; i++){
        ans.push_back(make_pair(a[0], a[i]));
        a[0] -= a[i];
    }
    cout << a[n - 1] - a[0] << "\n";
    for(auto&& i : ans){
        cout << i.first << " " << i.second << "\n";
    }
    cout << a[n - 1] << " " << a[0] << "\n";
}

Measured memory_bytes: 4336
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,K;
	while(cin>>N>>K) {
		ll ans=0;
		RANGE(b, K+1, N+1) {
			ll v=N/b*(b-K);
			if(K==0) v--;
//			DD(v);
			v += max(0LL, N%b-K+1);
			ans+=v;
//			DD(b);DD(v);
		}
		
		cout<<ans<<endl;
//		break;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.regex.Pattern;
class Main
{
		// your code goes here
		public static void main(String args[])
		{
                   // Comparator cmprtr=null;
                    int n,c=0;
                    Scanner sc= new Scanner(System.in);
                    n=sc.nextInt(); 
                    int a[]=new int[n];
                    for(int i=0;i<n;i++)
                    {
                        a[i]=sc.nextInt();
                    }
                    for(int i=0;i<n;i++)
                    {
                        if(a[i]%2==0)
                        {
                            if(a[i]%3==0 || a[i]%5==0)
                            {
                                
                            }
                            else
                            {
                                c++;
                            }
                        }
                    }
                    if(c>0)
                    {
                        System.out.println("DENIED");
                    }
                    else
                    {
                        System.out.println("APPROVED");
                    }
                }}     
    




Measured memory_bytes: 23252
# D - Road to Millionaire
def sell(price):
  global money
  global stock
  
  money += price * stock
  stock = 0


def buy(price):
  global money
  global stock

  stock += money // price
  money %= price


N = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

for i in range(N - 1):
  if A[i] < A[i + 1]:
    sell(A[i])
    buy(A[i])
  elif A[i + 1] < A[i]:
    sell(A[i])

sell(A[N - 1])

print(money)

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

int main(){
	int N;
	cin >> N;
	vector<int> A;
	for(int i=0;i<N;i++){
		int X;
		cin >> X;
		A.push_back(X);
	}
	sort(A.begin(), A.end());
	bool chk = true;
	for(int i=0;i<N-1;i++){
		if(A[i] == A[i+1]){
			chk = false;
			break;
		}
	}
	if(chk) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX)
#define VEC2(type,name,w,h) vector<vector<type>>name(h,vector<type>(w))

using namespace std;
typedef long long ll;


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; }
template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    string s,t;
    cin>>s>>t;
    vector<vector<int>> dp(3100,vector<int>(3100,0));

    rep(i,s.length()){
        rep(j,t.length()){
            if(s[i]==t[j]){
                chmax(dp[i+1][j+1],dp[i][j]+1);
            }
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    int i=s.length();
    int j=t.length();

    string ans="";
    while(i>0&&j>0){
        if(dp[i][j]==dp[i-1][j]){
            --i;
        }
        else if(dp[i][j]==dp[i][j-1]){
            --j;
        }
        else{
            ans=s[i-1]+ans;
            --i;
            --j;
        }
    }
    cout<<ans;
}
/*
*/

Measured memory_bytes: 41292
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    ll N = 50;
    ll a[55] = {};
    rep(i,0,N) a[i] = i;
    ll v = K / N;
    rep(i,0,N) a[i] += v;
    ll amari = K % N;
    rep(i,0,amari){
        rep(j,0,N){
            if(i == j){
                a[j] += N;
            }else{
                a[j]--;
            }
        }
    }
    print(N);
    printa(a,N);

}


Measured memory_bytes: 256