akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    vector<string> s(n);rep(i,n)cin>>s[i];
    vector<P> duplus, duminus, duzero;
    rep(i,n){
        string str = s[i];
        ll u = 0, d = 0;
        rep(j,str.size()){
            if(str[j]=='(')u+=1;
            else{
                u-=1;
                d=min(d,u);
            }
        }
        if(u>=0)duplus.push_back({d,u});
        else duminus.push_back({d-u,u});

    }
    sort(rALL(duplus));
    sort(ALL(duminus));
    ll pos = 0;

    for(P p:duplus){
        if(pos+p.first<0){
            cout<<"No";
            return 0;
        }
        pos+=p.second;
    }
    for(P p:duminus){
        if(pos+p.first+p.second<0){
            cout<<"No";
            return 0;
        }
        pos+=p.second;
    }
    if(pos==0)cout<<"Yes";
    else cout<<"No";

    return 0;
}

Measured memory_bytes: 50304
n, k = map(int, input().split())

ans = 0
if k == 0:
    ans = n*n
else:
    for b in range(k+1, n+1):
        p = n // b
        ans += (b-k)*p
        r = n % b
        if r >= k:
            ans += r-k+1
print(ans)


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

Measured memory_bytes: 596
#木の根を求める
def find(x,par):
    if par[x] == x:
        return x
    else:
        return find(par[x],par)

#xとyの属する集合の併合
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y,par):
    return find(x,par) == find(y,par)
    
h, w = map(int,input().split())
s = [["dammy"] * (w+2)]
for i in range(h):
    s.append(["dammy"]+list(input())+["dammy"])
s.append(["dammy"] * (w+2))

par = [i for i in range(h*w+1)] #index調整
rank = [1] * (h*w+1) #index調整

for i in range(1,h+1):
    for j in range(1,w+1):
        index = w*(i-1)+j
        if s[i][j] == "#": #黒
            if s[i-1][j] == ".":
                unite(index, index-w, par, rank)
            if s[i+1][j] == ".":
                unite(index, index+w, par, rank)
            if s[i][j-1] == ".":
                unite(index, index-1, par, rank)
            if s[i][j+1] == ".":
                unite(index, index+1, par, rank)
        elif s[i][j] == ".": #白
            if s[i-1][j] == "#":
                unite(index, index-w, par, rank)
            if s[i+1][j] == "#":
                unite(index, index+w, par, rank)
            if s[i][j-1] == "#":
                unite(index, index-1, par, rank)
            if s[i][j+1] == "#":
                unite(index, index+1, par, rank)

bw = [[0,0] for i in range(h*w+1)]
parset = set()

for i in range(1,h+1):
    for j in range(1, w+1):
        index = w*(i-1)+j
        parent = find(index,par)
        if not parent in parset:
            parset.add(parent)
        if s[i][j] == "#":
            bw[parent][0] += 1
        elif s[i][j] == ".":
            bw[parent][1] += 1

ans = 0

for i in list(parset):
    ans += (bw[i][0] * bw[i][1])
    
print(ans)

Measured memory_bytes: 34700
#include <bits/stdc++.h>
#include <vector>
#include <cmath>

using namespace std;

int n;
int cnt=0;
vector< vector<int> > board;

void sol(vector<int> che, int now){
	int flag=0;
	int jud=1;

	for(int i=1;i<n;i++) jud*=che[i];
	if(jud==1){
		cnt++;
		for(int i=2;i<n;i++) che[i]=0;
		che[1]=1;
		flag=1;
	}

	if(flag==0){
		for(int i=1;i<n;i++){
			if(board[now][i]==1 && che[i]==0){
				che[i]=1;
				sol(che, i);
				che[i]=0;
			}
		}
	}
	
}

int main(){

	int m, a, b;
	vector<int> che;

	cin>> n >> m;
	n++;

	che.resize(n);
	for(int i=2;i<n;i++) che[i]=0;
	che[1]=1;
	board.resize(n);
	for(int i=0;i<n;i++) board[i].resize(n);

	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			board[i][j]=0;
		}
	}

	for(int i=0;i<m;i++){
		cin>> a >> b;
		board[a][b]=1;
		board[b][a]=1;
	}

	sol(che, 1);

	cout<< cnt << endl;


}

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

const int MX = 100005;

int main() {
  int n;
  cin >> n;
  vector<ll> cnt(MX);
  rep(i, n) {
    int a;
    cin >> a;
    cnt[a]++;
  }

  ll s = 0;
  rep(i, MX) s += i * cnt[i];

  int q;
  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    s += c * cnt[b] - b * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 4008
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

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

	cin >> K;
	for (int i = 0; i < K; i++) {
		cin >> N >> M;
		long long int ans = 0;
		if (N > M) {
			swap(N, M);
		}
		ans = (N - 1) * 2;
		if (M - 1 > N) {
			ans++;
		}
		long long int m = M - 1;
		for (long long int j = sqrt(N*M - 1); j >= N + 1; j--) {
			if ((N*M - 1) / j > N&&j == (N*M - 1) / j) {
				ans++;
			}
			else if ((N*M - 1) / j > N&&j < (N*M - 1) / j) {
				ans += (j - N) * 2;
				break;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=result.begin();i!=result.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
//#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

int main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
    lli a;
  cin>>a;
  cout<<a*a*3;









    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll a = in(), b = in();
    cout << (
        a <= 5 ? 0 :
        a <= 12 ? b / 2 :
        b
        ) << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    L = [0] * (10**6+1)
    for a in A:
        L[a] += 1
    ans = 0
    Ng = [False] * (10**6+1)
    for a, cnt in enumerate(L):
        if cnt:
            for i in range(a*2, 10**6+1, a):
                Ng[i] = True
    for a, (cnt, ng) in enumerate(zip(L, Ng)):
        if cnt == 1 and not ng:
            ans += 1
    print(ans)

main()


Measured memory_bytes: 35048
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, x = inintm()
X = inintl()

if x not in X:
    X.append(x)
    n += 1

X.sort()

ans = X[1] - X[0]
prev = X[0]

for i in range(1,n):
    ans = min(math.gcd(ans, X[i]-prev), ans)
    prev = X[i]

print(ans)


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

int main() {
    string s;
    cin >> s;
    vector<int> cnt(3);
    for (int i = 0; i < (int)s.size(); i++) {
        cnt.at(s.at(i) - 'a')++;
    }
    if (max({cnt.at(0), cnt.at(1), cnt.at(2)}) - min({cnt.at(0), cnt.at(1), cnt.at(2)}) <= 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
/*
date 2018-__-__
time:from:  to:
problem's name:
statue:
writer:Patrick_y
*/
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#include <math.h>
#include <stdio.h>
#include <time.h>
#define mp make_pair
typedef long long ll;
using namespace std;
const int INF=20050226;
/*------------main part------------*/



vector<int> edg[100005];
int dis2[100005];
bool vis[100005];
int num1,num2;
int dis[100005];
void dfs(int x)
{
	if(vis[x])
		return;
	vis[x]=true;
	for(int i=0;i<edg[x].size();i++)
	{
		if(dis[edg[x][i]]>dis[x]+1)
		{
			dis[edg[x][i]]=dis[x]+1;
			dfs(edg[x][i]);
		}
	}
}
void df2(int x)
{
	if(vis[x])
		return;
	vis[x]=true;
	for(int i=0;i<edg[x].size();i++)
	{
		if(dis2[edg[x][i]]>dis[x]+1)
		{
			dis2[edg[x][i]]=dis2[x]+1;
			df2(edg[x][i]);
		}
	}
	return;
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		edg[x].push_back(y);
		edg[y].push_back(x); 
	}
	for(int i=0;i<=n;i++)
	{
		dis2[i]=dis[i]=INF;
	}
	dis[1]=0;
	dfs(1);
	memset(vis,0,sizeof(vis));
	dis2[n]=0;
	df2(n);
	for(int i=1;i<=n;i++)
	{
		if(dis[i]<=dis2[i])
		{
			num1++;
		}
		else
		{
			num2++;
		}
	}
	if(num1>num2)
	{
		cout<<"Fennec";
	}
	else
	{
		cout<<"Snuke";
	}
	return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long

int N, ans = 0;
string S;

void solve(){
    for(int i = 1; i < N;i++){
        int cnt = 0;
        string X = S.substr(0,i);
        string Y = S.substr(i,N-i);
        for(int j = 0; j < 27; j++){
            char buff = 'a'+j;
            if(X.find(buff) != string::npos && Y.find(buff) != string::npos) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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

    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    int n,cnt = 0, ans = 0; cin >> n;
    REP(i,n){
        cnt = 0;
        int I = i;
        while(I % 2 == 0) {
             cnt++;
             I /= 2;
        }
        ans = max(ans,cnt);
    }
    cout << pow(2,ans) << endl;
}





Measured memory_bytes: 3252
#include <iostream>
#include <cstdint>

using namespace std;

int main() {

    int64_t x, y;
    
    cin >> x >> y;
    
    if (y > 2 * x) {
        int64_t a = max((y - 2 * x) / 4, (int64_t)0);
        
        cout << x + a << "\n";
    }
    else {
        cout << y / 2 << "\n";
    }
    
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static int abs(int a){
        return (a>0)?a:(-a);
    }
    public static int gcd(int a,int b){
        if(a<0) return gcd(-a,b);
        if(b<0) return gcd(a,-b);
        if(a<b) return gcd(b,a);
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int X=sc.nextInt();
        int[] x=new int[N];
        
        if(N==1){
            x[0]=sc.nextInt();
            System.out.println(abs(x[0]-X));
            return ;
        }
        
        for(int i=0;i<N;i++){
            x[i]=sc.nextInt()-X;
        }
        
        int gcd=gcd(x[0],x[1]);
        
        for(int i=2;i<N;i++){
            gcd=gcd(gcd,x[i]);
        }
        
        System.out.println(gcd);
    }
}


Measured memory_bytes: 50820
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
string s[N+2];int aa[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;map<string,int>mp;
  for(int i=1;i<=n;i++)
  {
    cin>>s[i]>>aa[i];
    mp[s[i]]=i;
  }
  string ss;cin>>ss;int sm=0;
  for(int i=mp[ss]+1;i<=n;i++)
    sm+=aa[i];
  cout<<sm<<endl;
  
  return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  string a="";
  while(n){
    n--;
    int z=(n%(int)26);
    char x=z+'a';
    a+=x;
    n/=26;
  }
  reverse(a.begin(),a.end());
  cout<<a;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N;
    string S;
    cin >> N >> S;
    long long con = 0;
    for (int i = 0; i < N; ++i) if (S[i] == 'R') ++con;
    long long res = con;

    long long alr = 0;
    for (int i = 0; i < con; ++i) {
        if (S[i] == 'R') ++alr;
        chmin(res, con-alr);
    }
    cout << res << endl;
}

















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

int main() {
  
  string a;
  cin >> a;
  a[5] = ' ';
  a[13] = ' ';
  
  cout << a << endl;
  
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[int(e) for e in input().split()]
A.sort(reverse=True)
S=sum(A)
count=0
for i in range(N):
    if A[i]>=S/(4*M):
        count+=1
if count>=M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
N, A, B = list(map(int, input().split()))
C = A+B
x = list(input())
for i in x:
  if i == "c":
    print("No")
  elif i == "a" and C > 0:
    print("Yes")
    C -= 1
  elif i == "b" and C> 0 and B > 0:
    print("Yes")
    C -= 1
    B -= 1
  else:
    print("No")
    

Measured memory_bytes: 56184
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	string s;
	cin >> s;
	cin >> s;
	cout << 'A' << s[0] << 'C' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    ll ans = (1900 * m + 100 * (n - m)) * pow(2, m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4020
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define INF	1234567890

int N, M, D[1123], C[1123];
int ans = 0, memo[1123][1123];

// dp(i,j) := ??????i?????§j??\??§?????£??????????????´???????¨????????°????
int dp(int i, int j) {
	if (i == 0) { return 0; }
	if (i > j) { return INF; }
	else {
		if (memo[i][j] != -1) { return memo[i][j]; }
		return memo[i][j] = std::min(dp(i - 1, j - 1) + D[i-1] * C[j-1], dp(i, j - 1));
	}
}

int main(void) {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) { scanf("%d", &D[i]); }
	for (int i = 0; i < M; ++i) { scanf("%d", &C[i]); }

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

	printf("%d\n", dp(N, M));
	return 0;
}

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

int main(){

  int h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int time = (h2*60 + m2) - (h1*60 + m1);

  int ans = time - k;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3624
from collections import Counter
H, W, N, *L = map(int, open(0).read().split())
dic = {}
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[i*W+j] = dic.get(i*W+j,0)+1
c = Counter(dic.values())
ans = [(H-2)*(W-2)]+[0]*9
for k in c.keys():
  ans[k] = c[k]
  ans[0] -= c[k]
print('\n'.join(map(str,ans)))

Measured memory_bytes: 116276
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll n;
    cin>>n;
    ll res = 0;
    for(int i=1;i<=n;i++){
	ll tmp = i;
	ll cnt = 0;
	while(tmp>0){
	    cnt++;
	    tmp/=10;
	}
	if(cnt%2==1)res++;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/mnt/c/Users/moiki/bash/env/bin/python
N,K = map(int, input().split())

if K % 2 == 0:
    kinds_mod_0 = N//K
    kinds_mod_half = 0
    for i in range(1,N+1):
        if i % K == K//2:
            kinds_mod_half+=1
    print( kinds_mod_0**3 + kinds_mod_half**3)
else:
    kinds_mod_0 = N//K
    print(kinds_mod_0 ** 3)
    # for i in range(1, N+1):
    #     if i % K == 0:





Measured memory_bytes: 38640
n = int(input())
A = [int(x) for x in input().split()]
backward = [0] * n
forward = [0] * n
for i, a in enumerate(A):
    if i + a < n:
        forward[i + a] += 1
    if i - a >= 0:
        backward[i - a] += 1
ans = 0
for x, y in zip(forward, backward):
    ans += x * y
print(ans)


Measured memory_bytes: 32272
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

import math

n = int(input())

lis = factorization(n)

c = 0

for i in range(len(lis)):
    b = math.floor((lis[i][1]*2)**(1/2))
    if b*(b+1) > lis[i][1]*2:
        b = b - 1
    c = c + b
if n == 1:
    print(0)
else:
    print(c)



Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	string s;
    cin >> s;
    int n = s.size();
    while(n!=0){
        s[n-1] = 'x';
        n--;
    }
    cout << s;

}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;

int main(){
  double r;
  cin >> r;

  double S = r * r * M_PI;
  double shu = 2 * r * M_PI;

   printf("%.5f %.5f", S,shu);
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <map>
#include <set> 
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)

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

    int ans;
    if(n < 100) {
        ans = pow(100, d) * n;
    } else {
        ans = pow(100, d) * (n+1);
    } 
    
    cout << ans << endl;   

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef long double ld;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string a,b;
    cin>>a>>b;
    int n=a.size();
    for(int i=0;i<n;i++) {
        bool ok=1;
        for(int j=0;j<n;j++) {
            if(a[j]!=b[(i+j)%n])
                ok=0;
        }
        if(ok) {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}
/**



**/


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<stdio.h>
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=2e5+500;
const int inf=0x3f3f3f3f;
const int p=1e9+7;
int n;
char a[maxn],b[maxn];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    while(cin>>n>>a>>b){
        for(int i=0;i<n;i++){
            cout<<a[i]<<b[i];
        }cout<<endl;
    }
    return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123
typedef pair<ll, ll> P;



//initialization here
//
const int maxn = 1e5+10;

//
//initialization finish


// your function is here
//

//
// your function finished



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int n; cin >> n;
	vi a;

	rep(i, n)
	{
		int t; cin >> t;
		a.pb(t);
	}
	
	rvsort(a);

	int sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i += 2) sum1 += a[i];
	for (int i = 1; i < n; i += 2) sum2 += a[i];


	Print(sum1 - sum2);
	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
using static System.Math;
using System.Collections.Generic;
using System.Linq;
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        if (n == 1) { Console.WriteLine(0); goto exit; }
        if (IsPrime(n)) { Console.WriteLine(1); goto exit; }
        var a = GeneratePrime((int)Sqrt(n));
        var b = getPrime(n, a);
        getAns(b);
    exit:;
    }
    static void getAns(List<int> a)
    {
        var ans = 0;
        foreach (var x in a)
            ans += getN(x);
        Console.WriteLine(ans);
    }
    static int getN(int n)
    {
        var p = 1;
        while (true)
        {
            if (p * (p + 1) > 2 * n) return p - 1;
            else if (p * (p + 1) == 2 * n) return p;
            else p++;
        }
    }
    static bool IsPrime(long n)
    {
        if (n < 2) return false;
        else if (n == 2) return true;
        else if (n % 2 == 0) return false;
        double sqrtNum = Sqrt(n);
        for (int i = 3; i <= sqrtNum; i += 2)
            if (n % i == 0) return false;
        return true;
    }
    static List<int> getPrime(long n, List<int> a)
    {
        var ans = new List<int>();
        var t = n;
        for (int i = 0; i < a.Count(); i++)
        {
            if (a[i] > t) break;
            var count = 0;
            while (true)
            {
                if (t % a[i] == 0)
                {
                    t /= a[i];
                    count++;
                    if (t > a[i] && IsPrime(t)) { t = 1; ans.Add(1); }
                }
                else
                {
                    if (count > 0) ans.Add(count);
                    break;
                }
            }
        }
        return ans;
    }
    static List<int> GeneratePrime(int m)
    {
        var a = new List<int>();
        int p;
        var sqrtMax = Math.Sqrt(m);
        var s = Enumerable.Range(2, m - 1).ToList();
        do
        {
            p = s.First();
            a.Add(p);
            s.RemoveAll(n => n % p == 0);
        }
        while (p < sqrtMax);
        a.AddRange(s);
        return a;
    }
}

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

//--------------------------------------------
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

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

int main(){
  int h,w;
  string s;
  vector <string> v;

  cin >> h >> w;
  REP (i, h) {
    cin >> s;
    v.push_back(s);
  }

  REP (i, 2 * h) {
    REP (j, w) {
      cout << v.at(i / 2).at(j);
    }
    cout << "\n";
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, y;
  int i, j;
  int s = -1;
  int t = -1;
  int u = -1;
  
  scanf("%d", &n);
  scanf("%d", &y);
  
  for(i = 0; i <= n; i++){
    for(j = 0; j <= n - i; j++){
      if(y == (i * 10000 + j * 5000 + (n - i - j) * 1000)){
        s = i;
        t = j;
        u = n - i - j;
        goto loopend;
      }
    }
  }
  loopend:
  
  printf("%d %d %d\n", s, t, u);
  return 0;
}

Measured memory_bytes: 128
#TLE
N, M = map(int, input().split())
a_list = list(map(int, input().split()))

written_nums = []
for i in range(M):
    b, c = map(int, input().split())
    written_nums.append((c, b))

written_nums.sort(reverse = True)
append_list = []
for c, b in written_nums:
    append_list += [c for _ in range(b)]

    if len(append_list) >= N:
        break

a_list += append_list
a_list.sort(reverse = True)

print(sum(a_list[:N]))


Measured memory_bytes: 24908
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main(){
  int n;
  cin>>n;
  
  string s;
  cin>>s;
  if(n%2!=0){
    cout<<"No"<<endl;
  }
  else{
    int d=n/2;
    rep(i,d){
      if(s[i]!=s[i+d]){
        cout<<"No"<<endl;
        break;
      }
      if(i==d-1){
        cout<<"Yes"<<endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
using namespace std;
 
int main() {
    //input
    int n;cin >> n;
    vector<int> d(n + 1);for(int i = 1; i < n + 1;i++) cin >> d[i];
    int m;cin >> m;
    vector<int> t(m + 1);for(int i = 1; i < m + 1;i++) cin >> t[i];

    if(m > n){
        cout << "NO" << endl;
        return 0;
    }
 
    //compute
    multiset<int> st1,st2;
    for(int i = 1; i < n + 1;i++) st1.insert(d[i]);
    for(int i = 1; i < m + 1;i++) st2.insert(t[i]);

    //output
    if (includes(st1.begin(), st1.end(),st2.begin(), st2.end())){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 23540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	int[] openStoreBitArr;
	int[][] benefitArr;
	int n;
	
	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		n = fs.nextInt();
		openStoreBitArr = new int[n];
		
		for(int i = 0; i < n; i++){
			int storeIBit = 0;
			for(int j = 0; j < 10; j++){
				storeIBit = storeIBit << 1;
				if(fs.nextInt() == 1){
					storeIBit += 1;
				}
			}
			openStoreBitArr[i] = storeIBit;
		}
		
		benefitArr = new int[n][11];
		
		for(int i =0; i < n; i++){
			for(int j = 0; j < 11; j++){
				benefitArr[i][j] = fs.nextInt();
			}
		}
		
//		for(int i =0; i < n; i++){
//			System.out.println(Arrays.toString(benefitArr[i]));
//		}
		System.out.println(dfs(0, 0));
	}

	
	int numOfBit(int n){
		int retVal = 0;
		for(int i = 0; i < 10; i++){
			if(((n>>i) & 1) == 1){
				retVal++;
			}
		}
		return retVal;
	}
	
	int dfs(int bit, int depth){
		if(depth == 10){
			return calcBenefit(bit);
		}
		
		return Math.max(dfs(bit<<1, depth+1), dfs((bit<<1)+1, depth+1));
	}
	
	int calcBenefit(int bit){
		if(bit == 0){
			return -1000000001;
		}
		int benefit = 0;
		for(int i = 0; i < n; i++){
			benefit += benefitArr[i][numOfBit(bit & openStoreBitArr[i])];
		}
		return benefit;
	}
	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

struct Medicine {int a, b, c;};

const int INF = 1e9;

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<Medicine> M(N);
  for(auto& i: M) cin >> i.a >> i.b >> i.c;
  auto res = INF;
  vector<vector<int>> dp(401, vector<int>(401, INF));
  dp[0][0]=0;
  for(auto m: M) {
    auto dup = dp;
    for(auto a=m.a; a<=400; ++a) for(auto b=m.b; b<=400; ++b) {
      dp[a][b] = min(dp[a][b], dup[a-m.a][b-m.b]+m.c);
      if(a*B==b*A) res = min(res, dp[a][b]);
    }
  }
  if(res==INF) res = -1;
  cout << res << endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL

using namespace std;
using llong = long long;

int main()
{
	IOS; 
	
	string S, T;
	cin >> S >> T;
	int len = S.length();
	int i;
	int ans = 0;
	for (i = 0; i < len; i++)
	{
		if (S[i] != T[i]) ans++;
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 3768
import string
numbers = "0123456789"
alphabets = string.ascii_letters # a-z+A-Zをロード
characters = numbers + alphabets
 
def base_cvt(value, n=2):
    try:
        tmp = int(value)
    except:
        raise ValueError('Invalid value:', value)
 
    if n < 2 or n > len(characters):
        raise ValueError('Invalid n:', value)
 
    result = ''
    tmp = int(value)
    while tmp >= n:
        idx = tmp%n
        result = characters[idx] + result
        tmp = int(tmp / n)
    idx = tmp%n
    result = characters[idx] + result
    return result



N,K = map(int,input().split())

length = base_cvt(str(N), K)
length = len(length)
print(length)

Measured memory_bytes: 4020
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	p := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	ans := 0
	for i := 1; i < n-1; i++ {
		if p[i-1] > p[i] && p[i] > p[i+1] || p[i+1] > p[i] && p[i] > p[i-1] {
			ans++
		}
	}
	fmt.Println(ans)
}


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

int main(){
	int n;
	cin >> n;
	int v[n],c[n],i,ans=0;
	for(i=0;i<n;i++) cin >> v[i];
	for(i=0;i<n;i++) cin >> c[i];
	for(i=0;i<n;i++) if(v[i]-c[i]>0) ans += (v[i] - c[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n;
int a[N], c[N];
int mx[4], mxv[4];
void add(int x, int p) {
    ++c[x];
    if(c[x] > mx[p]) {
        mx[p] = c[x];
        mxv[p] = x;
    } else if(c[x] > mx[p + 1]) {
        mx[p + 1] = c[x];
        mxv[p + 1] = x;
    }
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i += 2) add(a[i], 0);
    for(int i = 1; i < N; i++) c[i] = 0;
    for(int i = 2; i <= n; i += 2) add(a[i], 2);
    int ans = n;
    if(mxv[0] == mxv[2]) {
        if(mx[1] > mx[3]) {
            ans -= mx[1] + mx[2];
        } else if(mx[1] < mx[3]){
            ans -= mx[0] + mx[3];
        } else if(mx[1] == mx[3] && !mx[1]) {
            ans -= n / 2;
        } else {
            ans -= mx[0] + mx[3];
        }
    } else {
        ans -= mx[0] + mx[2];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int K, A, B; cin >> K >> A >> B;
    int ans = 1;
    REP(i, K){
        if(ans < A) ans++;
        else if(i == K - 1) ans++;
        else{
            ans += B - A;
            i++;
        }
    }
    cout << max(ans, K + 1) << endl;
    
    return 0;
}

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

//20
typedef long long ll;
			
int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		sum += v[i];
	}
	//}
	//ll x = v[0];
	//for (int i = 1; i < n; ++i) {
		//x = (x * v[i])/__gcd(x,v[i]);
	//}
	cout << sum - n;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main(){
	int n,x;
	
	cin>>n>>x;
	for (int i=0;i<n;i++){
		cin>>a[i];
	}
	
	sort(a,a+n);
	int cnt=0;
	for (int i=0;i<n-1;i++){
		if (x>=a[i]){
			x-=a[i];
			cnt++;
		}
	}
	if (a[n-1]==x){
		cnt++;
	}
	cout<<cnt<<endl;
} 

Measured memory_bytes: 256
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, N = lr()

U = 20000 #max(H)+max(A)
# dp[i] はモンスターへi攻撃する時、使用する魔力の最小値
INF = 10 ** 10
dp = np.full(U, INF, np.int64)
dp[0] = 0

for _ in range(N):
    a, b = lr()
    n = (U + (-U)%a) // a
    dp = np.resize(dp, U + (-U)%a).reshape(-1, a)
    # 列のサイズはa
    dp -= (np.arange(n) * b)[:, None]
    dp = np.minimum.accumulate(dp, axis=0)
    # ここでdpを現時点の魔力の最小値に更新
    dp += (np.arange(n) * b)[:, None]
    dp = np.ravel(dp)[:U]

answer = min(dp[H:])
print(answer)


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,d[100010];

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    if( n&1 ){
        cout << 0;
        return 0;
    }
    for(ll i=0; i<n; i++) cin >> d[i];
    sort( d,d+n );

    cout << d[n/2]-d[-1+n/2];

    return 0;
}


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

int main()
{
    int n,k,ans;
    scanf("%d %d",&n,&k);
    int ar[n+1];
    for(int i=1;i<n+1;i++)
        scanf("%d",&ar[i]);
    int dp[n+1];
    for(int i=0;i<n+1;i++)
        dp[i]=1000000000;
    dp[1]=0;dp[2]=abs(ar[1]-ar[2]);
    for(int i=3;i<=n;i++){
        for(int j=i-1;j>=0 && j>=(i-k);j--){
            dp[i]=min(dp[i],dp[j]+abs(ar[i]-ar[j]));
        }
    }

    printf("%d\n",dp[n]);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
using namespace std;
using ll = long long;

int main(void) {
    string s;
    cin >> s;

    ll ans = 0;
    int cnta = 0, cntbc = 0;
    rep (i, s.size() - 1) {
        if (s[i] == 'A') {
            cnta ++;
        }   
        else if (s[i] == 'B' && s[i + 1] == 'C') {
            ans += cnta;
            i++;
        }
        else cnta = 0;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main () {
  int K;
  string S;
  cin >> K >> S;
  int N = S.size();
  if (K >= N) {
    cout << S << endl;
    return 0;
  }
  cout << S.substr(0, K) << "..." << endl;
}

Measured memory_bytes: 3628
// AtCoder Beginners Contest 175
// A - Rainy Season

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <random>
#include <vector>
#include <chrono>

using namespace std;
//using namespace std::chrono;

int main()
{
    //steady_clock::time_point start = steady_clock::now();
    string S;

    cin >> S;
	int cnt = 0;
	/*
	for (int i = 0; i < 3; i++) {
		if (S[i] =='R') {
			cnt++;
		} 
	}
	*/
	if (S == "SSS") cnt = 0;
	if (S == "SSR") cnt = 1;
	if (S == "SRS") cnt = 1;
	if (S == "SRR") cnt = 2;
	if (S == "RSS") cnt = 1;
	if (S == "RSR") cnt = 1;
	if (S == "RRS") cnt = 2;
	if (S == "RRR") cnt = 3;
	cout << cnt << endl;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define s 1000000007

long inverse(long n, long mod)
{
    long m = mod - 2;
    long ans = 1;
    long prod = n;
    while (m != 0)
    {
        if (m & 1)
        {
            ans *= prod;
            ans %= mod;
        }
        m >>= 1;
        prod *= prod;
        prod %= mod;
    }
    return ans;
}

long C(long n, long m)
{
    long N = 1;
    for (int i = n - m + 1; i <= n; i++)
    {
        N *= i;
        N %= s;
    }
    long M = 1;
    for (int i = 1; i <= m; i++)
    {
        M *= i;
        M %= s;
    }
    return (N * inverse(M, s)) % s;
}

int main()
{
    long K, N;
    cin >> N >> K;
    for (int i = 1; i <= K; i++)
    {
        if (N - K + 1 >= i)
            cout << (C(K - 1, i - 1) * C(N - K + 1, i)) % s << endl;
        else
            cout << 0 << endl;
    }
}

Measured memory_bytes: 256
/*
 * DATE : 2017-07-01
 * Algo :
*/
#include<bits/stdc++.h>
using namespace std;
/*------- Constants---- */

#define Long                    long long
#define Ulong                   unsigned long long
#define FOR(I,A,B)              for(long long i=0; i < n ; i++ )
#define REP(i,n)                for(long long i=0; i < n ; i++ )
#define mp                      make_pair
#define pb                      push_back
#define all(x)                  (x).begin(),(x).end()
#define PI                      acos(-1.0)
#define EPS                     1e-9
#define F                       first
#define S                       second
#define di(x)                   int x; input(x)
#define in(x)                   input(x)
#define in2(x,y)                in(x),in(y)
#define in3(x,y,z)              in(x),in2(y,z)
#define lc                      ((n)<<1)
#define rc                      ((n)<<1|1)
#define db(x)                   cout << #x << " -> " << x << endl;
#define ms(ara_name,value)      memset(ara_name,value,sizeof(ara_name))
#define IO                      ios_base::sync_with_stdio(0);cin.tie(0)
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
template<class T> inline void input(T &x) {
    register char c = getchar();x = 0;
    int neg = 0;
    for(; ((c<48 || c>57) && c != '-'); c = getchar());
    if(c=='-'){neg = 1;c = getchar();}
    for(; c>47 && c<58 ; c = getchar()){x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x = -x;
}
inline long long bigmod(long long p,long long e,long long M){
    long long ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

/***************************** END OF TEMPLATE *******************************/
const int N = 2e5+5;
long long f[N];
long long cnt[N], a[N];
const long long MOD = 1e9+7;
int n,pivot;
long long nCr(long long n,long long r)
{
    if(r>n || r < 0)return 0;
    long long c = (f[r] * f[n-r]) % MOD;
    return (f[n] * modinverse(c,MOD))%MOD;
}
int main()
{
    f[0] = 1;
    for(int i= 1;i < N;i ++ ) f[i] = (f[i-1] * i ) % MOD;
    in(n);
    for(int i=0;i<=n;i++) in(a[i]), cnt[a[i]] ++;
    for(int i=1;i<=n;i++) {
        if(cnt[i] == 2) {
            pivot = i;
        }
    }
    int x = -1, y = -1;
    for(int i = 0; i<= n;i ++ ) {
        if(a[i] == pivot ){
            if(x == -1) x = i;
            else y = i;
        }
    }

    for(int len= 1; len <= n + 1; len ++ ) {
        long long ans =  nCr(n-1,len);

        ans += nCr(n , len - 1 ) + nCr(n - 1, len - 1);
        ans %= MOD;
        int left = x, righ = n - y;
//        for(int i = 0; i <= len; i ++ ) {
//            ans -= nCr(left, i) * nCr(righ , len-1-i);
//
//        }
        ans -= nCr(left + righ , len - 1);
        ans = (ans % MOD + MOD) % MOD;
        printf("%lld\n",ans);
    }

    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

void solve(std::string S)
{
  YesNo(S[2] == S[3] && S[4] == S[5]);
}

signed main()
{
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cstdlib>
#include <cstring>

bool matches_condition(int value)
{
  if(value % 5 != 1) {
    return false;
  }
  for(int i = 2; i * i <= value; i++) {
    if(value % i == 0) {
      return false;
    }
  }
  return true;
}

int generate_matched_value(int begin, int end)
{
  for(int i = begin; i < end; i++) {
    if(matches_condition(i)) {
      return i;
    }
  }
  fputs("Nothing found...\n", stderr);
  exit(1);
}

int main()
{
  int n;
  int result[100];

  scanf("%d", &n);

  result[0] = 11;
  for(int i = 1; i < n; i++) {
    result[i] = generate_matched_value(result[i-1]+1, 55555);
  }
  for(int i = 0; i < n; i++) {
    printf("%d", result[i]);
    if(i == n - 1) {
      putchar('\n');
    } else {
      putchar(' ');
    }
  }
  return 0;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter
import numpy as np
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    N = readint()
    ab = sorted([list(readnums()) for _ in range(N)], key=itemgetter(1))
    a = np.cumsum(np.array(list(map(lambda x: x[0], ab))))
    b = list(map(lambda x: x[1], ab))
    for A, B in zip(a, b):
        if A > B:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 64240