akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 305;

char s[MAXN];

int dp[MAXN][MAXN][MAXN];

void solve(){
	int n, k;
	scanf("%s%d", &s[0], &k);
	n = strlen(s);
	REP(i, 0, n) {
		dp[i][i][0] = 1;
	}
	REPN(l, 0, k) {
		for(int i = n - 1; i >= 0; i--) {
			if (l > 0) {
				dp[i][i][l] = dp[i][i][l - 1];
			}
			REP(j, i + 1, n) {
				dp[i][j][l] = max(dp[i + 1][j][l], dp[i][j - 1][l]);
				if (l > 0) {
					dp[i][j][l] = max(dp[i][j][l], dp[i][j][l - 1]);
				}
				if (s[i] == s[j]) {
					dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l] + 2);
				} else if (l > 0) {
					dp[i][j][l] = max(dp[i][j][l], dp[i + 1][j - 1][l - 1] + 2);
				}
			}
		}
	}
	printf("%d\n", dp[0][n - 1][k]);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 110848
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int n;
    cin>>n;
    ll a[100000];
    rep(i,n){
        ll aa;
        cin>>aa;
        a[i]=aa;
        if(aa==0){
            cout<<0<<endl;
            return 0;
        }
    }
    ll ans=1;
    rep(i,n){
        ll div=1'000'000'000'000'000'000;
        //ll limit=(div%ans==0)?(div/ans):((div/ans)+1);
        if(a[i]>div/ans){
            cout<<-1<<endl;
            return 0;
        }else{
            ans*=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

                


Measured memory_bytes: 4376
#include<iostream>
using namespace std;
int main()
{
    int n,l,index=0,value=300,sum=0;
    cin>>n>>l;
    int ar[n],check[n];
    for(int i=0;i<n;++i)
    {
        check[i]=0;
        ar[i]=l+i;
        sum=sum+ar[i];
        if(ar[i]<0){check[i]=1;ar[i]=ar[i]*(-1);}
        if(ar[i]<value){value=ar[i];index=i;}
    }
    if(check[index]==1){ar[index]=ar[index]*(-1);}
    cout<<sum-ar[index];
    
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_i
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <array>
using namespace std;

#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define EPS (1e-7)
#define INF (1e9)
#define MODI (1000000007)

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// dp[i][j] : コインをi枚使い、j枚が表である確率
// double dp[3001][3001];
array<double, 3001> dpA, dpB;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	// 入力、DP後、DP前
	vector<double> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	dpB[0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			// i-1回目で表の枚数がj-1で、i回目が表
			// i-1回目で表の枚数がjで、i回目が裏
			dpA[j] = dpB[j - 1] * p[i - 1] + dpB[j] * (1.0 - p[i - 1]);
		}
		swap(dpA, dpB);
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) {
		ans += dpB[i];
	}
	printf("%0.10f\n", ans);

	return 0;
}


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

int main() {
	char a, b;
	cin >> a >> b;
	
  	if( a == 'H' && b == 'H' ) cout << 'H' << endl; 
  	else if( a == 'H' && b == 'D' ) cout << 'D' << endl;
  	else if( a == 'D' && b == 'H' ) cout << 'D' << endl;
  	else if( a == 'D' && b == 'D' ) cout << 'H' << endl;
  	else;
}


Measured memory_bytes: 256
import bisect


def main():
    N = int(input())
    P = list(map(int, input().split(' ')))
    Q = [0] + P + [N + 1]
    index_q = [0 for _ in range(len(Q))]
    for i, q in enumerate(Q):
        index_q[q] = i
    I = [0, 0, N + 1, N + 1]
    ans = 0
    for c in range(N, 0, -1):
        i = index_q[c]
        j = bisect.bisect_left(I, i)
        w, x, y, z = I[j - 2], I[j - 1], I[j], I[j + 1]
        ans += c * ((x - w) * (y - i) + (i - x) * (z - y))
        I.insert(j, i)
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  map<string, int> MA;
  string S;
  int mx = 0;
  while (cin >> S) mx = max(mx, ++MA[S]);
  vector<string> V;
  for (auto ma : MA) if (ma.second == mx) V.push_back(ma.first);
  sort(V.begin(), V.end());
  for (auto v : V) cout << v << "\n";
}

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

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

	int n, t;
	cin >> n;

	int sum = 0, mini = 999;
	while (n--) {
		cin >> t;
		if (t % 10) mini = min(mini, t);

		sum += t;
	}
	if (sum % 10) cout << sum;
	else {
		if (mini == 999) cout << 0;
		else cout << sum - mini;
	}
}

Measured memory_bytes: 256
import heapq

def main():
    n, k, q = map(int, input().split())
    a = tuple(map(int, input().split()))

    m = float('inf')
    for y in sorted(set(a)):
        x = find_x(a, y, k, q)
        if x is None:
            break
        m = min(m, x - y)
    
    print(m)

def find_x(a, y, k, q):
    gs = groups(a, y, k)
    xs = []

    for g in gs:
        xs.extend(heapq.nsmallest(len(g) - k + 1, g))
    
    xss = heapq.nsmallest(q, xs)
    if len(xss) < q:
        return None
    
    return xss[-1]

def groups(a, m, k):
    g = []

    pos = 0
    while pos < len(a):
        i = pos
        while i < len(a) and a[i] < m:
            i += 1
        
        j = i
        while j < len(a) and a[j] >= m:
            j += 1
        
        if j - i >= k:
            g.append(a[i:j])
        
        pos = j
    
    return g

main()

Measured memory_bytes: 3444
n,m=map(int,input().split())
res=[[]for _ in range(n+1)]
a=0
w=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    res[p].append(s)

for i in range(1,n+1):
    if "AC" in res[i]:
        a+=1
        f=0
        for j in range(len(res[i])):
            if res[i][j]=="WA" and f==0:
                w+=1
            if res[i][j]=="AC":
                f=1
        
print(a,w)
    

        


    
        
        
    
    
    
    
        


Measured memory_bytes: 25220
from sys import stdin

if __name__ == '__main__':
    # is_begin = False
    for n in stdin:
        if int(n) == 0:
            break
        # else:
        #     if is_begin:
        #         print()
        # is_begin = True

        bottom_total = []
        right_total = []
        for _ in range(int(n)):
            line = input().split(' ')
            total = 0
            for i, v in enumerate(line):
                print(repr(int(v)).rjust(5), end='')
                total += int(v)
                if len(bottom_total) < i + 1:
                    bottom_total.append(int(v))
                else:
                    bottom_total[i] += int(v)
            right_total.append(total)
            print(repr(right_total[_]).rjust(5))

        for num in bottom_total:
            print(repr(num).rjust(5), end='')
        print(repr(sum(bottom_total)).rjust(5))

Measured memory_bytes: 7624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    double ans = 0.5;
    if (n % 2 == 1) {
        ans = ((n / 2) + 1) / (double)n;
    }
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    CIN(A);CIN(B);CIN(C);CIN(D);
    COUT(max(A*B,C*D));
    return 0;
}


Measured memory_bytes: 256
import math
N, D = list(map(int, input().split()))
rows = []
for i in range(N):
  rows.append(list(map(int, input().split())))

ans = 0
for row in rows:
  if D >= math.sqrt(pow(row[0], 2) + pow(row[1], 2)):
    ans += 1

print(str(ans))

Measured memory_bytes: 45460
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int nax = 3005;
ll dp[nax][nax];

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    // dp[0][n-1]
    for(int L = n - 1; L >= 0; --L) {
        for(int R = L; R < n; ++R) {
            if(L == R) {
                dp[L][R] = a[L];
            }
            else {
                dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
            }
        }
    }
    printf("%lld\n", dp[0][n-1]);
}


Measured memory_bytes: 70016
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        int D;
        int G;
        int[] p;
        int[] c;

        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            D = in.Int();
            G = in.Int();
            p = new int[D];
            c = new int[D];
            for (int i = 0; i < D; i++) {
                p[i] = in.Int();
                c[i] = in.Int();
            }

            int ans = 1000000;
            for (int i = 0; i < D; i++) {
                ans = Math.min(ans, calc(0, 1 << i, i + 1));
            }
            out.println(ans);
        }

        private int calc(int score, int a, int b) {
            int ans = 0;
            for (int i = 1; i <= p[b - 1]; i++) {
                if (score >= G) {
                    return ans;
                }
                score += b * 100;
                ans++;
            }
            score += c[b - 1];
            if (score >= G) {
                return ans;
            }
            int temp = 10000000;
            for (int i = 0; i < D; i++) {
                int c = a | (1 << i);
                if (a != c) {
                    temp = Math.min(temp, calc(score, c, i + 1));
                }
            }

            return ans + temp;
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23380
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    string a, b;
    cin >> a >> b;
    string s = a + b;
    int n = s.size();
    reverse(s.begin(), s.end());
    int num = 0;
    int tmp = 1;
    rep(i, n) {
        num += tmp * (s[i] - '0');
        tmp *= 10;
    }
    for (int i = 1; i * i <= 100100; ++i) {
        if (num % i == 0 && num / i == i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];

bool X[N][N];

void initialize() {
	for (int i = 0; i < N; i++ ) { row[i] = FREE, col[i] = FREE; }
		for (int i = 0; i < 2 * N - 1; i++ ) { dpos[i] = FREE; dneg[i] = FREE; }
	}

void printBoard() {
	for ( int i = 0; i < N; i++ ) {
		for ( int j = 0; j < N; j++ ) {
			if ( X[i][j] ) {
				if ( row[i] != j ) return;
			}
		}
	}
	for ( int i = 0; i < N; i++ ) {
		for ( int j = 0; j < N; j++ ) {
			cout << (( row[i] == j ) ? "Q" : "." );
		}
		cout << endl;
	}
}

void recursive(int i) {
	if ( i == N) {
		printBoard(); return;
	}

	for ( int j = 0; j < N; j++ ) {
		if (NOT_FREE == col[j] ||
			NOT_FREE == dpos[i + j] ||
			NOT_FREE == dneg[i - j + N - 1] ) continue;
			row[i] = j; col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
		recursive(i + 1);
		row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
	}
}

int main() {
	initialize();

	for (int i = 0; i < N; i++)
		for (int j = 0; j< N; j++ ) X[i][j] = false;

	int k; cin >> k;
	for (int i = 0; i<k; i++ ){
		int r, c; cin >> r >> c;
		X[r][c] = true;
	}

	recursive(0);

	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define INF 99999999
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

int64_t max(int64_t a,int64_t b){return a<b?b:a;}
int64_t min(int64_t a,int64_t b){return a<b?a:b;}
int64_t aabs(int64_t a){return a<0?-a:a;}

int64_t calc(int64_t h,int64_t w){
    int64_t x,y;
    int64_t ret = INF;
    
    y=h/2-5;
    y=max(0,y);
    
    REP(j,10){
        x=w*y/(h+y);
        
        
        x=max(0,x-5);
        
        REP(i,10){
            int64_t a = h*x;
            int64_t b =(w-x)*y;
            int64_t c =(w-x)*(h-y);
            
            int64_t d = aabs(a-b);
            int64_t e = aabs(b-c);
            int64_t f = aabs(a-c);
            
            int64_t g = max(d,max(e,f));
            
            ret = min(ret,g);
            
            x++;
            x=min(x,w);
        }
        
        y++;
        y=min(y,h);
    }
    
    return ret;
}

int main(void){
    int64_t h,w;
    cin >> h >> w;
    
    int ret = INF;
    
    if(h*w%3==0){
        ret =0;
    }
    
    if(true){
        int64_t kk = h;
        int64_t a = kk/3;
        int64_t b = (kk-a)/2;
        int64_t c = kk-b-a;
        
        int64_t d = aabs(a-b);
        int64_t e = aabs(b-c);
        int64_t f = aabs(a-c);
        
        
        int64_t g = max(d,max(e,f))*w;
        
        ret = min(g,ret);
    }
    
    
    if(true){
        int64_t kk = w;
        int64_t a = kk/3;
        int64_t b = (kk-a)/2;
        int64_t c = kk-b-a;
        
        int64_t d = aabs(a-b);
        int64_t e = aabs(b-c);
        int64_t f = aabs(a-c);
        
        
        int64_t g = max(d,max(e,f))*h;
        
        ret = min(g,ret);
    }
    
    ret = min(calc(w,h),ret);
    ret = min(calc(h,w),ret);
    
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int f(int x)
{
	int ret=0;
	while(x) ret+=x%10,x/=10;
	return ret;
}
int min(int a, int b){ return a>b?b:a;}
int main()
{
	int n,a,b,sol=10000;
	scanf("%i",&n);
	for(a=1;a<n;a++)
	{
		b=n-a;
		sol=min(sol,f(a)+f(b));
	}
	printf("%i\n",sol);
	return 0;
}

Measured memory_bytes: 128
"""
from collections import defaultdict
from collections import deque

def prime(N):
    se = [0,0,1]+[1]*(N-2)
    n = 2
    while n ** 2 <= N:
        if se[n]:
            nn = 2*n
            while nn <= N:
                se[nn] = 0
                nn += n
        n += 1

    return [x for x in range(0,N+1) if se[x]]
"""
N = int(input())
A = list(map(int,input().split()))

# N = 1のときはコーナーケース！

if N == 1:
    if A[0] == 1:
        print(1)
        print(1)
    else:
        print(0)
    exit()

#deq = deque()

"""
pr = prime(N)

deq = deque(pr)
deq.appendleft(1)

cnt = len(deq)

d = [0]*(N+1)
d[1] = -1
for p in pr:
    d[p] = -1

B = pr
while cnt < N:
    C = []
    for num in B:
        if num * 2 > N:
            break
        for p in pr:
            if num * p > N:
                break
            aaa = num * p
            if d[aaa] <= 0:
                d[aaa] = p
                deq.append(aaa)
                C.append(aaa)
                cnt += 1
    B = sorted(C)
"""
B = [0]*N

for n in range(N,0,-1):
    B[n-1] = (sum(B[2*n-1:N:n]) + A[n-1])%2

a = sum(B)
print(a)
for i in range(N):
    if B[i]:
        print(i+1)


Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }
#define INF 1e10

int main() {
    ll n, d;
    cin >> n >> d;
    vector<ll> x(n);
    vector<ll> y(n);
    int ans = 0;
    rep(i, n){
        cin >> x.at(i) >> y.at(i);
        if(x.at(i) * x.at(i) + y.at(i) * y.at(i) <= d * d){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6424
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())

dp = [[0] * (W+1) for _ in range(N)]

for i in range(N):
    for j in range(1, W+1):
        if w[i] > j:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], v[i]+dp[i-1][j-w[i]])

print(max(dp[N-1]))

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define SUM(v) accumulate((v).begin(),(v).end(),0ll)
#define range(i,left,right) (left<=i && i<right)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int iscount(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

Vi yakusuu(int n){
    Vi ret;
    for(int i=1 ; i*i<=n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int n;
    cin>>n;
    int ans=0;
    Vi yaku_n=yakusuu(n);
    for(auto x : yaku_n){
        if(x==1) continue;
        int m=n;
        while(m%x==0) m/=x;
        if(m%x==1) ans++;
    }

    Vi yaku_n1=yakusuu(n-1);
    for(auto x : yaku_n1){
        if(n%x==1) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
	int a, b, c;
	int i;
	int num=0;
	scanf("%d %d %d", &a, &b, &c);

	for(i=a; i<= b; i++){
		if(c%i == 0){

			num = num + 1;
		}
	}
	printf("%d\n", num);
	return 0;

}


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

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

const long long INF = 1LL << 60;
const long long mod = 1000000007;


int main(void){
   int a,b,k; cin >> a >> b >> k;
    int t=0;
    for(int i=min(a,b);i>=1;i--){
	if(a % i == 0 && b % i == 0)t++;
	if(t==k){
	    cout << i << endl;
	    break;
	}
   }
   return 0;
}


Measured memory_bytes: 256
N  = int(input())
A_list = []
primary_max = 0
secondary_max = 0

for i in range(N) :
    n = int(input())
    if (primary_max <= n) :
        if (primary_max == secondary_max) :
            primary_max = n
        else :
            secondary_max = primary_max
            primary_max = n
    elif (secondary_max < n and n < primary_max) :
        secondary_max = n

    A_list.append(n)

for a in A_list :
    if (a == primary_max) :
        print(secondary_max)
    else :
        print(primary_max)



Measured memory_bytes: 12520
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

#define int long long

template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

const ll MOD = 1000 * 1000 * 1000 + 7;

const int MAX_N = 100010;
const int MAX_M = 100010;

ll x[MAX_N], y[MAX_M],
   accum_x[MAX_N], accum_y[MAX_M];

signed main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        if (i > 0) {
            accum_x[i] = (MOD + accum_x[i - 1] - x[i - 1]) % MOD;
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
        if (i > 0) {
            accum_y[i] = (MOD + accum_y[i - 1] - y[i - 1]) % MOD;
        }
    }

    /*
    cout << "accum_x" << endl;
    for (int i = 0; i < n; i++) {
        cout << accum_x[i] << " ";
    }
    cout << endl;

    cout << "accum_y" << endl;
    for (int i = 0; i < m; i++) {
        cout << accum_y[i] << " ";
    }
    cout << endl;
    */

    ll a = 0,
       b = 0;
    for (int i = 1; i < n; i++) {
        a = (a + (((ll)i * x[i]) % MOD + MOD + accum_x[i]) % MOD) % MOD;
    }

    for (int i = 1; i < m; i++) {
        b = (b + (((ll)i * y[i]) % MOD + MOD + accum_y[i]) % MOD) % MOD;
    }

    cout << (a * b) % MOD << endl;

    return 0;
}


Measured memory_bytes: 3328
num = int(input())
val = [int(x) for x in input().split()]

numbers = [int(x) for x in range(-1, 100001)]
numbers_dict = dict()

for number in numbers:
    numbers_dict[number] = numbers_dict.get(number, 0) + 1

for i in val:
    numbers_dict[i - 1] += 1
    numbers_dict[i] += 1
    numbers_dict[i + 1] += 1

print(max(numbers_dict.values())-1)

Measured memory_bytes: 21624
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n;
    scanf("%d", &n);
    if(n % 2 != 0)
        n *= 2;
    printf("%d\n", n);
    return 0;
}

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

int linearsearch(int x,int S[],int n){
	for(int i=0;i<n;i++){
		if(S[i]==x)
			return i;
	}
	return -1;
}
	
int main(){
	int n;
	cin>>n;
	int A[n];
	for(int i=0;i<n;i++){
		cin>>A[i];
	}

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

	int c=0;
	for(int i=0;i<m;i++){
		if(linearsearch(B[i],A,n)!=-1) c++;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
string b[1000000];
bool cmp(string a, string b)
{
    return a < b;
}
int main()
{
    //freopen("bfr.in","r",stdin);
    //freopen("bfr.out","w",stdout);
    int n,l;
    cin >> n >> l;
    for(int i = 1;i <= n;++i)
        cin >> b[i];
    sort(b+1,b+1+n,cmp);   
    for(int i=1;i<=n;++i)
        cout<<b[i];
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 8064
using System;

    class Program
    {
        static void Main(string[] args)
        {
            string[] inputs = Console.ReadLine().Split(' ');

            int a = int.Parse(inputs[0]);
            int b = int.Parse(inputs[1]);
            int c = int.Parse(inputs[2]);
            int k = int.Parse(inputs[3]);

            int sum = 0;
            if (a >= k)
            {
                sum = k;
            }
            else
            if (a + b >= k)
            {
                sum = a;
            }
            else
            {
                sum = a - (k - (a + b));
            }

            Console.WriteLine(sum);
        }
    }


Measured memory_bytes: 27292
import java.util.Scanner;
public class Main{

	public static void main(String[] args){
		//writeInput();
		solve();
		}

	public static void solve(){
		Scanner sc = new Scanner(System.in);

		long K =Long.parseLong(sc.next());
		int N = 50;
		long m = K/N;
		long r = K%N;
		
		long[] a = new long[N];
		for(int i=0;i<N-(int)r;i++)a[i]=m+N-r-1;
		for(int i=N-(int)r;i<N;i++)a[i]=m+2*N-r;
		
		answer(N,a);
		sc.close();

	}

	public static void answer(long N, long[] a){
		System.out.println(N);
		System.out.print(a[0]);
		for(int i=1;i<N;i++)System.out.print(" "+a[i]);
		System.out.println();
	}


/*	public static void writeInput(){
		try{
			File file = new File("c:\\Users\\jugem\\Documents\\pleiades\\input.dat");
			if (checkBeforeWritefile(file)){
				PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
				pw.println("1234567894848");
				pw.close();
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}

	public static boolean checkBeforeWritefile(File f){
		return f.exists()?(f.isFile()&&f.canWrite()):false;
	}
*/
}


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

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

  // ここにプログラムを追記
  for (int i = 0; i < N; i++) {
    string color;
    cin >> color;
    
    if (color == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    if (i + 1 == N) {
      cout << "Three" << endl;
    }
  }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();

        int out = 0;
        for(int i=1; i<n; i++) {
            int tmpN = i;
            int tmpM = n-i;
            int sumN = 0;
            int sumM = 0;
            while(true) {
                sumN += tmpN % 10;
                if(tmpN / 10 > 0) {
                    tmpN /= 10;
                } else {
                    break;
                }
            }
            while(true) {
                sumM += tmpM % 10;
                if(tmpM / 10 > 0) {
                    tmpM /= 10;
                } else {
                    break;
                }
            }
            if(i == 1) {
                out = sumN + sumM;
            } else if(out > sumN + sumM) {
                out = sumN + sumM;
            }
        }
        System.out.println(out);
    }
}


Measured memory_bytes: 23764
#include<stdio.h>
int main() {
	int a, b, sum, p;
	while (scanf("%d %d", &a, &b)!= EOF) {
		p = 0;
		sum = a + b;
		while (sum != 0) {
			sum =sum/ 10;
			p++;
		}
		printf("%d\n", p);
	}
	return 0;
}

Measured memory_bytes: 600
import copy
n = int(input())
r = []
for _ in range(n):
    city, x = input().split()
    x = int(x)
    r.append((city, x))

d = copy.deepcopy(r)
d = sorted(d, key=lambda x: -x[1])
d = sorted(d, key=lambda x: x[0])

for k in d:
    print(r.index(k) + 1)


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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; ++i) {
	    cin >> arr[i];
	}
	long long dp[n];
	dp[0] = 0;
	for(int i = 1; i < n; ++i) {
	    dp[i] = abs(arr[i] - arr[i-1]) + dp[i-1];
	    if(i-2 >= 0)
	        dp[i] = min(dp[i], abs(arr[i] - arr[i-2]) + dp[i-2]);
	    //cout << dp[i] << " ";
	}
	//cout << endl;
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,count=0;
  cin >> n;
  long long int a[n],b[n+1];
  b[0]=0;
  map <long long ,long long>list;
  list[0]=1;
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i+1]=a[i]+b[i];
    count+=list[b[i+1]];
    list[b[i+1]]++;
  }
  cout << count <<endl;
}

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

int main() {
    int x;
    cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1  << endl;
    return 0;
}

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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

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

        vector<int> maxHeight(2*r);
        for(int i=0;i<n;i++){
            int tl, tr, th;
            cin >> tl >> tr >> th;
            for(int x=tl;x<tr;x++){
                if(-r <= x && x < r){
                    maxHeight[x+r] = max(th, maxHeight[x+r]);
                }
            }
        }
        double ans = 10000;
        for(int x=-r;x<r;x++){
            int c;
            if(x < 0){
                c = -x-1;
            }else{
                c = x;
            }
            ans = min(ans, r+maxHeight[x+r]-sqrt(r*r - c*c));
        }
        printf("%.6f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1228
import Control.Applicative
import Text.Printf

main :: IO ()
main = solve <$> f >>= printf "%.10f\n"
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Double
solve [n, k] = f 0 n 1
  where
    f :: Double -> Int -> Int -> Double
    f x m d = let m' = (k + d - 1) `div` d
              in if m == 0
                 then x / (fromIntegral n)
                 else if m < m'
                      then f x m (d * 2)
                      else f (x + (fromIntegral (max 0 (m - m' + 1))) / (fromIntegral d)) (m' - 1) (d * 2)


Measured memory_bytes: 508
N = int(input())
a_list = list(map(int, input().split()))

ball_list = [0] * (N + 1)
for n in reversed(range(1, N + 1)):
    mod = 0
    for i in range(n, N + 1, n):
        mod ^= ball_list[i]
    if mod != a_list[n - 1]:
        ball_list[n] = 1

num = sum(ball_list)
print(num)

if num > 0:
    for i, b in enumerate(ball_list):
        if b == 1:
            print(i)


Measured memory_bytes: 7148
// AOJ 0302: Star Watching
// 2017.12.27 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 524290

#define INF 0x55555555
typedef struct { int x, y, l; } T;
T tbl[MAX];
int seg[4][MAX], sz;
char buf[30], *p;

int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

#if 0
void segtree(int id, int n)
{
	int k;
	k = 1; while (k < n) k <<= 1;
	sz = k;
	memset(seg[id], INF, sizeof(seg[id]));
}
#endif

// update kth value to v
void update(int id, int k, int v)
{
	int t;
	k += sz-1;
	seg[id][k] = v;
	while (k > 0) {
		if (!(k & 1)) k--;
		t = k, k >>= 1;
		v = seg[id][t++]; if (v > seg[id][t]) v = seg[id][t];
		seg[id][k] = v;
	}
}

int query2(int id, int a, int b, int k, int l, int r) 
{
	int m, lmin, rmin;

	if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return seg[id][k];
	k <<= 1, m = (l + r) >> 1;
    lmin = query2(id, a, b, ++k, l, m);
    rmin = query2(id, a, b, ++k, m, r);
    if (lmin > rmin) lmin = rmin; 
    return lmin;
}

// get min in [a, b)
int query(int id, int a, int b)
{
	return query2(id, a, b, 0, 0, sz);
}

int cmp(T *a, T *b) { return a->l - b->l; }

int main()
{
	int n, d, i, j;
	long long ans, a;

	fgets(p=buf, 30, stdin);
	n = in(), d = in();
	for (i = 0; i < n; i++) {
		fgets(p=buf, 30, stdin);
		tbl[i].x = in(), tbl[i].y = in(), tbl[i].l = in();
	}
	qsort(tbl, n, sizeof(T), cmp);
	tbl[n].l = INF;

	sz = 1; while (sz < n) sz <<= 1;
	memset(seg, INF, sizeof(seg));

	for (i = 0; i < n; i++) {
		update(0, i, -tbl[i].x), update(1, i, tbl[i].x);
		update(2, i, -tbl[i].y), update(3, i, tbl[i].y);
	}

	ans = 0;
	i = j = 0;
	while (1) {
		while (tbl[j].l - tbl[i].l <= d) j++;

		a = (((long long)query(0, i, j)) + query(1, i, j)) *
			(((long long)query(2, i, j)) + query(3, i, j));
		if (a > ans) ans = a;

		if (j == n) break;
		while (i < n && tbl[j].l - tbl[i].l > d) i++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 12332
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],q[N];


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
              double x,y,v;
              cin>>x>>y>>v;
              if(x/v<=y)puts("Yes");
              else puts("No");
	}
	return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

signed main(){
    int h, w;
    int n;
    cin >> h >> w >> n;
    int a[n];
    rep(i,n) cin >> a[i];

    int index = 0;
    rep(i, h) {
        if(i%2==0) {
            rep(j, w) {
                cout << index+1 <<" "<< flush;
                a[index]--;
                if(a[index]==0) index++;
            }
        }else {
            deque<string> num(w);
            rrep(j, w) {
                num.push_front(to_string(index+1));
                a[index]--;
                if(a[index]==0) index++;
            }
            rep(k,w) cout << num[k] <<" "<< flush;
        }
        cout << "" << endl;
    }

    return 0;
}


Measured memory_bytes: 3732
// ABC157B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main()
{
	vector<int>A(9);
	rep(i,9){
		cin >> A.at(i);
	}
	int N;
	cin >> N;
	int b;
	rep(k, N) {
		cin >> b;
		auto itr = find(A.begin(), A.end(), b);
		if (itr - A.begin() < 9) { 
			// もし選ばれた数がビンゴカードになるならAijを0にする
			A.at(itr - A.begin()) = 0;
		}
	}
	bool ans = false;
	if (A.at(0) + A.at(1) + A.at(2) == 0)ans = true;
	if (A.at(3) + A.at(4) + A.at(5) == 0)ans = true;
	if (A.at(6) + A.at(7) + A.at(8) == 0)ans = true;
	if (A.at(0) + A.at(4) + A.at(8) == 0)ans = true;
	if (A.at(2) + A.at(4) + A.at(6) == 0)ans = true;
	if (A.at(0) + A.at(3) + A.at(6) == 0)ans = true;
	if (A.at(1) + A.at(4) + A.at(7) == 0)ans = true;
	if (A.at(2) + A.at(5) + A.at(8) == 0)ans = true;
	//
	if (ans==true)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
#define MAX 100000
typedef long long ll; 
int n,k;
int T[MAX];

int check(ll P){ 
    int i=0;
    for(int j=0;j<k;j++){
        ll s=0;
        while(s+T[i]<=P){
            s+=T[i];
            i++;
            if(i==n)
                return n;
        }   
    }   
    return i;
}
int solve(){
    ll left=0;
    ll right=100000*10000;
    ll mid;
    while(right-left>1){
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n)right=mid;
        else 
            left=mid;
    }   
    return right;
}
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>T[i];                         
    ll ans=solve();
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3476
n,k = [int(x) for x in input().split()]
a = [list(map(int, list(bin(int(x))[2:]))) for x in input().split()]
b = list(map(int, list(bin(k)[2:])))
m = len(b)
for i in a:
    m = max(m,len(i))
for i in range(n):
    for j in range(m-len(a[i])):
        a[i].insert(0,0)
for j in range(m-len(b)):
    b.insert(0,0)
s = [0]*m
for i in a:
    for j in range(m):
        if not i[j]:
            s[j] += 1
dp = [[0 for i in range(2)] for k in range(m+1)]
dp[0][1] = -float("inf")
f = [1<<(m-i-1) for i in range(m)]
for i in range(m):
    for j in range(2):
        x = 1 if j else b[i]
        for d in range(x+1):
            j_ = j | (d < b[i])
            k = dp[i][j]+f[i]*(s[i]*d+(n-s[i])*(1-d))
            if k > dp[i+1][j_]:
                dp[i+1][j_] = k
print(max(dp[m]))


Measured memory_bytes: 119988
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int i, k;
	int n;
	int* a;
	scanf("%d", &n);
	a = malloc(sizeof(int)*n);
	for(i = 0; i < n; i++) scanf("%d", &a[i]);
	for(i = 1; i < n; i++){
		printf("%d", a[0]);
		for(k = 1; k < n; k++)
			printf(" %d", a[k]);
		printf("\n");
		int v = a[i];
		int j = i-1;
		while(j >= 0 && a[j] > v){
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
	}
	printf("%d", a[0]);
	for(k = 1; k < n; k++)
		printf(" %d", a[k]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && b!=c){
        cout << "Yes" << endl;
    }else if (a == c && b!= a) {
        cout << "Yes" << endl;
    }else if(b == c && a != b) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const long long INF = 1LL << 60;
int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    vector<int>x(N);
    vector<int>y(M);
    int a=-1000;
    int b=1000;
    rep(i,N){
        cin>>x[i];
        if(a<x[i]){
            a=x[i];
        }
    }
    rep(i,M){
        cin>>y[i];
        if(y[i]<b){
            b=y[i];
        }
    }
    bool ans=false;
    for(int i=X+1; i<Y+1; i++){
        if(a<i&&i<=b){
            ans=true;
        }
    }
    if(ans==false){
        cout<<"War"<<endl;
    }
    else{
        cout<<"No War"<<endl;
    }
}


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

using namespace std;

const int N = 2e5 + 2;

int n, a[N], b[N], fen[N];
long long ans, dp[N];

void upd(int pos){
      for(int i = a[pos]; i <= n; i |= i + 1){
            if(dp[fen[i]] < dp[pos])
                  fen[i] = pos;
      }
}

int get(int r){
      int ret = 0;
      for(; r > 0; r = (r & (r + 1)) - 1){
            if(dp[fen[r]] > dp[ret]){
                  ret = fen[r];
            }
      }
      return ret;
}

int main(){
      cin >> n;

      for(int i = 1; i <= n; i ++)
            cin >> a[i];
      for(int i = 1; i <= n; i ++)
            cin >> b[i];

      for(int i = 1; i <= n; i ++){
            int pos = get(a[i] - 1);
            dp[i] = dp[pos] + b[i];
            upd(i);
            ans = max(ans, dp[i]);
      }

      cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N,D;
map<string,vector<P> > ss;
string s[202];
bool ok[202][202];

int main(){
  while(1){
    cin>>N;
    if(N==0)break;
    cin>>D;
    memset(ok,0,sizeof(ok));
    ss.clear();
    rep(i,N){
      cin>>s[i];
      int sz=s[i].size();
      ss[s[i]].push_back(P(i,0));
      rep(j,sz){ // delete
        string t=s[i];
        t=t.substr(0,j)+t.substr(j+1,sz-1-j);
        ss[t].push_back(P(i,1));
      }
      rep(j,sz-1){ // swap
        string t=s[i];
        swap(t[j],t[j+1]);
        ss[t].push_back(P(i,1));
      }
      rep(j,sz)repl(c,'a','z'+1){ // mutate
        string t=s[i];
        t[j]=c;
        ss[t].push_back(P(i,1));
      }
      rep(j,sz+1)for(char c='a';c<='z';c++){ // insert
        string t=s[i];
        string u;
        u+=t.substr(0,j);
        u+=c;
        u+=t.substr(j,sz-j);
        ss[u].push_back(P(i,1));
      }
    }
    for(auto it : ss){
      for(auto it1 : it.se){
        for(auto it2 : it.se){
          if(it1.se+it2.se<=D){
            ok[it1.fi][it2.fi]=true;
            ok[it2.fi][it1.fi]=true;
          }
        }
      }
    }
    vector<pair<string,string> > res;
    rep(i,N)rep(j,i){
      if(ok[i][j]){
        res.push_back(pair<string,string>(min(s[i],s[j]),max(s[i],s[j])));
      }
    }
    sort(all(res));
    rep(i,res.size())cout<<res[i].fi<<","<<res[i].se<<endl;
    cout<<res.size()<<endl;
  }
return 0;
}



Measured memory_bytes: 27168
#include<stdio.h>
int main()
{ 
    char a[2];
  	int counter;
    scanf("%s",a);
  	
  	//printf("%c",a[0]);

    if(a[0]=='1')
      ++counter;
    if(a[1]=='1')
      ++counter;
	if(a[2]=='1')
      ++counter;
  	
  	printf("%d",counter);
  
    return 0;
}

Measured memory_bytes: 128
#include <random>
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  vector<int> v(3);
  for(int i=0;i<3;i++) cin >> v[i];
  int k;cin>>k;
  int cnt = 0;
  while(v[0]>=v[1]){
      cnt++;
      v[1] *= 2;
  }
  while(v[1]>=v[2]){
      cnt++;
      v[2] *= 2;
  }
  cout << (cnt<=k ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3644