akhauriyash/Code-Regression huggingface dataset:
#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;

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

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef complex<double> point;

#define X real()
#define Y imag()
#define angle(a) (atan2((a).imag(), (a).real()))
#define vec(a, b) ((b) - (a))
#define same(p1, p2) (dp(vec(p1, p2), vec(p1, p2)) < EPS)
#define dp(a, b) ((conj(a) * (b)).real())
#define cp(a, b) ((conj(a) * (b)).imag())
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) (a) / length(a)
#define rotateO(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotateO(vec(about, p), ang) + about)
#define reflectO(v, m) (conj((v) / (m)) * (m))
#define clr(a, b) memset(a, b, sizeof(a));

const ll N = 100005;
const int MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1.0);

ll n, k, h[N];
ll memo[N];

ll solve(int i)
{
	if(i == n - 1)
		return 0;

	ll& ret = memo[i];
	if(~ret)
		return ret;

	ret = solve(i + 1) + llabs(h[i] - h[i + 1]);
	for(int x = i + 2; x <= min(n - 1, i + k); x++)
		ret = min(ret, solve(x) + llabs(h[i] - h[x]));

	return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    	cin >> h[i];
    clr(memo, -1);
    cout << solve(0) << endl;
}

Measured memory_bytes: 6528
package main

import "fmt"

func main() {
	var A, B, C, D, maxC, minC, maxD, minD, P, maxP, minP int
	fmt.Scan(&A, &B, &C, &D)
	maxC = B - B%C
	if A%C == 0 {
		minC = A
	} else {
		minC = A + (C - A%C)
	}
	countC := (maxC-minC)/C + 1
	maxD = B - B%D
	if A%D == 0 {
		minD = A
	} else {
		minD = A + (D - A%D)
	}
	countD := (maxD-minD)/D + 1
	P = lcm(C, D)
	maxP = B - B%P
	if A%P == 0 {
		minP = A
	} else {
		minP = A + (P - A%P)
	}
	countP := (maxP-minP)/P + 1

	fmt.Println(B - A + 1 - countC - countD + countP)

}
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
	// return a / gcd(a, b) * b   桁あふれ対策
}

Measured memory_bytes: 512
N=int(input())
s=map(int,input().split())
a=[]
j=0
for i in s:
  a.append(i)
for i in range(N-1):
  if a[i]>a[i+1]:
    j+=(a[i]-a[i+1])
    a[i+1]=a[i]
print(j)

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

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a.push_back(a[i] + k);
    int ans = 1e9;
    rep(i, n) {
        ans = min(ans, a[n - 1 + i] - a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1804
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n,x;
	cin>>n>>x;
	int l[n];
	rep(i,n)cin>>l[i];
	int res=1;
	int d=0;
	int i=0;
	while(d+l[i]<=x&&i<n){res++;d=d+l[i];i++;}
	cout<<res;
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    int k = sc.nextInt();
    HashSet<String> set = new HashSet<String>();
    ArrayList<String> list = new ArrayList<String>();
    for(int i = 0; i < s.length(); i++) {
      for(int j = 1; j <= 5; j++) {
        if((i + j) <= n) set.add(s.substring(i, i + j));
      }
    }
    for(Iterator<String> itr = set.iterator(); itr.hasNext();) {
      list.add(itr.next());
    }
    Collections.sort(list);
    System.out.println(list.get(k - 1));
  }
}


Measured memory_bytes: 26704
// abc137c.cpp : Green Bin
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

	unordered_map<ll,ll> v;
	while (n--){
		string s; cin>>s;
		sort(s.begin(), s.end());
		ll k = 0LL;
		for(char c: s) k = k*26LL + (c-'a');
		v[k]++;
	}

	ll ans = 0LL;
	for(auto p: v) ans += p.second * (p.second-1) / 2LL;
	cout<< ans << endl;
}

Measured memory_bytes: 4388
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

//10進数を2進数に変換_63個の要素を持つ配列
vector<int> Convert10to2(ll n) {
	vector<int> ans(63);
	rep(i, 63) {
		ans[i] = n % 2;
		n -= n % 2;
		n /= 2;
	}
	return ans;
}
//2進数を10進数に変換_63個の要素を持つ配列
ll Convert2to10(vector<int> a) {
	ll ans=0;
	ll j = 1;
	rep(i, a.size()) {
		ans += a[i] * j;
		if (i != a.size() - 1) {
			j *= 2;
		}
	}
	return ans;
}
//XORを計算
vector<int> CalcXOR2to2(vector<int> a, vector<int> b) {
	rep(i, 63) {
		if (a[i] != b[i]) {
			a[i] = 1;
		}
		else {
			a[i] = 0;
		}
	}
	return a;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int> c(m);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, k) {
			int a;
			cin >> a;
			c[a - 1]++;
		}
	}
	int ans=0;
	rep(i, m) {
		if (c[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, C;
int d[30][30];
int c[501][501];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> C;
  REP(i, C) REP(j, C) cin >> d[i][j];

  REP(i, n) REP(j, n) {
    cin >> c[i][j];
    c[i][j]--;
  }

  int c_0[30];
  int c_1[30];
  int c_2[30];

  REP(i, C) {
    ll sum_0 = 0;
    ll sum_1 = 0;
    ll sum_2 = 0;
    REP(l, n) REP(p, n) {
      if((l + p) % 3 == 0) sum_0 += d[c[l][p]][i];
      else if((l + p) % 3 == 1) sum_1 += d[c[l][p]][i];
      else sum_2 += d[c[l][p]][i];
    }
    c_0[i] = sum_0;
    c_1[i] = sum_1;
    c_2[i] = sum_2;
  }

  ll ans = LLINF;
  REP(i, C) REP(j, C) REP(k, C) if(i != j && j != k && k != i) {
    ll sum = c_0[i] + c_1[j] + c_2[k];
    ans = min(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1280
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY puts("Yes")
#define NN puts("No")
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
bool sumiko[2000000];
int solve(){
  int n,m;
  cin >> n >> m;
  Graph G(n);
  int a,b;
  rep(i,m){
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  rep(i,G[0].size()){
    sumiko[G[0][i]] = true; 
  }
  rep(i,G[n - 1].size()){
    if(sumiko[G[n - 1][i]]){
      puts("POSSIBLE");
      return 0;
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 12144
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

map<ll, int> primeFactor(ll num){
	map<ll, int> ret;
	for(ll i = 2; i * i <= num; i ++){
		while(num%i == 0){
			ret[i] ++;
			num /= i;
		}
	}
	if(num != 1)ret[num] = 1;
	return ret;
}
ll powll(ll x, ll y){
	ll ret = 1;
	for(ll i = 0; i < y; i ++){
		ret *= x;
	}
	return ret;
}

int main(){

	ll N, P;
	cin >> N >> P;
	map<ll, int> pf = primeFactor(P);
	
	ll ans = 1;
	for(auto itr = pf.begin(); itr != pf.end(); itr ++){
		//cout << itr->first << " " << itr->second << endl;
		ans *= max(1LL, powll(itr->first, (itr->second / N)));
	}
	cout << ans << endl;

//"Hiroakimm0415"
	return 0;
}

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

int main() {
    string x;
    cin >> x;
    if (x[5] == '0' && (x[6] == '1' || x[6] == '2' || x[6] == '3' || x[6] == '4')){
        cout << "Heisei" << endl;
    }
  else{
    cout << "TBD" << endl;
}
}

Measured memory_bytes: 384
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <queue>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define T3I tuple<int, int, int>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    int a, b;
    cin >> a >> b;
    int x = max(a*50, b*40);
    x = (x+3)/4;
    if(x*8/100 == a && x/10 == b) {
        cout << x << endl;
    }else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
const double pi = acos(-1) ;

void solve(){
	double a , b , h , m ;
	cin >> a >> b >> h >> m ;
	double hour = 30.0*h ;
	double min = 6*m ;
	hour += (0.5*m) ;
	double dif = fabs(hour-min) ;
	if(360-dif < dif) dif = 360-dif ;
	double ans = a*a + b*b - 2*a*b*cos(dif*pi/180.0) ;
	ans = sqrt(ans) ;
	cout << fixed << setprecision(20) <<ans << endl ;

}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
}


Measured memory_bytes: 4236
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// ReSharper disable PossibleNullReferenceException
// ReSharper disable AssignNullToNotNullAttribute

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
           Console.WriteLine(n*(n-1)/2);
        }
    }
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

const ll INF=1e13+7;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
#define rep(i,n) for(int i=0;i<(n);i++)

int Place[60][60];
bool seen[60][60];
int W,H;

void DFS(int h,int w){
    seen[h][w]=true;

    for(int i=0;i<8;i++){
        int nw=w+dx[i];
        int nh=h+dy[i];

        if(nw<0||nw>=W||nh<0||nh>=H)continue;
        if(Place[nh][nw]==0)continue;

        if(seen[nh][nw]==true)continue;

        DFS(nh,nw);
    }
}

int Input(){
    int Co=0;
    cin>>W>>H;
    if(W==0&&H==0) return -1;
    rep(i,H){
        rep(j,W)cin>>Place[i][j];
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(Place[i][j]==1&&seen[i][j]==false){
                Co++;
                DFS(i,j);
            }
        }
    }
    return Co;
}

int main(){
    vector<int> answers(0);
    int ans=0,num=0;
    while(1){
        memset(seen,false,sizeof(seen));
        ans=Input();
        if(ans==-1)break;
        answers.push_back(ans);
        num++;
    }
    rep(i,num)cout<<answers[i]<<endl;
    return 0;
}

//a=97,z=122


Measured memory_bytes: 3136
#include <cstdio>
int N, Q, a[200001], E[200001], O, C[200001];
inline void inc(int x)
{
	if (1 <= x && x <= N && C[x]++ == 0)
		O--;
}
inline void dec(int x)
{
	if (1 <= x && x <= N && --C[x] == 0)
		O++;
}
inline void add(int x)
{
	inc(E[x]--);
}
inline void del(int x)
{
	dec(++E[x]);
}
int main()
{
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; i++)
		E[i] = i;
	O = N;
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", a + i);
		add(a[i]);
	}
	while (Q--)
	{
		int x, w;
		scanf("%d%d", &x, &w);
		del(a[x]);
		a[x] = w;
		add(a[x]);
		printf("%d\n", O);
	}
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<long long> m(n+1);
  m.at(0)=2;
  m.at(1)=1;

  for(int i=2;i<n+1;i++){
    m.at(i)=m.at(i-1)+m.at(i-2);
  }
  
  cout<<m.at(n)<<endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = input()
    White = np.zeros(n + 1)
    Black = np.zeros(n + 1)

    for i in range(n):
        if S[i] == "#":
            Black[i + 1] = Black[i] + 1
        else:
            Black[i + 1] = Black[i]

    for i in reversed(range(n)):
        if S[i] == ".":
            White[i] = White[i + 1] + 1
        else:
            White[i] = White[i + 1]

    res = White + Black
    print(int(min(res)))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 17640
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,l,x[300005],t[300005],top,ans;
int main()
{
	scanf("%d%d",&n,&l);
	l*=2;
	for(int i=1;i<=n;i++)scanf("%d",&x[i]);
	for(int i=1;i<=n;i++)
	{
		int ti;
		scanf("%d",&ti);
		ans+=(ti-1)/l;
		ti=(ti-1)%l+1;
		t[i]=2*(ti<=l-2*x[i])+(ti<=2*x[i]);
		if(t[i]==0)ans++,x[0]=x[i];
		else t[++m]=t[i],x[m]=x[i];
	}
	n=m;
	bool f=1;
	for(int i=1;i<=n;i++)
	{
		if(t[i]==3)top++;
		if(t[i]==2)
		{
			ans++,m--;
			if(top)m--,top--,f=1;
			else f=0;
		}
	}
	if(!m)return printf("%lld\n",1ll*(ans+f)*l),0;
	top=0,f=1;
	if(x[n]<x[0])f=0;
	for(int i=n;i>=1;i--)
	{
		if(t[i]==2)continue;
		if(t[i]==3)top++;
		if(t[i]==1)
		{
			ans++,m--;
			if(top)m--,top--;
		}
		if(!top)f=0;
	}
	if(f)m--;
	ans+=(m+3)/2;
	printf("%lld\n",1ll*l*ans);
	return 0;
}

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

int main() {
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i=5;i<=n;i*=5){
            ans += n/i;
        }
        cout << ans << endl;
    }
    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int E[15];
ll dp[1<<15];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	while(M--) {
		cin>>x>>y;
		x--,y--;
		E[x] |= 1<<y;
	}
	
	dp[0]=1;
	for(int ST=1;ST<1<<N;ST++) {
		int U=((1<<N)-1)^ST;
		for(int S=ST-1; S>=0; S--) {
			S&=ST;
			int T=ST^S;
			if((T&3)==3) continue;
			
			ll mul=1;
			FOR(i,N) {
				if(T&(1<<i)) (mul *= 1<<__builtin_popcount(E[i]&U))%=mo;
				if(U&(1<<i)) (mul *= (1<<__builtin_popcount(E[i]&T))-1)%=mo;
			}
			(dp[ST] += mul*dp[S])%=mo;
		}
	}
	cout<<dp[(1<<N)-1]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,j,a,b,c,min=10000,max=1;
  scanf("%d%d%d%d",&n,&a,&b,&c);
  int l[n+1];
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
    max*=4;
  }
  for(i=1;i<max;i++){
    int anum=0,bnum=0,cnum=0,k=i,mp=0;
    for(j=0;j<n;j++){
      if(k%4==1){
        if(anum!=0)
          mp+=10;
        anum+=l[j];
      }
      else if(k%4==2){
        if(bnum!=0)
          mp+=10;
        bnum+=l[j];
      }
      else if(k%4==3){
        if(cnum!=0)
          mp+=10;
        cnum+=l[j];
      }
      k/=4;
    }
    if(anum!=0 && bnum!=0 &&cnum!=0){
      mp+=abs(anum-a)+abs(bnum-b)+abs(cnum-c);
      if(mp<min)
        min=mp;
    }
  }
  printf("%d\n",min);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
     
#define pll pair <long long,long long>
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define vll vector <ll>
#define NFS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define M 1000000007   
using namespace std;

void solve()
{
	int x,n;
	cin>>x>>n;
	bool found=false;
	vector<int> v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		if(v[i]==x)
			found=true;
	}
	if(!found)
		{cout<<x;return;}
	sort(v.begin(),v.end());
	int idx=0;
	for(int i=0;i<(int)v.size();i++)
	{
		if(v[i]==x)
			idx=i;
	}
	int ans1=x,ans2=x;
	for(int i=idx;i<(int)v.size();i++)
	{
		if(v[i]!=ans1)
		{
			break;
		}
		ans1++;
	}
	for(int i=idx;i>=0;i--)
	{
		if(v[i]!=ans2)
		{
			break;
		}
		ans2--;
	}
	if(x-ans2<=abs(x-ans1))
	{
		cout<<ans2;
	}else{
		cout<<ans1;
	}
}
 
int main()
{
    NFS
 	int t=1;
 	//cin>>t;
 	while(t--)
 	{
 		solve();
 	}
    return 0;
}

Measured memory_bytes: 3648
[N,L] = list(map(int,input().split()))
aji = []
for i in range(1,N+1):
    aji.append(L-1+i)

output = sum(aji)-min(list(map(abs,aji)))

if aji[list(map(abs,aji)).index(min(list(map(abs,aji))))]<0:
    output += 2*min(list(map(abs,aji)))

print(output)

Measured memory_bytes: 3064
N = int(input()); INF = float("inf")
A = list(map(int,input().split()))
#dp[i+1][j]: i番目まで見てj=0(i番目がそのまま),j=1(i番目が逆転)の時の最大値
dp = [[-INF]*2 for _ in range(N)]
dp[0][0] = 0
dp[0][1] = 0
dp[1][0] = A[0]+A[1]
dp[1][1] = -(A[0]+A[1])
for i in range(2,N):
  dp[i][0] = max(dp[i-1][0] + A[i], dp[i-1][1] + A[i])
  dp[i][1] = max(dp[i-1][0] - (A[i-1]*2 + A[i]), dp[i-1][1] + A[i-1]*2 - A[i])
#print(dp)
ans = max(dp[N-1])
print(ans)

Measured memory_bytes: 30552
n,m=map(int,input().split())
ab=[]

for _ in range(n):
    aa,bb=map(int,input().split())
    ab.append((aa,bb))

ab=sorted(ab,key=lambda t: t[0])

ans=0
sums=0

for c in ab:
    sums+=min(c[1],m)
    ans+=min(c[1],m)*c[0]
    m-=c[1]
    if m <= 0:
        print(ans)
        exit()

    
    


Measured memory_bytes: 18952
N, C, K = map(int, raw_input().split())
T = []
for i in xrange(N):
    T.append(int(raw_input()))
T = list(sorted(T))
nBus = 0
curBus = []
for i in xrange(N):
    if len(curBus) == 0:
        curBus.append(T[i])
        continue
    if (T[i] - curBus[0] > K) or len(curBus) == C:
        nBus += 1
        curBus = []
    curBus.append(T[i])
if len(curBus) > 0:
    nBus += 1
print nBus

Measured memory_bytes: 7480
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)



int main(){
    int N;
    cin>>N;
    cout<<(N-2)*180<<endl;
}



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

const bool CHECK_OVERFLOW64 = true;
const long long LL_INF = (long long) 2e18 + 5;

struct point {
    long long x, y;

    point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}

    point operator-(const point &other) const {
        return point(x - other.x, y - other.y);
    }
};

long long cross(const point &a, const point &b) {
    return a.x * b.y - b.x * a.y;
}

int cross_sign(const point &a, const point &b) {
    if (CHECK_OVERFLOW64) {
        double double_value = (double) a.x * b.y - (double) b.x * a.y;

        if (abs(double_value) > 1e18)
            return double_value > 0 ? +1 : -1;
    }

    uint64_t uint64_value = (uint64_t) a.x * b.y - (uint64_t) b.x * a.y;

    if (uint64_value == 0)
        return 0;

    return uint64_value < 9e18 ? +1 : -1;
}

bool left_turn(const point &a, const point &b, const point &c) {
    return cross_sign(b - a, c - b) > 0;
}


// monotonic_dp_hull enables you to do the following two operations in amortized O(1) time:
// 1. Insert a pair (a_i, b_i) into the structure. a_i must be non-decreasing.
// 2. For any value of x, query the maximum value of a_i * x + b_i. x must be non-decreasing.
// All values a_i, b_i, and x can be positive or negative.
struct monotonic_dp_hull {
    deque<point> points;

    void insert(const point &p) {
        assert(points.empty() || p.x >= points.back().x);

        if (!points.empty() && p.x == points.back().x) {
            if (p.y <= points.back().y)
                return;

            points.pop_back();
        }

        while (points.size() >= 2 && left_turn(points[points.size() - 2], points.back(), p))
            points.pop_back();

        points.push_back(p);
    }

    void insert(long long a, long long b) {
        insert(point(a, b));
    }

    // Queries the maximum value of ax + by.
    long long query(long long x, long long y = 1) {
        static long long prev_x = -LL_INF, prev_y = 1;
        assert(prev_x == -LL_INF || x * prev_y >= prev_x * y);
        prev_x = x; prev_y = y;

        while (points.size() >= 2 && x * (points[1].x - points[0].x) >= (points[0].y - points[1].y) * y)
            points.pop_front();

        return points[0].x * x + points[0].y * y;
    }
};


int N;
long long C;
vector<int> H;
vector<long long> dp;

int main() {
    scanf("%d %lld", &N, &C);
    H.resize(N);

    for (int &h : H)
        scanf("%d", &h);

    dp.resize(N);
    monotonic_dp_hull hull;

    for (int i = 0; i < N; i++) {
        if (i == 0)
            dp[i] = 0;
        else
            dp[i] = -hull.query(2 * H[i]) + (long long) H[i] * H[i];

        hull.insert(H[i], -((long long) H[i] * H[i] + C + dp[i]));
    }

    printf("%lld\n", dp[N - 1]);
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;

int main(void){
    Cin(int, n);
    vector<int> out{1,2,3,5,6,9,10,13,17};
    Cout((find(Range(out), n) != out.end()) ? "No" : "Yes");
}

Measured memory_bytes: 256
import sys
import math
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
l,r,d=get_ints()
count=0
for i in range(l,r+1):
    if i%d==0:
        count=count+1
print(count)

Measured memory_bytes: 62088
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  string s;
  i64 k;
  cin >> s >> k;
  i64 ans = 0;
  string tmp = s;
  for (i64 i = 1; i < tmp.size(); i++)
    if (tmp[i] == tmp[i - 1])
    {
      tmp[i] = '*';
      ans++;
    }
  i64 cnt = 0;
  tmp = tmp[tmp.size() - 1] + s;
  for (i64 i = 1; i < tmp.size(); i++)
    if (tmp[i] == tmp[i - 1])
    {
      tmp[i] = '*';
      cnt++;
    }
  bool ok = true;
  for (i64 i = 1; i < s.size(); i++)
    if (s[i] != s[i - 1])
      ok = false;
  if (s.size() == 1)
    cout << k / 2 << endl;
  else if (ok)
    cout << k * s.size() / 2 << endl;
  else
    cout << ans + cnt * (k - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int h,n;
pair<int,int> a[1005];
int dp[1001][10001];
int help(int id,int co)
{
    if(co>=h)
    return 0;
    if(id==n)
        return INT_MAX;
        if(dp[id][co]!=-1)
            return dp[id][co];
    int op1 = help(id,co+a[id].first)+a[id].second;
    int op2 = help(id+1,co);
    int an = min(op1,op2);
    dp[id][co]=an;
    return an;
}
    signed main(){
        goku
     memset(dp,-1,sizeof(dp));
     cin>>h>>n;
     for(int i=0;i<n;i++)
     {
         cin>>a[i].first>>a[i].second;
     }
     cout<<help(0,0);
       return 0;
    }


Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inp_vecN for(int i=0;i<n;i++)cin>>v[i]; 
vector<int> get_Factors(ll n)
{
      vector <int> v;
      for(ll i=2; i<=sqrt(n)+1; i++)
      {
            if(n%i==0)
            {
                  v.push_back(i);
                  v.push_back(n/i);
            }
      }

      v.push_back(1);

      return v;
}
string get_bin(ll n)
{
    string s = "";
    while(n > 0)
    {
        s += ('0' + n%2);
        n /= 2;
    }
    reverse(s.begin(), s.end());
    return s;
}

ll bin_to_dec(string s)
{
    ll ans = 0;
    for(auto ch: s)
    {
        ans *= 2;
        ans += (ch - '0');
    }
    return ans;
}
void PrintVector(vector<ll> v,int n)
{

    for(int i=0;i<n;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
int no_of_primeFactors(int n)  
{ 
    int count=0;
    while (n % 2 == 0)  
    {  
        count++;
        n = n/2;  
    }  
   
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    { 
        while (n % i == 0)  
        {  
           count++;
            n = n/i;  
        }  
        
    }  
    if (n > 2)  
        count++;
    return count;
} 
 ll gcd(int a, int b)
{ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
} 
   
  ll lcm(int a, int b)  
{  
    return (a/gcd(a, b)*b);  
}  



ll pwr(ll base,ll expo,ll m)
{
    if(base==0) return 0LL;
    if(expo==0) return (1LL%m);
    if((expo&1)==0) {ll temp=pwr(base,expo>>1,m); return (temp*temp)%m;}
    return ((base%m)*pwr(base,expo-1,m))%m;
}

int main(int argc, char const *argv[])
{
    ios;

   // ll n;
    //cin>>n;
    string s,t;
    cin>>s>>t;

    if( t.substr(0,s.length())==s)
    {
      cout<<"Yes";
    }
    else
      cout<<"No";

    





    



    return 0;
}

Measured memory_bytes: 3604
n, k, q = map(int, input().split())
a = [int(input()) for _ in range(q)]

cnt = [0] * n

for i in a:
    cnt[i - 1] += 1

for c in cnt:
    if k - (q - c) > 0:
        print('Yes')
    else:
        print('No')


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

string n;
int k;

int dp[107][5][2];

int32_t main() {

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

    cin >> n >> k;

    int l = n.length();

    dp[0][0][0] = 1;

    for(int i = 0; i < l; ++i) {
        int dig = n[i] - '0';
        for(int j = 0; j <= k; ++j) {
            if(dig == 0) {
                dp[i+1][j][0] += dp[i][j][0];
            } else {
                dp[i+1][j][1] += dp[i][j][0];
            }
            dp[i+1][j][1] += dp[i][j][1];
            if(j < k) {
                for(int d = 1; d <= 9; ++d) {
                    dp[i+1][j+1][1] += dp[i][j][1];
                    if(dig == d) {
                        dp[i+1][j+1][0] += dp[i][j][0];
                    } else if(d < dig) {
                        dp[i+1][j+1][1] += dp[i][j][0];
                    }
                }
            }
        }
    }

    int ans = dp[l][k][0] + dp[l][k][1];
    cout << ans << '\n';
    
    return 0;
}


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

typedef long long ll;

int main() {
	ll n, m;
	cin >> n >> m;
	ll num1 = n,num2=m/2;
	if (num2 < num1) {
		cout << num2 << endl;
	}
	else {
		ll num3 = m - num1 * 2;
		cout << num3 / 4 + num1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    string S;
    cin >> S;
    map<char, int>d;
    for (int i=0; i<S.size(); i++) {
        if (d.count(S[i]) == 0) {
            d[S[i]] = 1;
        }
    }

    bool ikeru = false;
    char a;
    for (char j='a'; j <= 'z'; j++) {
        if (d.count(j) == 0) {
            ikeru = true;
            a = j;
            break;
        }
    }

    if (ikeru) {
        cout << a << endl;
    } else {
        cout << "None" << endl;
    }

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M; cin>>N>>M;

    vector<list<int> > order(N);
    rep(i,N)rep(j,M){
        int a; cin>>a; a--;
        order[i].pb(a);
    }

    using litr = list<int>::iterator;
    vector<vector<litr> > pos(N, vector<litr>(M));
    rep(i,N){
        ITR(itr,order[i]){
            pos[i][*itr] = itr;
        }
    }

    vi d(M);
    int ans=N;
    rep(i,M){
        fill(all(d),0);
        rep(i,N) d[order[i].front()]++;
        auto itr = max_element(all(d));
        chmin(ans,*itr);
        int x = itr-d.begin();
        rep(i,N){
            order[i].erase(pos[i][x]);
        }
    }
    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 6896
/*
author: Apoorv Singh
*/

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

typedef vector <int> vi;
typedef vector <long long> vl;
typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define ll long long
#define pb push_back   
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " " << (x) << endl;
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second

ll modulo = 1e9 + 7;

template <class X>

void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t, f = 0;
    cin >> t;
    char prev;
    um <string, int> d;
    FOR(i,0,t)
    {
        string x;
        cin >> x;
        int l = x.length();
        if (i == 0)
            prev = x[l-1];
        if (i > 0 and (x[0] != prev or d[x]))
            f = 1;
        prev = x[l-1];
        d[x] = 1;
    }
    if (f)
        cout << "No" << endl;
    else 
        cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> S(M);
  for (int i=0;i<M;i++) {
    int k;cin >> k;
    S.at(i).resize(k);
    for (int j=0;j<k;j++) {
      cin >> S.at(i).at(j);
    }
  }
  vector<int> P(M);
  for (int i=0;i<M;i++) cin >> P.at(i);
  int count=0;
  for (int bit;bit<(1<<N);bit++) {
    bool result=true;
    for (int i=0;i<M;i++) {
      int c=0;
      for (int x:S.at(i)) {
        if (bit & (1<<(x-1))) c++;
      }
      if (!(c%2)==P.at(i)) {
        result=false;
        break;
      }
    }
    if (result) count++;
  }
  cout << count << endl;
}


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

int main()
{  
  int n,l;
  cin >> n >> l;
  int min=l;
  int ans=0;
  for(int i=0;i<n;++i){
    if(l+i<=0){
      if(min<l+i){
        min=l+i;
      }
    }else{
      if(min>l+i){
        min=l+i;
      }
    }
    ans+=(l+i);
  }
  
  cout << ans-min;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
dp=[10**4*n]*n
l=list(map(int,input().split()))
dp[0]=0
for i in range(1,n):
  dp[i]=min(dp[i-j]+abs(l[i-j]-l[i]) for j in range(1,min(i,k)+1))
print(dp[-1])

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

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    int n, W;
    cin >> n >> W;

    vi w(n + 1), v(n + 1);
    for (int i = 0; i < n; ++i){
        cin >> w[i] >> v[i];
    }

    int dp[n + 1][W + 1];
    memset(dp, 0, sizeof dp);

    for (int i = 0; i <= n; ++i){
        for (int j = 0; j <= W; ++j){
            if (i == 0 || j == 0){
                dp[i][j] = 0;
            } else if (w[i - 1] <= j){
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            } else {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[n][W] << '\n';
}

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

int main() {
  int K,T;
  cin>>K>>T;
  vector<int> a(T);
  for(int i=0;i<T;i++) cin>>a[i];

  int ans=1234567890;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int most=a[0];
  vector<int> c(K);
  int sum=0;
  for(int i=1;i<T;i++){
    sum+=a[i];
  }
  if(sum>=a[0]) cout<<0<<endl;
  else {
    cout<<a[0]-sum-1<<endl;
  }
  }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n = 0;
  string s;
  cin >> s;
  for (int i = 0; i< s.size()-1;i++){
    if (s[i] == 'P'){
      if (s[i+1] == '?') s[i+1]='D';
    }
    else if (s[i] == '?') s[i] = 'D';
  }
  if (s[s.size()-1] == '?') s[s.size()-1] = 'D';

  cout << s << endl;

  


  return 0; 
}



Measured memory_bytes: 3756
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7


def main():
    a = list(map(int, input().split()))
    t = min(a[0], a[3], a[4])
    r = t * 3
    a[0] -= t
    a[3] -= t
    a[4] -= t
    for i in [0,3,4]:
        r += a[i] // 2 * 2
    if t > 0:
        rr = (t-1) * 3
        for i in [0,3,4]:
            rr += (a[i]+1) // 2 * 2
        if rr > r:
            r = rr
    return a[1] + r


print(main())


Measured memory_bytes: 7840
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define pf push_front
LL A[101010];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    rep(i, N) scanf("%lld", &A[i]);
    
    // 2. sort.
    sort(A, A + N);
    
    // 3. ぐるぐるする.
    deque<LL> dq;
    rep(i, N / 2){
        // 奇数ならば, 後ろに追加, 偶数ならば, 前に追加.
        if(i % 2) dq.pb(A[i]), dq.pf(A[N - 1 - i]);
        else      dq.pf(A[i]), dq.pb(A[N - 1 - i]);
    }
    // if(N & 1) dq.pf(A[N / 2]);
    // 
    // ex.
    // 5
    // 1
    // 19
    // 2
    // 6
    // 7
    // -> 6 は 前(6 7 1 19 2)でなく, 後ろ(7 1 19 2 6)に追加した方が, 大きくなる(42 < 45).
    if(N & 1){
        if(abs(dq.front() - A[N / 2]) > abs(dq.back() - A[N / 2])) dq.pf(A[N / 2]);
        else                                                       dq.pb(A[N / 2]);
    }
    // for(auto &p : dq) printf("%lld ", p);
    // puts("");
    
    // 4. 隣り合う要素の差の合計.
    LL ans = 0;
    rep(i, N - 1) ans += abs(dq[i + 1] - dq[i]);
    
    // 5. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
    return 0;
}


Measured memory_bytes: 3632
n,t = map(int,input().split())

ans = 100000000000000
for i in range(n):
    x, y = map(int,input().split())
    if y > t:
        continue
    else:
        if ans > x:
            ans = x


if ans ==100000000000000:
    print("TLE")
else:
    print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void dfs(int x,string a,string b,string c){
	if(x==a.length()){
		if(b==c){puts("YES");exit(0);}
		else return ;
	}
	if(a[x]=='A')dfs(x+1,a,b,c);
	dfs(x+1,a,b,c+a[x]);
}
int main(){
	string s,t="AKIHABARA";
	cin>>s;
	dfs(0,t,s,"");
	puts("NO");
}

Measured memory_bytes: 256
import java.math.BigDecimal

fun main() {
    val l = nextInt()
    println(BigDecimal(l.toDouble() * l * l / 27).toPlainString())
}

val scanner = java.util.Scanner(System.`in`)
fun next(): String = scanner.next()
fun nextInt() = scanner.nextInt()
fun nextLong() = scanner.nextLong()
fun nextList() = readLine()!!.split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")

fun main(args: Array<String>) = main()

Measured memory_bytes: 29468
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxn = 1e5 + 111;
int main() {
    string a, b;
    cin >> a >> b;
    int aa = a.length(), bb = b.length();
    int maxcnt = 0;
    for (int i = 0; i + bb - 1 < aa; ++i) {
        int cnt = 0;
        for (int j = 0; j < bb; ++j) {
            if (a[i + j] == b[j]) ++cnt;
        }
        maxcnt = max(maxcnt, cnt);
    }
    printf("%d\n", bb - maxcnt);
    return 0;
}

Measured memory_bytes: 3708
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <string_view>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout(a) cout << fixed << setprecision((int)(a))

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1'000'000'007;
constexpr ll MOD2   = 998'244'353;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)      for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
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); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int dp[100000];

    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                    dp[i - 1] + abs(h[i] - h[i - 1]));
    }

    cout << dp[n - 1] << endl;

return 0;
}


Measured memory_bytes: 4020
#include <stdio.h>

typedef struct {
	int id;
	int rank;
	int score;
} TEAM;

TEAM team[200];

int cmp_score(TEAM *A, TEAM *B)
{
	return (B->score - A->score);
}

int cmp_id(TEAM *A, TEAM *B)
{
	return (A->id - B->id);
}

int main(void)
{
	int N;
	int i, j;
	
	for (i = 0; i < 200; i++){
		team[i].id = i;
	}
	
	scanf("%d", &N);
	for (i = 0; i < N * (N - 1) / 2; i++){
		int a, b, c, d;
		
		scanf("%d %d %d %d", &a, &b, &c, &d);
		
		if (c > d){
			team[a - 1].score += 3;
		}
		else if (c == d){
			team[a - 1].score += 1;
			team[b - 1].score += 1;
		}
		else {
			team[b - 1].score += 3;
		}
	}
	
	qsort(team, N, sizeof(TEAM), cmp_score);
	
	for (i = 1; i <= N; i++){
		if (i == 1){
			team[i].rank = 1;
		}
		else if (team[i - 1].score == team[i].score){
			team[i].rank = team[i - 1].rank;
		}
		else if (team[i - 1].score > team[i].score){
			team[i].rank = i;
		}
	}
	
	qsort(team, N, sizeof(TEAM), cmp_id);
	
	for (i = 0; i < N; i++){
		printf("%d\n", team[i].rank + 1);
	}
	
	return 0;
}

Measured memory_bytes: 648
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
	int n, a[100001],max=0,sum=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
		if (max < a[i])max = a[i];
	}
	printf("%d\n", sum - max / 2);
	return 0;
}

Measured memory_bytes: 128
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, K = MAP()
    N += 1

    ans = 0
    for i in range(K, N+1):
        ans += i*(N-i) + 1
        ans %= mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10648