akhauriyash/Code-Regression huggingface dataset:
# E - Crested Ibis vs Monster
from collections import defaultdict


def main():
    H, N, *AB = map(int, open(0).read().split())
    dp = defaultdict(lambda: 1 << 30)  # dp[i] := min magic points to decrease monster's health by i
    dp[0] = 0
    for i in range(H):
        if i not in dp:
            continue
        for a, b in zip(*[iter(AB)] * 2):
            if i + a < H:
                dp[i + a] = min(dp[i + a], dp[i] + b)
            else:
                dp[H] = min(dp[H], dp[i] + b)
    print(dp[H])


if __name__ == "__main__":
    main()


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n; cin >> n;
  vector<ll> v(n); cin >> v;
  ll sum = 0;
  for(ll e:v)sum += e;
  ll ans = 1000000000000000;
  ll sum2 = 0;
  for(ll e:v){
    sum2 += e;
    ChangeMin(ans, abs(sum2 - abs(sum-sum2)));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
def main():
    n = int(input())
    H = list(map(int, input().split()))
    A = list(map(int, input().split()))

    def segfunc(x, y):
        if x >= y:
            return x
        else:
            return y

    def init(init_val):
        # set_val
        for i in range(n+1):
            seg[i+num-1] = init_val[i]
        # built
        for i in range(num-2, -1, -1):
            seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

    def update(k, x):
        k += num - 1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

    def query(p, q):
        if q <= p:
            return ide_ele
        p += num - 1
        q += num - 2
        res = ide_ele
        while p < q:
            if p&1 == 0: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[p])
            if q&1 == 1: #左のnode: == 1, 右のnode: == 0
                res = segfunc(res, seg[q])
                q -= 1 # 隣に移動
            p = p//2 # 隣のnodeの親にアクセス
            q = (q-1)//2 #親のnodeにアクセス
        if p == q:
            res = segfunc(res, seg[p])
        else:
            res = segfunc(segfunc(res, seg[p]), seg[q])
        return res

    # identity element
    ide_ele = 0

    # num: n以上の最小の2のべき乗
    num = 2**n.bit_length()
    seg = [ide_ele]*2*num

    X = [0]*(n+1)
    for i in range(n):
        update(H[i], query(0, H[i]+1)+A[i])
    print(query(0, n+2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 123644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,T;
  cin >> N >>T;
  vector<pair<int,int>> p(N);
  for(int i = 0; i < N; i++){
    int c,t;
    cin >> c >> t;
    p.at(i) = make_pair(c,t);
  }
  int cost = 1001;
  int ans = -1;
  for(int i = 0; i < N; i++){
    if (p.at(i).second <= T){
      if(p.at(i).first < cost){
        cost = p.at(i).first;
        ans = i;
      }
    }
  }
  if(ans == -1)cout << "TLE"<<endl;
  else cout << cost << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i, j, k, n, m;
    int a[4][13];
    char x;
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            a[i][j] = 0;
        }
    }
    scanf("%d", &k);
    for (n = 0; n < k; n++)
    {
        scanf("%c", &x);        /* 前の行の改行を１つ読み込む*/
        scanf("%c %d", &x, &m); /* i行目の、文字と整数の組を読み込む*/
          if (x == 'S')
        {
            a[0][m - 1] = 1;
        }
        else if (x == 'H')
        {
            a[1][m - 1] = 1;
        }
        else if (x == 'C')
        {
            a[2][m - 1] = 1;
        }
        else if (x == 'D')
        {
            a[3][m - 1] = 1;
        }
    }
    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 13; j++)
        {
            if (a[i][j] == 0)
            {
                if (i == 0)
                {
                    printf("S %d", j + 1);
                }
                else if (i == 1)
                {
                    printf("H %d", j + 1);
                }
                else if (i == 2)
                {
                    printf("C %d", j + 1);
                }
                else if (i == 3)
                {
                    printf("D %d", j + 1);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2032
N, M = [int(n) for n in input().split()]
Hs = [int(n) for n in input().split()]
# len(Hs) = N = 展望台の数
# M = 展望台同士を結ぶ道の数
not_good = set()
for i in range(0, M):
    A, B = [int(n) for n in input().split()]
    diff = Hs[A-1] - Hs[B-1]
    if diff > 0:
        not_good.add(B)
    elif diff < 0:
        not_good.add(A)
    else:
        not_good.add(A)
        not_good.add(B)
ans = N-len(not_good)
print(ans)

Measured memory_bytes: 20128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N;
	int a[11234];
	cin >> N;
	REP(i, N) scanf("%d", a + i);
	
	int ans = 0;
	REP(i, N) {
		while (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        char c;
        cin >> c;
        A[i] = c - '0';
    }
    set<int>se1;
    set<pair<int, int>>se2;
    set<tuple<int, int, int>>se3;
    for (int i = 0; i < N; ++i) {
        for (auto x: se2) {
            se3.insert(make_tuple(x.first, x.second, A[i]));
        }
        for (auto x: se1) {
            se2.insert({x, A[i]});
        }
        se1.insert(A[i]);
    }
    cout << se3.size() << "\n";
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define MAX 100

int main(){
  int n,i,j,v,u,k;
  int Adj[MAX][MAX];

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0;j<n;j++)
      Adj[i][j]=0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d", &u);
    scanf("%d", &k);
    u--;
  for(j=0;j<k;j++){
      scanf("%d", &v);
      v--;
      Adj[u][v]=1;
  }

  }


  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j==n-1)printf("%d", Adj[i][j]);
      else printf("%d ", Adj[i][j]);
    }printf("\n");}
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

//int par[100], l[100], r[100]; //lは左の子、rは右の子
struct node {
    int p, l, r; /* data */
};

node t[100];
void pre (int u) {
    if (u == -1) return;
    printf (" %d", u);
    pre (t[u].l);
    pre (t[u].r);
}
void in (int u) {
    if (u == -1) return;
    in (t[u].l);
    printf (" %d", u);
    in (t[u].r);
}
void post (int u) {
    if (u == -1) return;
    post (t[u].l);
    post (t[u].r);
    printf (" %d", u);
}
int main() {
    int n;
    cin >> n;
    rep (i, n + 1) t[i].p = -1;
    rep (i, n) {
        int now, left, right;
        cin >> now >> left >> right;
        t[now].l = left;
        t[now].r = right;
        if (left != -1) t[left].p = now;
        if (right != -1) t[right].p = now;
    }
    int root;
    rep (i, n) if (t[i].p == -1) root = i;
    cout << "Preorder\n";
    pre (root);
    cout << "\nInorder\n";
    in (root);
    cout << "\nPostorder\n";
    post (root);
    cout << "\n";
}


Measured memory_bytes: 3152
N, A, B = map(int, input().split())
S = input()

foreign = 1
now = 0
for i in range(N):
    s = S[i]
    if s == 'a':
        if now < A + B:
            flg = True
        else:
            flg = False
    elif s == 'b':
        if now < A + B and foreign <= B:
            flg = True
        else:
            flg = False
        foreign += 1
    else:
        flg = False
    if flg:
        print("Yes")
        now += 1
    else:
        print("No")


Measured memory_bytes: 4040
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    print(max(a)-min(a))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3316
n, d = map(int, input().split())
points = [[]] * n
for i in range(n):
  points[i] = list(map(int, input().split()))
 
def helper(a, b):
  s = 0
  for i in range(d):
    s += (a[i] - b[i]) ** 2
  a = int(0.5 + (s ** 0.5))
  if a * a == s:
    return 1
  return 0
 
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        ans += helper(points[i], points[j])
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;



int main()
{
	ll l, r;
	cin >> l >> r;
	ll d = r - l; //2018
	if (r - l >= 2018) {
		cout << 0;
		return 0;
	}
	ll ans = 10001000;
	for (ll i = l;i <= r;i++) {
		for (ll j = l;j <= r;j++) {
			if (i == j) continue;
			ans = min(ans, j * i % 2019);
			
		}
	}cout << ans;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAX=5005,mod=1e9+7,inf=0x3f3f3f3f;

typedef pair < ll, ll > ii;
int f[MAX][MAX][2],F[MAX][MAX][2],cnt[MAX];
#define X first
#define Y second
#define pb push_back
//vector < int > pr[MAX];
int n,m;
//ll a[MAX];
int A,B;
int get(int a,int b){
    a+=b;if(a>=mod) a-=mod;return a;
}
int main()
{
    //memset(ST,0,sizeof ST);
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("45C.inp","r",stdin);freopen("45C.out","w",stdout);
    cin>>n;
    cin>>A>>B;
    //cout<<mod*2;
    if(A>B) swap(A,B);
    ll ans=1;
    f[0][0][1]=1;
    f[0][0][0]=1;
    cnt[0]=1;
    F[0][0][0]=1;
    F[0][0][1]=1;
    for(int i=1;i<=n;i++){ans=ans<<1;if(ans>=mod) ans-=mod;}
    for(int i=1;i<=n;i++){
        if(i>=A) f[i][0][0]=(cnt[i-1]-cnt[i-A]+mod)%mod;
        else f[i][0][0]=cnt[i-1];
        F[i][i][0]=get( F[i-1][i][0],f[i][0][0] );
        for(int j=1,ma=min(B-1,i);j<=ma;j++){
            //for(int u=A;u<j;u++) f[i][j][0]+=f[i-u][j-u][1];
            if(i>=A) f[i][j][0]=F[i-A][i-j][1];

            F[i][i-j][0]=get( F[i-1][i-j][0],f[i][j][0] );
        }
        for(int j=1,ma=min(B-1,i);j<=ma;j++){
            //for(int u=1;u<=j;u++) f[i][j][1]+=f[i-u][j-u][0];

            f[i][j][1]=F[i-1][i-j][0];

            F[i][i-j][1]=get(F[i-1][i-j][1],f[i][j][1]);
            cnt[i]=get(f[i][j][1],cnt[i]);
        }
        cnt[i]=get(cnt[i-1],cnt[i]);
    }
    ll temp=0;
    for(int j=0;j<B;j++){
        temp=(temp+f[n][j][1]+f[n][j][0])%mod;
        //cout<<j<<' '<<f[n][j][1]<<' '<<f[n][j][0]<<'\n';
    }
    cout<<(ans-temp+mod)%mod;
}


Measured memory_bytes: 236992
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
    if(M<N) cout<<NO<<endl;
    else cout<<YES<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

using namespace std;

int main()
{
    cout << fixed << setprecision(20);

    long double a, b, h, m;

    cin >> a >> b >> h >> m;
    
    // 各針の角度
    long double h_ang = 2*M_PI * (h*60+m)/720;
    long double m_ang = 2*M_PI * m / 60;

    // 余弦定理
    long double ans = a*a + b*b - 2*a*b*cos(h_ang-m_ang);
    ans = sqrt(ans);

    cout << ans << endl;
}

Measured memory_bytes: 4176
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");

	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
	
	for(i=9;i>0;i--){
	  if (n%i==0){if(n/i<10){console.log('Yes');
                            break;}
	                 else{console.log('No');
                         break;}
	             }
	         }
	                 
   // console.log('No');
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9420
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

#define rep(i,s,n) for(ll (i)=(s);(i)<(n);(i)++)
#define repd(i,n,s) for(ll (i)=(n-1);(i)>=(s);(i)--)
#define all(x) x.begin(),x.end()
#define size(x) ((ll)(x).size()
#define PB push_back

int main(){
  int n;
  cin >> n;
  if(n%2==0){
      cout << n/2 << endl;
  }else{
      cout << (n/2)+1 << endl;
  }
}


Measured memory_bytes: 256
N = int(input())

if N % 2 == 0:
  print(N//2,N,N)
else:
  for h in range(2,3501,2):
    for n in range(2,3501,2):
      if 4*h*n-n*N-h*N != 0:
        w = h*n*N/(4*h*n-n*N-h*N)
        if w > 0 and w.is_integer():
          print(h,n,int(w))
          exit()


Measured memory_bytes: 40812
package main

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

func main() {
	var s []byte
	fmt.Scan(&s)
	var q int
	fmt.Scan(&q)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var mode int
	var hs, ts []byte

	for i := 0; i < q; i++ {
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		if t == 1 {
			mode = 1 - mode
		} else {
			sc.Scan()
			f, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c := []byte(sc.Text())[0]
			if mode == 0 {
				if f == 1 {
					hs = append(hs, c)
				} else {
					ts = append(ts, c)
				}
			} else {
				if f == 1 {
					ts = append(ts, c)
				} else {
					hs = append(hs, c)
				}
			}
		}
	}

	if mode == 0 {
		fmt.Printf("%s%s%s\n", string(reverse(hs)), string(s), string(ts))
	} else {

		fmt.Printf("%s%s%s\n", string(reverse(ts)), string(reverse(s)), string(hs))
	}
}

func reverse(bs []byte) []byte {
	nbs := make([]byte, len(bs))
	for i := range bs {
		nbs[i] = bs[len(bs)-i-1]
	}
	return nbs
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    while(true){
        int d, e;
        cin >> d >> e;
        if(d == 0) break;
        double ans = 1e8;
        for(int x = 0; x <= d; x++){
            int y = d - x;
            double l = sqrt((x * x + y * y) * 1.0);
            ans = min(ans, abs(l - e));
        }
        cout << fixed << setprecision(15) << ans << endl;
    }
}



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

int main(){
  char X,Y;
  cin >> X >> Y;
  if(X<Y){
    cout << "<" << endl;
  }
  else if(X==Y){
    cout << "=" << endl;
  }
  else{
    cout << ">" << endl;
  }
}

Measured memory_bytes: 256
n=int(input())

a= list(map(int,input().split()))

a.sort()

plus_sum = a.pop(-1)
plus_memo = plus_sum
minas_sum = a.pop(0)
minas_memo = minas_sum

for aa in a:
    if 0 < aa:
        minas_sum -= aa
    else:
        plus_sum -= aa

print(plus_sum-minas_sum)

for aa in a:
    if 0 < aa:
        print(minas_memo, aa)
        minas_memo -= aa
    else:
        print(plus_memo, aa)
        plus_memo -= aa
print(plus_memo, minas_memo)

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

int main() {
	// your code goes here
	long long Q,H,S,D,N = 0;
	cin>>Q;
	cin>>H,
	cin>>S;
	cin>>D;
	cin>>N;
	Q = Q *2;
	if(Q<H)
	{
	    H = Q;
	}
	H = H*2;
	if(H<S)
    {
        S = H;
    }
    long long res= 0;
    if(2*S <= D)
    {
        res = N*S;
    }
    else
    {
        res = (N/2)*D + (N%2)*S;
    }
    cout << res;
	return 0;
}


Measured memory_bytes: 256
#almost everywhere zero

n=input()
k=int(input())
dp_small=[[0 for i in range(4)] for j in range(101)]
dp_same=[[0 for i in range(4)] for j in range(101)]

#dp/smallすでに小さい
#dp_largeまだ小さいかどうかわからない
for i in range(101):
    dp_small[i][0]=1
dp_small[0][0]=0
dp_same[0][0]=1
for i in range(len(n)):
    a=int(n[i])
    #左からi+1番目の桁について考える
    if a!=0:
        dp_small[i+1][1]=dp_small[i][1]+9*dp_small[i][0]+(a-1)*dp_same[i][0]+dp_same[i][1]
        dp_small[i+1][2]=dp_small[i][2]+9*dp_small[i][1]+(a-1)*dp_same[i][1]+dp_same[i][2]
        dp_small[i+1][3]=dp_small[i][3]+9*dp_small[i][2]+(a-1)*dp_same[i][2]+dp_same[i][3]

        dp_same[i+1][1]=dp_same[i][0]
        dp_same[i+1][2]=dp_same[i][1]
        dp_same[i+1][3]=dp_same[i][2]       
        
        
        
        
    elif a==0:
        dp_small[i+1][1]=dp_small[i][1]+9*dp_small[i][0]
        dp_small[i+1][2]=dp_small[i][2]+9*dp_small[i][1]
        dp_small[i+1][3]=dp_small[i][3]+9*dp_small[i][2]

        dp_same[i+1][1]=dp_same[i][1]
        dp_same[i+1][2]=dp_same[i][2]
        dp_same[i+1][3]=dp_same[i][3]
        
L=len(n)
sums= dp_small[L][k]+dp_same[L][k]

print(sums)


Measured memory_bytes: 3188
from collections import Counter
def main():
    N, P = map( int, input().split())
    A = Counter(list( map( lambda x: int(x)%2, input().split())))
    zero = A[0]
    one = A[1]
    ans = 1
    now = 1
    for i in range(1,one+1):
        now *= (one-i+1)
        now //= i
        if i%2 == 0:
            ans += now
    if P == 0:
        print( ans*pow(2,zero))
    else:
        print(pow(2,N) - ans*pow(2,zero))
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const int maxn = 2e5+7;
const ll MOD = 1e9+7;
int n,x,y;
vi ans(maxn,0);
int dist(int i, int j){
	return min(abs(j-i), 1+abs(x-i)+abs(y-j));
	// return min(abs(j-i), min(1+abs(x-i)+abs(y-j), 1+abs(y-i)+abs(x-j)));
}
int main(){
	fast_io;
	cin>>n>>x>>y;
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			int d = dist(i,j);
			ans[d]++;
		}
	}
	for(int i=1;i<n;i++)cout<<ans[i]<<"\n";
	// trace(cnt)
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 1024
#coding:utf-8

import itertools
n = int(input())
a = ''.join(input().split(' '))
b = ''.join(input().split(' '))

p = 0
q = 0
i = 0
for it in itertools.permutations(range(1, n + 1)):
    it = list(it)
    it = ''.join([str(num) for num in it])
    if it == a:
        p = i
    if it == b:
        q = i
    
    i += 1
print(abs(p-q))

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


int main()
{
  int k;
  string s;
  cin >> k >> s;
  if((int)s.size() <= k)
  {
    cout << s << endl;
  }
  else
  {
    s = s.substr(0, k);
    s += "...";
    cout << s << endl;
  }
  
  
  
  return 0;
}

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int N,T;
	std::cin >> N >> T;
	int now,pre,point;
	point = pre = 0;
	ull ans = 0;
	for (size_t i = 0; i < N; i++) {
		std::cin >> now;
		if (now - pre > T) {
			ans = ans + (pre + T - point);
			point = now;
			pre = now;
			if (i == N-1) {
				ans = ans + T;
			}
		}
		else {
			pre = now;
			if (i == N-1) {
				ans = ans + (now + T - point);
			}
		}
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    cout << 180*(n-2) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  auto f=[](string str){return str==string(str.rbegin(),str.rend());};
  cout<<(f(s)&&f(string(s.begin(),s.begin()+(n-1)/2))&&f(string(s.begin()+(n+3)/2-1,s.end()))?"Yes":"No");
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using vc=vector<char>;
using vi=vector<int>;
using ll=long long;
using vll=vector<ll>;


ll calc(int n, vc&s, int k)
{
	ll ans=0LL;
	ll nd=0, nm=0, ndm=0;

	for(int i=0;i<n;i++)
	{
		if(i-k>=0)
		{
			if(s[i-k]=='D') nd--, ndm-=nm;
			if(s[i-k]=='M') nm--;
		}
		if(s[i]=='D') nd++;
		if(s[i]=='M') nm++, ndm+=nd;
		if(s[i]=='C') ans+=ndm;
	}
	return ans;
}


int main(void)
{
	int n, q;
	vc s(1000000+2);

	while(scanf("%d%1000000s%d", &n, &s[0], &q)==3)
	{
		vi k(q);
		vll nd(n), ndm(n);

		for(int i=0;i<q;i++)
		{
			scanf("%d", &k[i]);
		}

		for(int i=0;i<q;i++)
		{
			printf("%lld\n", calc(n, s, k[i]));
		}
	}

	return 0;
}


Measured memory_bytes: 16896
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * AtCoder Beginner Contest 1xx
 * <p>
 * https://atcoder.jp/contests/abc1xx/tasks/abc1xx_c
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        System.out.println(
                IntStream.range(0, n)
                        .mapToObj(m -> sc.nextLine().chars().sorted()
                                .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
                                .toString()
                        )
                        .collect(Collectors.groupingBy(v -> v, Collectors.counting()))
                        .values()
                        .stream()
                        .filter(count -> count > 1)
                        .mapToLong(count -> (count * (count - 1)) / 2)
                        .sum()
        );
    }
}


Measured memory_bytes: 72172
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { {0,0,-1,1},{-1,1,0,0} };
struct P {
ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
ll to, cost;
};
struct S {//辺の情報を入れる変数
int from, to, cost;
};
struct H {
int x, y;
};
bool operator<(H a, H b) {
if (a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
ll gcm(ll i, ll j) {//最大公約数
if (i > j) swap(i, j);
if (i == 0) return j;
return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
if (b <= c || d <= a) return 0;
return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin>>s;
	s[3]='8';
	cout<<s<<endl;
	getchar(); getchar();
}


Measured memory_bytes: 256
N = int(input())
S = []
A, B, AB, BA = 0, 0, 0, 0
for i in range(N):
    a = input()
    S.append(a)
    if a[0] == 'B' and a[-1] == 'A':
        BA += 1
    elif a[0] == 'B':
        B += 1
    elif a[-1] == 'A':
        A += 1
    AB += a.count('AB')
ans = 0

ans += AB + min(A, B)
ans += BA
if A == 0 and B == 0 and BA > 0:
    ans -= 1
print(ans)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();

int32_t main(){

    vector<int> v(5);
    for(auto &i : v) cin>>i;
    for(int i=0;i<5;i++){
        if(v[i]==0){
            cout<<i+1<<"\n";
            exit(0);
        }
    }

    
    return 0;
}

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

int a, b, c, d, e, f;

typedef pair< int, int > iP;

double density(iP st){
    if(st.second == 0) return 0;
    return (double)100 * st.second / (st.first + st.second);
}

int main(){
    cin >> a >> b >> c >> d >> e >> f;
    bool dp1[3001] = {false}, dp2[3001] = {false};
    dp1[100 * a] = dp1[100 * b] = true;
    dp2[0] = dp2[c] = dp2[d] = true;
    for(int i = 1; i * 100 <= f; i++){
        if(dp1[i * 100]){
            dp1[(i + a) * 100] = dp1[(i + b) * 100] = true;
        }
    }
    for(int i = 1; i <= f; i++){
        if(dp2[i]){
            dp2[i + c] = dp2[i + d] = true;
        }
    }

    iP ans = iP(0, 0);
    for(int i = 100; i <= f; i += 100){
        for(int j = 0; i + j <= f; j++){
            if(dp1[i] && dp2[j] && j <= e * (double)(i / 100)){
                if(density(ans) <= density(iP(i, j))){
                    ans = iP(i, j);
                }
            }
        }
    }

    cout << ans.first + ans.second << " " << ans.second << endl;
}

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

#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
#define N	    1000001
ll A[N], dp[N];
void solve(){	
	ll n;
	cin >> n;
	ll A[n+1];
	rep(i, 1, n+1)
		cin >> A[i];
	dp[1] = 0;
	dp[2] = abs(A[2] - A[1]);
	rep(i, 3, n+1)
		dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]), dp[i-2] + abs(A[i] - A[i-2]));
	cout << dp[n] << endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
   //  cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String w = sc.next();
    int[] kai = new int[26];
    for(int i = 0; i < w.length(); i++) {
      int d = w.charAt(i) - 'a';
      kai[d]++;
    } 
    String ans = "Yes";
    for(int i = 0; i < 26; i++) {
      if((kai[i] % 2) == 1) ans = "No";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
//typedef long long ll;
//typedef long double ld;
//typedef unsigned long long ull;
//typedef unsigned long double uld;
typedef pair<int,int> P;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
//struct area

//function area

//main area
int main(){
    string s;
    cin >> s;
    int first, last;
    rep(i,s.size()){
        if(s[i] == 'A'){
            first = i;
            break;
        }
    }
    for(int i = s.size()-1; 0<=i; i--){
        if(s[i] == 'Z'){
            last = i;
            break;
        }
    }
    cout << last - first + 1 << endl;
}
/*



*/

Measured memory_bytes: 3760
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


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


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


def main():
    n, k = MI()
    p = LI()
    max_seq = sum(p[:k])

    current = sum(p[:k])

    for i in range(k, n):
        current = current - p[i - k] + p[i]
        max_seq = max(max_seq, current)

    print((max_seq + k) / 2)


main()


Measured memory_bytes: 101992
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, M, a[60], b[60], c[60], d[60];
  cin >> N >> M;

  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < M; i++) cin >> c[i] >> d[i];


  for (int i = 0; i < N; i++) {
    long long v = 1e18;
    int ans = 0;
    for (int j = 0; j < M; j++) {
      long long tmp = abs(a[i]-c[j]) + abs(b[i] - d[j]);
      if (v > tmp) {
        ans = j + 1;
        v = tmp;
      }
    }
    printf("%d\n", ans);
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

string s;
int rec(int pos, int sml){
	if(pos == s.size()) return 0;
	int d = s[pos] - '0';
	int res = (sml ? 9 : d) + rec(pos + 1, sml);
	if(!sml && d > 0) res = max(res, d - 1 + rec(pos + 1, 1));
	
	return res;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> s;
	cout << rec(0, 0) << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef vector<P> vp;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}
bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
    
int main(){
    ll N; cin >> N;
    vl cs(N + 1, 0), ss(N + 1, 0), fs(N + 1, 0);
    for (int i = 1; i <= N - 1; i++) {
        cin >> cs[i]; cin >> ss[i]; cin >> fs[i];
    }
    
    for(int i = 1; i <= N; i++){
        ll ret = ss[i] + cs[i];
        for (int j = i + 1; j < N; j++) {
            ret = ((ret + (fs[j] - 1)) / fs[j]) * fs[j];
            ret = max(ret, ss[j]);
            ret += cs[j];
        }
        cout << ret << endstr;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

class UnionFind {
public:
	UnionFind(int sz) :
		parent(sz, -1) {}

	int root(int id) {
		if (parent[id] < 0)
			return id;

		return parent[id] = root(parent[id]);
	}

	int size(int id) {
		return -parent[root(id)];
	}

	bool unite(int id1, int id2) {
		id1 = root(id1);
		id2 = root(id2);

		if (id1 == id2)
			return false;

		if (parent[id2] < parent[id1])
			swap(id1, id2);

		parent[id1] += parent[id2];
		parent[id2] = id1;
		return true;
	}

private:
	vector<int> parent;
};

int main(void)
{
	int N, M;
	cin >> N >> M;

	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];

		A[i]--;
		B[i]--;
	}
		

	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());

	UnionFind un(N);
	vector<long long> ans(M, 0);
	ans[0] = (long long)N * (N - 1) / 2;
	for (int i = 0; i < M - 1; i++) {
		ans[i + 1] = ans[i];

		if (un.root(A[i]) != un.root(B[i])) {
			ans[i+1] -= (long long)un.size(A[i]) * un.size(B[i]);
			un.unite(A[i], B[i]);
		}
	}

	reverse(ans.begin(), ans.end());

	for (int i = 0; i < M; i++)
		cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N); 
    REP(i,N) cin>>a[i];

    sort(ALL(a),greater<int>());
    int scoreA=0,scoreB=0;
    REP(i,N){
        if(i%2==0)
            scoreA+=a[i];
        else
            scoreB+=a[i];
    }
    cout<<scoreA-scoreB<<endl;

}


Measured memory_bytes: 256
# inputの割り当て
A = int(input()) #５００円の枚数
B = int(input()) #1００円の枚数
C = int(input()) #5０円の枚数
X = int(input()) #合計金額

# 変数準備
i = 0
ans = 0

# for文
for i in range(A+1):
	j = 0
	for j in range(B+1):
		k = 0
		for k in range(C+1):
			sum = 500*i + 100*j + 50*k
			if sum - X == 0:
				ans += 1
		k += 1
	j += 1
i += 1

# 結果の表示
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 59);
constexpr ll MOD = 1000000007ll;

// structure ------------------------------------------

using graph = vector<vector<ll>>;

// function -------------------------------------------
ll f(ll a, ll b){
    return a / b;
}

// 最大公約数を計算 GCD
// 最小公倍数を計算 LCM
ll llgcd(ll a, ll b){
    if(b == 0){
        return a;
    }
    return llgcd(b, a % b);
}
ll lllcm(ll a, ll b){
    if(a == 0 || b == 0){
        return 1;
    }
    return a / llgcd(a, b) * b;
}


// Unionfind 素集合データ構造
struct Unionfind {
    vector<ll> par;
    vector<ll> rank;

    Unionfind(ll n) : par(n), rank(n) {
        REP(i, n) { par[i] = i; }
    }

    ll root(ll v) {
        if(par[v] == v) return v;
        return par[v] = root(par[v]);
    }

    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) return;

        if(rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if(rank[x] == rank[y]) { rank[x]++; }
        }
    }

    bool is_same(ll x, ll y) { return root(x) == root(y); }
};

// main -----------------------------------------------

int main() {
    ll n;
    cin >> n;
    vector<P> xy(n);
    REP(i, n){
        cin >> xy[i].first >> xy[i].second;
        xy[i].first --;
        xy[i].second --;
    }

    sort(xy.begin(), xy.end());

    vector<bool> is_seen(100000);
    vector<vector<ll>> x_kara_y(100000);
    REP(i, n){
        x_kara_y[xy[i].first].push_back(xy[i].second);
    }

    Unionfind uf(100000);

    REP(x, 100000){
        
        if(x_kara_y[x].size() <= 1){
            continue;
        }
        ll moto = x_kara_y[x][0];
        for(ll v : x_kara_y[x]){
            uf.unite(moto, v);
        }

    }

    vector<vector<ll>> kosuu(100000);
    REP(i, n){
        ll x = xy[i].first, y = xy[i].second;
        kosuu[uf.root(y)].push_back(x);
    }
    // cout << "iizo" << endl;

    REP(y, 100000){
        sort(kosuu[y].begin(), kosuu[y].end());
        kosuu[y].erase(unique(kosuu[y].begin(), kosuu[y].end()), kosuu[y].end());
    }


    vector<ll> root_tonaru_y(100000, 0);
    REP(y, 100000){
        root_tonaru_y[uf.root(y)] ++;
        // cout << uf.root(y) << " ";
    }

    ll ans = 0;
    REP(y, 100000){
        ans += root_tonaru_y[y] * ll(kosuu[y].size());
    }

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

Measured memory_bytes: 14820
#include<stdio.h>
int main(void){
  int i,c,d;
  double a,b,e,f;
  scanf("%lf%lf",&a,&b);
  for(i=1;i<10000;i++){
    e=i*0.08;
    f=i*0.1;
    c=(int)e;
    d=(int)f;
    if(c==a&&d==b){
          printf("%d",i);
      return 0;
    }}
    printf("-1");
    return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include<vector>
#define inf 1e9
using namespace std;
struct activity
{
    int A,B,C;
    
};
int solve(vector<activity> ar,int n)
{
   int dp[n+1][3];
   dp[1][0]=ar[1].A;
   dp[1][1]=ar[1].B;
   dp[1][2]=ar[1].C;
   for(int i=2;i<=n;i++)
   {
       dp[i][0]=ar[i].A + max(dp[i-1][1],dp[i-1][2]);
       dp[i][1]=ar[i].B + max(dp[i-1][0],dp[i-1][2]);
       dp[i][2]=ar[i].C + max(dp[i-1][0],dp[i-1][1]);
   }
   return max(dp[n][0],max(dp[n][1],dp[n][2]));
}

int main()
{
   int n;
   cin>>n;
   vector<activity> ar(n+1);
   for(int i=1;i<=n;i++)
   {
       cin>> ar[i].A;
       cin>> ar[i].B;
       cin>> ar[i].C;
       
   }
   cout<<solve(ar,n);
   
   return 0;
}

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

template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;
long long h[110000];
long long dp[110000];

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

		for (int i=0; i<N; ++i) cin >> h[i];

		for (int i=0; i<110000; ++i) dp[i] = INF;

		dp[0] = 0;

		for (int i=0; i<N; ++i) {
				for (int j=1; j<=K; ++j) {
						chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
				}
		}

		cout << dp[N-1] << endl;
		return 0;
}


Measured memory_bytes: 1920
N,M=map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]
import copy
import heapq
ans=0

for i in range(8):
    li=[]
    heapq.heapify(li)
    hoge=[1,1,1]

    for j in range(3):
        if ((i >> j) & 1):
            hoge[j]=-1
    for k in range(N):
        tmp=0
        for r in range(3):
            tmp += S[k][r] * hoge[r]
        heapq.heappush(li, tmp)
    re=0
    for t in range(M):
        re += heapq.heappop(li)

    re = abs(re)
    if re > ans :
        ans=re

print(ans)

Measured memory_bytes: 3828
/* h-ex5_4
   Ohshima */

#include <stdio.h>

int main(void){
  char str[11], *ptr;
  int len = 0, max_len = 0;
  scanf("%s", str);
  ptr = str;
  while(*ptr != '\0'){
    if(*ptr == 'A' || *ptr == 'C' || *ptr == 'G' || *ptr == 'T'){
      len++;
    }else{
      if(len > max_len){
        max_len = len;
      }
      len = 0;
    }
    ptr++;
  }
  if(len > max_len){
    max_len = len;
  }
  printf("%d\n", max_len);
  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x;
    cin>>x;
    if(x.size() == 2){
        if(x[0] == x[1]){
            cout<<1<<" 2" <<endl;
        }else cout<<-1<<" -1"<<endl;

    }else {
        bool flag = false;
        for(int i = 0 ; i < x.size() -1 ; i++){
            if(x[i] == x[i+1]){
                cout<<i+1<<" "<<i+2<<endl;
                return;
            }
        }
        for(int i = 0 ; i< x.size() -2 ; i++){
            if(x[i] == x[i+2]){
                cout<<i+1<<" "<<i+ 3<<endl;
                return;
            }
        }
        cout<<-1<<" "<<-1<<endl;
    }

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{  
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin>>A[i];
  }
  int X=0;
  for (int i = 41 - 1; i >= 0; --i)
  {
    int CNT = 0;
    for (int j = 0; j < N; ++j)
    {
      if((A[j]>>i)&1)
      CNT++;
    }
    if(CNT*2<=N &&(X+(1LL<<i))<=K)
      X+=(1LL<<i);
    
  }
  int ANS = 0;
  for (int i = 0; i < N; ++i)
  {
    ANS += (X^A[i]);
  }
  cout<<ANS<<endl;
  
  
  
  
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>

#define rep(i,n) for(int i=0; i<(n); ++i)

int main(){
    int h,n; std::cin >> h >> n;
    int all=0;
    rep(i,n){
        int a; std::cin >> a;
        all += a;
    }
    std::cout << (all < h ? "No" : "Yes") << std::endl;

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

int f(int n) {
    int res = 0;
    while (n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    if (n%f(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for y in a:
    if y<=x:
        ans+=1
        x-=y
if ans==N and x>0:
    ans-=1
print(ans)

Measured memory_bytes: 61644
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int X,Y;
    cin >> X >> Y;


    cout << X * Y<< endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long ll;

ll dp[1<<16], a[16][16];

int main () {
    int n;
    cin >> n;
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin >> a[i][j];

    for(int i=0;i<(1<<n);++i) {
        for(int j=0;j<n;++j) {
            if(!(i & (1<<j))) continue;
            for(int k=j+1;k<n;++k) {
                if(!(i & (1<<k))) continue;
                dp[i] += a[j][k];
            }
        }
    }

    for(int i=0;i<(1<<n);++i) {
        for(int mask=0;mask<=i/2;++mask) {
            if((i|mask) != i) continue;
            dp[i] = max(
                dp[i], 
                dp[i&mask]+dp[i&~mask]
            );
        }
    }

    cout << dp[(1<<n)-1] << "\n";
}

Measured memory_bytes: 768
# coding: utf-8
# Your code here!

s = input()
cnt = 0

for i in range(4):
    for j in [a+i+1 for a in range(3-i)]:
        if s[i] == s[j]:
            cnt += 1

if cnt == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940