akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
ll i ,j;
while(q--)
{
    ll n,m,k,l,r,a,b,c=0,g,counter=0,u,v,d,e,p,x,y,flag=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;

    cin >> a >> b >> c;
    cout << c << "  " << a << " " << b;

}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%tmod;}
    else{return (b*((temp*temp)%tmod))%tmod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
const int maxn=500009;
set<int> ss[26];
int main()
{
	char s[maxn];
	int n,q,iq,lq,rq,cq;
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++)
	{
		scanf("%c",&s[i]);
		ss[s[i]-'a'].insert(i);
	}
	cin>>q;
	int f;
	while(q--)
	{
		scanf("%d",&f);
		if(f==1)
		{
		scanf("%d",&iq);
		getchar();
		scanf("%c",&cq);
		ss[s[iq]-'a'].erase(iq);
		s[iq]=cq;//
		ss[cq-'a'].insert(iq);
	    }
	    else
	    {
	    	scanf("%d%d",&lq,&rq);
	    	int num=0;
	    	set<int>::iterator it;
			for(int i=0;i<26;i++)
			{
				it=ss[i].lower_bound(lq);
				if(it!=ss[i].end()&&*it<=rq)
				num++;
			}
			printf("%d\n",num);
		}
	}
	return 0;
}

Measured memory_bytes: 24192
x = gets
y = x.split
#
# if b[0].to_i < 0 || b[1].to_i < 0 || b[2].to_i < 0
#   return
# end
#
# if 100 < b[0].to_i || 100 < b[1].to_i || 100 < b[2].to_i
#   return
# end

if y[0].to_i < y[1].to_i && y[1].to_i < y[2].to_i && y[0].to_i < y[2].to_i
  puts "Yes"
  else
  puts "No"
end



Measured memory_bytes: 6844
var
  d,n,x,y,ans:int64;
  i:longint;
begin
  readln(n,x);
  ans := 1;
  d := 0;
  for i:=1 to n do begin
    read(y);
    d := d + y;
    if(d<=x) then inc(ans);
  end;
  writeln(ans);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

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

    const ll nmax = 100001;
    vector<bool> prime(nmax, true);
    prime[0] = prime[1] = false;
    for(ll x = 2; x < nmax; x++){
        if(prime[x]) for(ll y = x*2; y < nmax; y += x) prime[y] = false;
    }
    
    vector<ll> like(nmax, 0);
    for(ll x = 3; x < nmax; x+=2){
        if(prime[x] && prime[(x+1)/2]) like[x] = like[x-2]+1;
        else like[x] = like[x-2];
    }

    rep(i, n){
        ll l, r; cin >> l >> r;
        ll cnt = 0;
        bool lp = prime[l] && prime[(l+1)/2], rp = prime[r] && prime[(r+1)/2];
        if(lp && rp) cnt = like[r] - like[l] + 1;
        else if(!lp && rp) cnt = like[r] - like[l];
        else if(lp && !rp) cnt = like[r] - like[l] + 1;
        else cnt = like[r] - like[l];
        
        cout << cnt << endl;
    }
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define int long long 
#define rep(i, N) for (int i = 0; i < N; i++)
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define vi vector<int>
#define vvi vector< vi >

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

    vvi day(n, vi(361, -1));

    rep(i, n) {
        //cout << endl;
        //cout << i << endl;
        int2(a, b);
        int2(d, c);
        rep(j, d) {
            day[i][(j + ((a - 1) * 30) + b - 1) % 360] = c;
            //cout << day[i][(j + (a * 30) + b) % 360] << " ";
        }
        int st = (a - 1) * 30 + b - 1;
        int en = (st + d - 1) % 360;
        rep(j, 360) {
            int dist = min( (st - j + 360) % 360,
                    (j - en + 360) % 360);
            day[i][j] = max(day[i][j], max(c - dist, 0LL));
            //cout << day[i][j] << " ";
        }
        //cout << endl;
    }

    int ans = INF;
    rep(j, 360) {
        int tmp = 0;
        rep(i, n) {
            tmp = max(tmp, day[i][j]);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3280
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
N, M = tuple(li())
coods = list(li())
if len(coods) == 1:
    print(0)
elif N >= M:
    print(0)
else:

    coods = sorted(coods)
    deltas = []
    former = coods[0]
    for cood in coods:
        delta = cood - former
        deltas.append(delta)
        former = cood

    deltas = sorted(deltas, reverse=True)
    total_dis = coods[-1] - coods[0]
    for i in range(N-1):
        total_dis -= deltas[i]

    print(total_dis)



Measured memory_bytes: 13948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=2000003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int H,W;cin>>H>>W;
        vector<string> S(H);
        for(int i=0;i<H;i++) cin>>S[i];
        
        vector<int> le(26,INF),ri(26,-INF),up(26,INF),lo(26,-INF);
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(S[i][j]=='.') continue;
                int c=int(S[i][j]-'A');
                
                le[c]=min(le[c],j);
                ri[c]=max(ri[c],j);
                up[c]=min(up[c],i);
                lo[c]=max(lo[c],i);
            }
        }
        
        vector<int> use;
        
        for(int i=0;i<26;i++) if(le[i]!=INF) use.push_back(i);
        
        bool ok=false;
        do{
            
            vector<vector<char>> T(H,vector<char>(W,'.'));
            
            for(int q=0;q<use.size();q++){
                int k=use[q];
                
                for(int i=up[k];i<=lo[k];i++){
                    for(int j=le[k];j<=ri[k];j++){
                        T[i][j]=char('A'+k);
                    }
                }
            }
            
            ok=true;
            
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(S[i][j]!=T[i][j]) ok=false;
                }
            }
            
            if(ok) break;
            
        }while(next_permutation(all(use)));
        
        if(ok) cout<<"SAFE"<<endl;
        else cout<<"SUSPICIOUS"<<endl;
        
    }
}







Measured memory_bytes: 3156
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, k = MAP()
a = LIST()
print((n - 1 + k - 2) // (k - 1))

Measured memory_bytes: 74056
import heapq as hq
from itertools import accumulate
from math import ceil
N, H = map(int, input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort(key=lambda x:x[0], reverse=True)
ma, mb = ab[0]
q = [ab[i][1] for i in range(1, N)]
q.sort(reverse=True)
ans = float("inf")
acc = [0]+list(accumulate(q, lambda x,y:x+y))
for l in range(len(q)+1):
    h = H
    cnt = l
    h -= acc[l]
    if h <= 0:
        ans = min(ans, cnt)
        continue
    h -= mb
    cnt += 1
    if h <= 0:
        ans = min(ans, cnt)
        continue
    cnt += ceil(h/ma)
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 29532
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    while(C > 0){
        if(A <= 0){
            cout << "No" << endl;
            return 0;
        }
        C -= B;
        A -= D;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3636
n=int(input())
ans=1
num=0
for i in range(1,n+1):
    check=i 
    c_num=0
    while check>0 and check%2==0:
        check//=2
        c_num+=1
    if num<c_num:
        num=c_num
        ans=i
print(ans)

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

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

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

typedef long long ll;

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

    vector<int> subs(n+1, 0);
    for (int x = 2; x <= n; x++) {
        int boss;
        cin >> boss;
        subs[boss] ++;
    }

    for (int x = 1; x <= n; x++)
        cout << subs[x] << '\n';

    return 0;
}



Measured memory_bytes: 4048
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

typedef long long ll, lint;
typedef long double ldouble;

#define sz(v) ((int) (v).size())
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define For(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

template<class T>
string to_string(T arr, int len = 1e9) {
    stringstream ss;
    int i = 0;
    for (auto item : arr) {
        ss << item << ' ';
        if (++i == len)
            break;
    }
    return ss.str();
}

#ifdef LOCAL
    #define dbg(expr) cout << "[line " << __LINE__ << "] " << (#expr) << ": " << (expr) << endl;
#else
    #define dbg(expr) (void) 0;
#endif


const lint inf = 1e18;

struct Edge {
    int v, u;
    lint w;

    Edge() {}

    Edge(int v, int u, lint w): v(v), u(u), w(w) {}
};

struct Graph {
    vector<vector<Edge>> edges;

	Graph(int size) {
        edges.resize(size);
	}

    void add_edge(int v, int u, lint w) {
        edges[v].emplace_back(v, u, w);
        edges[u].emplace_back(v, u, w);
    }

    void dfs(int v, vector<int>& marked, map<int, lint>& x) {
        marked[v] = true;
        for (auto e : edges[v]) {
            int nxt = e.v;
            if (v == e.v) {
                nxt = e.u;
                x[nxt] = x[v] + e.w;
            } else
                x[nxt] = x[v] - e.w;
            if (!marked[nxt])
                dfs(nxt, marked, x);
        }
    }

    bool check() {
        vector<int> marked(size());
        map<int, lint> x;
        For (v, size()) {
            if (marked[v])
                continue;
            x[v] = 0;
            dfs(v, marked, x);
        }
        For (v, size()) {
            for (auto e : edges[v]) {
                if (x[e.u] - x[e.v] != e.w)
                    return false;
            }
        }
        lint min_value = inf;
        lint max_value = -inf;
        for (auto i : x) {
            min_value = min(min_value, i.second);
            max_value = max(max_value, i.second);
        }
        if (max_value - min_value > 1e9)
            return false;
        return true;
    }

    int size() const {
        return edges.size();
    }
};

int main() {
#ifndef LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(false);
#endif

    int n, m;
    cin >> n >> m;
    auto g = Graph(n);
    For (i, m) {
        int l, r, w;
        cin >> l >> r >> w;
        l--;
        r--;
        g.add_edge(l, r, w);
    }
    if (g.check())
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 23424
from sys import stdin
N = int(stdin.readline().rstrip())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

ans = 0
for i in make_divisors(N):
    if i != 1:
      if N//(i-1) == N % (i-1):
          ans += (i-1)
print(ans)

Measured memory_bytes: 3268
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int a,b,c,k;cin >> a >> b >> c >> k;
    for(int i=0;i<k;i++){
        if(b <= a) b *= 2;
        else if(c <= b) c *= 2;
    }

    if(a < b && b < c){
        cout << "Yes" << enld;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
 using namespace std;
 int mod(int n)
 {
     int div=ceil(n/-2)*-2;

     return n-div;
 }

 int main()
 {

    long long n;
    cin >> n;
    int cnt=0;

    string str;
    if(n==0){
        cout << 0 << endl;
    }
    else{
    while(n)
    {

        int temp=mod(n);
        if(temp==0)
            str+='0';
        else
            str+='1';
        n=ceil(n*1.0/-2);

    }
    reverse(str.begin(),str.end());
    cout << str << "\n";
    }
 }

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
H = gets.split.map(&:to_i)
H.unshift :padding
G = Array.new(N, 1)
G.unshift 0
M.times do 
    a, b = gets.split.map(&:to_i)
    G[a] = 0 if H[a] <= H[b]
    G[b] = 0 if H[b] <= H[a] 
end
puts G.sum

Measured memory_bytes: 23292
#include <cstdio>

const int P=998244353;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
inline int add(int a,const int &b){a+=b;return(a>=P)?a-P:a;}
inline int sub(int a,const int &b){a-=b;return (a<0)?a+P:a;}
int qsm(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
int n,A[401],B[401],Sa,Sb,f[401][401][401],inv,invmul[401],_mul[401];
int main(){
	_mul[0]=_mul[1]=invmul[0]=invmul[1]=1;
	for(int i=2;i<=400;i++)_mul[i]=mul(_mul[i-1],i);
	for(int i=2;i<=400;i++)invmul[i]=mul(P-P/i,invmul[P%i]);
	for(int i=2;i<=400;i++)invmul[i]=mul(invmul[i-1],invmul[i]);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",A+i,B+i),Sa+=A[i],Sb+=B[i];
	inv=qsm(Sa,P-2);
	f[0][0][0]=1;
	int ta=0,tb=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=ta;j++)
			for(int k=0;k<=tb;k++){
				f[i][j+A[i]][k]=add(f[i][j+A[i]][k],f[i-1][j][k]);
				for(int l=0,Mul=P-1;l<B[i];l++)
					f[i][j][k+l]=add(f[i][j][k+l],mul(mul(Mul,invmul[l]),f[i-1][j][k])),Mul=mul(Mul,mul(A[i],inv));
			}
		ta+=A[i],tb+=B[i];
	}
	int ans=0;
	for(int i=0;i<=Sa;i++)
		for(int j=0;j<=Sb;j++)
			ans=sub(ans,mul(mul(qsm(qsm(sub(1,mul(i,inv)),P-2),j+1),_mul[j]),f[n][i][j]));
	printf("%d\n",ans);
}

Measured memory_bytes: 249984
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#define ll long long 
#define dd double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int r,d,x;
  cin>>r>>d>>x;
  int t=10;
  int x1;
  while(t--){
  	x1=(r*x)-d;
  	cout<<x1<<endl;
  	x=x1;
  }
  
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  	int n;
  	cin>>n;
  	vector<int> v(n);
  	int sum = 0;
  	for(int i = 0; i < n; i++)
    {
    	cin>>v[i];
      	sum += v[i];
    }
  	int tr = round(double(sum) / double(n));
  	int res = 0;
  	for(int i = 0; i < n; i++)
    {
    	int d = v[i]-tr;
      	res += d*d;
    }
  	cout<<res<<"\n";
	return 0;
}


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

using namespace std;

#define fo(i,a,b) for (int i=a;i<=b;i++)
#define fd(i,a,b) for (int i=a;i>=b;i--)
#define fi first
#define se second	
#define mkp make_pair

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

const int N=1100000;

int n,son[N][3],v[N][3];
ll l,r,lim;
vector<P> p[N];

int read()
{
	int ret=0,sig=1;
	char c;
	while (c=getchar(),(c<'0'||c>'9')&&c!='-');
	if (c=='-') sig=-1;
	else ret=c-'0';
	while (c=getchar(),c>='0'&&c<='9') ret=ret*10+c-'0';
	return ret*sig;
}

void dfs(int pos)
{
	if (!son[pos][0])
	{
		p[pos].push_back(mkp(0,0));
		return;
	}
	int x=son[pos][1],y=son[pos][2];
	dfs(x);
	dfs(y);
	vector<P> A,B;
	for (int i=0,j=0;i<p[x].size();i++)
	{
		while (j<p[y].size()&&lim-p[x][i].se-p[y][j].fi-v[pos][1]-v[pos][2]>=0) j++;
		if (j) A.push_back(mkp(p[x][i].fi+v[pos][1],p[y][j-1].se+v[pos][2]));
	}
	for (int i=0,j=0;i<p[y].size();i++)
	{
		while (j<p[x].size()&&lim-p[y][i].se-p[x][j].fi-v[pos][1]-v[pos][2]>=0) j++;
		if (j) B.push_back(mkp(p[y][i].fi+v[pos][2],p[x][j-1].se+v[pos][1]));
	}
	int a=0,b=0;
	while (a<A.size()||b<B.size())
	{
		if (b==B.size()||(a!=A.size()&&(A[a].fi<B[b].fi||(A[a].fi==B[b].fi&&A[a].se<B[b].se))))
		{
			if (p[pos].empty()||A[a].se<p[pos][p[pos].size()-1].se) p[pos].push_back(A[a]);
			a++;
		}
		else
		{
			if (p[pos].empty()||B[b].se<p[pos][p[pos].size()-1].se) p[pos].push_back(B[b]);
			b++;
		}
	}
}

bool check()
{
	fo(i,1,n)
		while (!p[i].empty()) p[i].pop_back();
	dfs(1);
	if (!p[1].empty()) return true;
	return false;
}

int main()
{
	n=read();
	fo(i,2,n)
	{
		int fa=read(),a=read();
		son[fa][++son[fa][0]]=i;
		v[fa][son[fa][0]]=a;
		r+=a;
	}
	while (l<r)
	{
		ll mid=(l+r)/2;
		lim=mid;
		if (check()) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",r);
	return 0;
}
            

Measured memory_bytes: 55916
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define INF 1000000000
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int num[100]={};
	for(int i=0; i<n; i++){
		int a;
		scanf("%d", &a);
		num[a]++;
	}
	int R;
	for(int i=99; i>0; i--){
		if(num[i]>0){
			R=i;
			break;
		}
	}
	if(R%2==0){
		for(int i=1; i<R/2; i++){
			if(num[i]>0){
				printf("%s\n", "Impossible");
				return 0;
			}
		}
		if(num[R/2]!=1){
			printf("%s\n", "Impossible");
			return 0;
		}
		for(int i=R/2+1; i<=R; i++){
			if(num[i]<=1){
				printf("%s\n", "Impossible");
				return 0;
			}
		}
		printf("%s\n", "Possible");
	}else{
		for(int i=1; i<=R/2; i++){
			if(num[i]>0){
				printf("%s\n", "Impossible");
				return 0;
			}
		}
		if(num[(R+1)/2]!=2){
			printf("%s\n", "Impossible");
			return 0;
		}
		for(int i=(R+1)/2+1; i<=R; i++){
			if(num[i]<=1){
				printf("%s\n", "Impossible");
				return 0;
			}
		}
		printf("%s\n", "Possible");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;



int main()
{
	ll int n, m, div;
	cin >> n >> m;
	div = n / m;

	if (div) {
		n -= (m * div);
	}

	if (n > m - n) {
		printf("%lld", m - n);
	} else {
		printf("%lld", n);
	}



	return 0;
}

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

int main () {
  int N; cin >> N;
  
  vector<int>A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  
  sort (A.begin(), A.end());
  int ans = A.at(N-1) -A.at(0);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def solve(N, H):
    dp = [0] * N
    dp[0] = H[0] - 1
    for i in range(N-1):
        if dp[i] - H[i+1] >= 1:
            return False
        else:
            dp[i+1] = H[i+1] if dp[i] == H[i+1] else H[i+1] - 1

    return True


def main():
    N = int(input())
    H = list(map(int, input().split()))
    if solve(N, H):
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 14172
#include <stdio.h>

long long i, N, D, X[200001], Y[200001], count;

int main() {
	count = 0;
	scanf("%lld %lld", &N, &D);
	for (i = 1; i <= N; i++) {
		scanf("%lld %lld", &X[i], &Y[i]);
		if (D * D >= X[i] * X[i] + Y[i] * Y[i]) {
			count = count + 1;
		}
	}printf("%lld", count);
	return 0;
}

Measured memory_bytes: 4808
# coding: utf-8
from bisect import bisect_left, bisect_right
def check(x):
    flag = True
    for i in range(2, int(x**0.5) + 1):
        if x % i == 0:
            flag = False
            break
    return flag

def primes(n):  
    is_prime = [True] * (n + 1)  
    is_prime[0] = False  
    is_prime[1] = False  
    for i in range(2, int(n**0.5) + 1):  
        if not is_prime[i]:  
            continue  
        for j in range(i * 2, n + 1, i):  
            is_prime[j] = False  
    return [i for i in range(n + 1) if is_prime[i]]
def primes_plus(l):
    # l: 素数の配列
    L = []
    for p in l:
        if check((p+1)//2):
            L.append(p)
    return L
l_primes = primes(10**6)
l_primes = primes_plus(l_primes)[1:]
# print(len(l_primes))
Q = int(input())
for i in range(Q):
    ans = 0
    l, r = map(int, input().split())
    r += 1
    l_idx = bisect_left(l_primes, l)
    r_idx = bisect_left(l_primes, r)
    # print(l_idx, r_idx)
    if l == r and l_idx == r_idx and l == l_primes[l_idx]:
        print(1)
    else:
        print(r_idx - l_idx)
# print(l_primes)

Measured memory_bytes: 14032
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int n,m;
int a[100010],b[100010];
int ans[100010];
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		ans[a[i]]++;
		ans[b[i]+1]--;
	}
	for(int i=1;i<n;i++){
		ans[i]+=ans[i-1];
	}
	int aans=0;
	for(int i=0;i<n;i++){
		if(ans[i]==m)aans++;
	}
	cout<<aans<<endl;
    return 0; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MOD = 998244353;
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
inline ll qpow(ll a, ll b)
{
    int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
bool ok(string s, int l, int r)
{
    while (s[l] == s[r])
        ++l, --r;
    return l >= r;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    int n=s.size();
    if(ok(s,0,n-1)&&ok(s,0,(n-1)/2-1)&&ok(s,(n+3)/2-1,n-1))
      cout<<"Yes\n";
    else
      cout<<"No\n";
}


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

signed main(){
    int n; cin>>n;
    vector<int> a(n); rep(i,n) cin>>a.at(i);
    int ans1=0,ans2=0,sum=0;
    rep(i,n){
        sum+=a.at(i);
        if(i%2==0){
            if(sum<=0){
                ans1+=1-sum;
                sum=1;
            }
        }else{
            if(sum>=0){
                ans1+=sum+1;
                sum=-1;
            }
        }
    }
    sum=0;
    rep(i,n){
        sum+=a.at(i);
        if(i%2!=0){
            if(sum<=0){
                ans2+=1-sum;
                sum=1;
            }
        }else{
            if(sum>=0){
                ans2+=sum+1;
                sum=-1;
            }
        }
    }
    cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < n; i++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define FOR(i,m, n) for(int i = m-1; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
using namespace std;
typedef long long ll;
int main(){
    int h,a,k;
    cin>>h;
    cin>>a;
    if(h%a==0)cout<<h/a;
    else{
        cout<<h/a+1;
    }
    cout<<endl;
}

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

int main(){
    int N=0;
    cin >> N;
    double A[N];
    double ans=0;
    for (int i=0;i<N;++i) cin >> A[i];

    for (int i=0;i<N;++i){
        ans += 1 / A[i];
    }

    cout << 1/ans << endl;

}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


		
#階乗#
lim = 10**5   #必要そうな階乗の限界を入力
fact = [1] * (lim+1)
for n in range(1, lim+1):
	fact[n] = n * fact[n-1] % mod

#階乗の逆元#
fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	if n < r:
		return 0
	else:
		return (fact[n]*fact_inv[r]%mod)*fact_inv[n-r]%mod

N, K = MAP()
A = LIST()
A.sort()

ans = 0
for i in range(K-1, N):
	ans += A[i] * C(i, K-1)
	ans %= mod

for i in range(N-K+1):
	ans -= A[i] * C(N-i-1, K-1)
	ans %= mod

print(ans)

Measured memory_bytes: 29468
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

double distance(int i, int j, int x[], int y[]){
    double dx = x[j] - x[i];
    double dy = y[j] - y[i];
    return std::pow(dx*dx + dy*dy, 0.5);
}

int main(void){
    int n;
    std::cin >> n;

    int x[n+1];
    int y[n+1];
    for(int i = 1; i < n+1; i++){
        std::cin >> x[i] >> y[i];
    }

    std::vector<int> v(n);
    for(int i = 0; i < n; i++) v[i] = i+1;

    double sum = 0.0;

    do {
        for(int i = 0; i < n-1; i++) sum += distance(v[i], v[i+1], x, y);
    } while(std::next_permutation(v.begin(), v.end()));

    double Factorial = 1;
    for(int i = 2; i <= n; i++) Factorial *= i;

    double ans = sum / Factorial;
    printf("%.15lf", ans);
    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
int n, s, count = 0, digits[10];
void dfs(int cur, int start) {
               if(cur == n) {
                  int sum = 0;
 for(int i = 0; i < n; i++) { sum += digits[i];
 }
     if(sum == s) { count++; }
     return;
 }
 for(int i = start; i < 10; i++) {
     digits[cur] = i; 
     dfs(cur+1, i+1);
   }
}

int main(void){
   while(scanf("%d %d",&n,&s)!= EOF){
       if(n == 0 && s == 0){
           break;
       }
       count = 0;
       dfs(0, 0);
       printf("%d\n", count);
   }
 return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };


signed main() {
	ios::sync_with_stdio(false);
	int k, s, i, j,r;
	cin >> k >> s;
	int ans = 0;
	rep(i, k + 1) {
		rep(j, k + 1) {
			int z = s - i - j;
			if (i + j + z == s) {
				if((z >= 0) and z <= k)
					ans++;
				//cout << i << "+" << j << '+' << (s - (i + j)) << '=' << s  << endl;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())

#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define fora(i, a, b) for(int i = (a); i < (b); i++)
#define ford(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watch_all(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)
	
#define INF 0x3F3F3F3F

//=========================

int H[100001];
int dp[100001];

void run_test() {
	int N, K; cin >> N >> K;
    for0(i, N) cin >> H[i];
    ini(dp, 0x3f);
    dp[0] = 0;
    for0(i, N)
        for1(k, K)
            if(i+k < N) 
                dp[i+k] = min(dp[i+k], dp[i] + abs(H[i+k]-H[i]));
    cout << dp[N-1] << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t; while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	//infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	//if(infile.good()) infile.close();
}


Measured memory_bytes: 4568
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>

using namespace std;
int main(){
	int x;
	cin>>x;
	int sum = 0;
	for(int i = 1;i <= x;i+=2){
		int flag = 0;
		for(int j = 1;j <= i;j+=2){
			if(i%j==0) flag++;
		}
		if(flag == 8) sum++;
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;

signed main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a-b>0){
      if(c > (a-b)){
        cout << c-(a-b);
      }else{
        cout << 0;
      }
    }else {
      cout << c;
    }
    return 0;
      
}


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

int main(){
  ll n; cin >> n;
  ll w = pow(n,0.5);
  ll c;
  for(ll i = w; i>=1; i--){
    if(n%i == 0){
      c = i;
    break;
    }
  }
  ll b = n / c;
  ll ans = c+b-2;
  cout << ans << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long n,a,b,c,d,e,f;
  cin >>n>>a>>b>>c>>d>>e;
  f=min(min(a,b),min(c,d));
  f=min(f,e);
  if(f==1){
    cout << n/f+4;
    return 0;
  }
  cout << n/f+5;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || c + b == a) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    double x[2],y[2],r[2],h;
    for(int j=0;j<2;j++) scanf("%lf %lf %lf",&x[j],&y[j],&r[j]);
    h=hypot(abs(x[0]-x[1]),abs(y[0]-y[1]));
    if(h+r[1]<r[0]) puts("2");
    else if(h+r[0]<r[1]) puts("-2");
    else if(h<=r[0]+r[1]) puts("1");
    else puts("0");
  }
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{
	int N = 3;
	int num[3];
	for(int i = 0; i < N; i++)
	{
		cin >> num[i];
	}

	bool check = false;
	int cnt[11];
	for(int i = 0; i < N; i++)
	{
		cnt[num[i]]++;
	}

	check = cnt[5] == 2 && cnt[7] == 1;
	
	if (check)
		cout << "YES";
	else
		cout << "NO";
	
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.math;
import std.range;
import std.algorithm;

void main()
{
  double theta = 0;
  double x = 0, y = 0;
  foreach (s; stdin.byLine) {
    auto num = s.split(",").map!(to!int)();
    if (!num[0] && !num[1]) break;
    x += sin(theta * (PI / 180)) * num[0];
    y += cos(theta * (PI / 180)) * num[0];
    theta += num[1];
  }
  x.trunc.writeln();
  y.trunc.writeln();
}

Measured memory_bytes: 1176
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	fmt.Printf("%d\n", resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) (int, []int, []int) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	n := scanInt(sc)
	hs := make([]int, n)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		hs[i] = scanInt(sc)
	}
	for i := 0; i < n; i++ {
		as[i] = scanInt(sc)
	}
	return n, hs, as
}

func resolve(n int, hs, as []int) int {
	// dp min hight dp[i][j] items < i, hight = j
	// dp[i+1][h] = max_(k<h)(dp[i][k] + a[i]) // h[i] == h
	// dp[i+1][h] = dp[i][h]                   // h[i] != h
	// -> dp[h[i]] = max_(k<h[i]){dp[k]+a[i]}
	l := 0
	for i := 0; i < len(hs); i++ {
		if l < hs[i] {
			l = hs[i]
		}
	}
	t := newSegTree(l + 1)
	for i := 0; i < n; i++ {
		v := t.query(0, hs[i])
		t.update(hs[i], v+as[i])
	}
	return t.query(0, l+1)
}

func max(a []int) int {
	m := a[0]
	for _, v := range a {
		if v > m {
			m = v
		}
	}
	return m
}

type segTree struct {
	n int
	l []int
}

func newSegTree(n int) *segTree {
	size := 1
	for size < n {
		size <<= 1
	}
	t := &segTree{
		n: size,
		l: make([]int, size*2+1),
	}
	return t
}

func (t *segTree) update(idx int, v int) {
	if v == 90 {
		panic(1)
	}
	cur := t.n + idx - 1
	t.l[cur] = v
	for cur > 0 {
		cur = (cur - 1) / 2
		changeToMax(&(t.l[cur]), v)
	}
}
func (t *segTree) query(a, b int) int {
	// [a, b)
	return t._query(a, b, 0, 0, t.n)
}

func (t *segTree) _query(a, b, k, l, r int) int {
	if r <= a || b <= l { // unmatch
		return 0
	}
	if a <= l && b >= r { // involved
		return t.l[k]
	}
	// part match
	vl := t._query(a, b, k*2+1, l, (l+r)/2)
	vr := t._query(a, b, k*2+2, (l+r)/2, r)
	return max([]int{vl, vr})
}

const (
	inf  = math.MaxInt32
	ninf = math.MinInt32
)

func changeToMin(v *int, cand int) (updated bool) {
	if *v > cand {
		*v = cand
		updated = true
	}
	return updated
}

func changeToMax(v *int, cand int) (updated bool) {
	if *v < cand {
		*v = cand
		updated = true
	}
	return updated
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 11392
/*************************************
 * @contest:      AtCoder ABC156.
 * @user_id:      63720.
 * @user_name:    Jomoo.
 * @time:         2020-02-22.
 * @language:     C++.
 * @upload_place: Luogu.
*************************************/ 

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

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline Int read(char &c)       
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
    return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int N, R;

int main()
{
    R = read<int>();
    N = read<int>();
    if (R < 10) {
        write(N + (10 - R) * 100, 10);
    } else {
        write(N, 10);
    }
    return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> h(n);
  for (long long& hi : h) {
    cin >> hi;
  }
  vector<long long> dp(n, INT_MAX);
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = i - k; j < i; ++j) {
      if (j < 0) continue;
      dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
typedef long long ll;
ll x[100005];
ll y[100005];
int modd = 1e9 + 7;
ll ans,ansx,ansy;
int main() {
//    freopen("in.txt", "r", stdin);
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%lld", &x[i]);
    for (int i = 0; i < m; i++)
        scanf("%lld", &y[i]);
    for (ll i = 1; i < n; i++)
        ansx = (ansx + i * (n - i) % modd * (x[i] - x[i - 1]) % modd ) % modd;
    for (ll i = 1; i < m; i++)
        ansy = (ansy  + i * (m - i) % modd * (y[i] - y[i - 1]) % modd) % modd;
    ans = ansx * ansy % modd;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        rep(i,a) cout<<b;
        cout<<endl;
    }else{
        rep(i,b) cout<<a;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
dp = [0] * 20005
for w, s, v in sorted((map(int, input().split()) for i in xrange(int(input()))) , key = lambda i: i[0] + i[1]):
    for weight in xrange(s, -1, -1):
        dp[weight + w] = max(dp[weight] + v, dp[weight + w])
print max(dp)

Measured memory_bytes: 32748
<?php

$N = trim(fgets(STDIN));
$A = explode(" ",trim(fgets(STDIN)));

$gcd1[0] = $A[0];
$gcd2[0] = $A[$N-1];

for ( $i = 1; $i < $N; $i++) {
    $gcd1[$i] = my_gcd( $gcd1[$i-1], $A[$i-1] );
    $gcd2[$i] = my_gcd( $gcd2[$i-1], $A[$N-$i] );
}

$gcd[0] = $gcd2[$N-1];
$gcd[$N-1] = $gcd1[$N-1];

for ( $i = 1; $i < $N - 1; $i++) {
    $gcd[$i] = my_gcd( $gcd1[$i], $gcd2[$N-$i-1] );
}

echo max($gcd);

function my_gcd($a,$b){
    $max = max($a,$b);
    $min = min($a,$b);
    if ($min==0) {
        return $max;
    } else{
        return my_gcd($max % $min,$min);
    }
}

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

#define ll     long long
#define fr     first
#define sec    second
#define rep(i,n)  for(i=0;i<n;i++)
#define vi     vector <int>
#define vc     vector <char>
#define vl     vector <ll>
#define vb     vector <bool>
#define pb     push_back
#define M      1000000007
#define ios    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define open   freopen("input.txt","r",stdin);
#define close  freopen("output.txt","w",stdout);
#define M_PI   3.14159265358979323846
#define pp     pair<int,int>
#define nn 100003
#define MM 1000000000
#define MN 1000000000000000000
int main()
{
    ios;
    ll n,k,i,j,x,ans=0;
    cin>>n>>k;
    ll d;
    map <ll,vl> m;
    for(i=1;i<=k;i++)
    {
        cin>>d;
        rep(j,d)
        {
            cin>>x;
            m[x].pb(i);
        }
    }
    for(i=1;i<=n;i++)
    {
        if(m.find(i)==m.end())
            ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3632
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

X = ins()


def solve():
    ans = sum([int(d) for d in X])

    ans = max(ans, int(X[0]) - 1 + 9 * (len(X) - 1))

    return ans


print(solve())


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<3;i++){
        if(s[i]=='1'){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

public class Test
{
	public static void Main( )
	{
		string str = Console.ReadLine();
		int q = int.Parse( Console.ReadLine() );
		for( var i=0; i<q; i++ ) {
			string[] cmds = Console.ReadLine().Split( ' ' );
			int s = int.Parse( cmds[1] );
			int e = int.Parse( cmds[2] );
			int len = e-s+1;
			if( "print" == cmds[0] ) {
				Console.WriteLine( str.Substring( s, len ) );
			} else if( "reverse" == cmds[0] ) {
				string t = new string( str.Substring( s, len ).Reverse().ToArray() );
				str = str.Substring( 0, s )+t+str.Substring( e+1 );
			} else if( "replace" == cmds[0] ) {
				str = str.Substring( 0, s )+cmds[3]+str.Substring( e+1 );
			}
		}
	}
}

Measured memory_bytes: 9496
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
aN = LIST()

# dp[この子までの範囲で][飴を配る総数] = 場合の数
dp = [[0] * (K+1) for i in range(N+1)]
# 0番目まで(誰もいない)の範囲で0個配る場合の数は1通り
dp[0][0] = 1

for i in range(N):
    sm = [0] * (K+2)
    # 今回送るi行について累積和を取る
    for j in range(1, K+2):
        sm[j] = sm[j-1] + dp[i][j-1]
        sm[j] %= MOD
    for j in range(K+1):
        # iが送る予定の長さに応じた区間和を取る
        dp[i+1][j] = sm[j+1] - sm[max(j-aN[i], 0)]
        dp[i+1][j] %= MOD
        # for k in range(aN[i]+1):
        #     dp[i+1][j+k] += dp[i][j]
print(dp[N][K])


Measured memory_bytes: 146500
#include <bits/stdc++.h>
#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;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[100010];
map<int,int> mp;

int main(){
    int n;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        mp[a[i]]++;
    }

    int k = mp.size();

    if (k%2 != 0) cout << k << endl;
    else cout << k - 1 << endl;

    return 0;
}


Measured memory_bytes: 8632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
ll INF=9210000000000000000;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll>v(n);rep(i,n)cin>>v[i];
    ll ans=INF;
    for(int i=0;i+k-1<n;i++){
        ll l=v[i],m=v[i+k-1];
        if(m<0)ans=min(ans,-l);
        else if(l>0)ans=min(ans,m);
        else ans=min(ans,min(l*-2+m,-l+m*2));
    }
    cout<<ans;
}

Measured memory_bytes: 1024