akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll a,b,q;
ll s[100100],t[100100],x[100100];
ll sn[100100],tn[100100];

int main(){
	cin>>a>>b>>q;
	REP(i,a)
		cin>>s[i];
		
	REP(i,b)
		cin>>t[i];
		
	REP(i,q)
		cin>>x[i];
		
	REP(i,a){
		auto it=lower_bound(t,t+b,s[i]);
		if(it!=t+b&&it!=t){
			ll pos=distance(t,it);
			sn[i]=min(s[i]-t[pos-1],t[pos]-s[i]);
		}else if(it==t){
			sn[i]=t[0]-s[i];
		}else{
			sn[i]=s[i]-t[b-1];
		}
	}
	REP(i,b){
		auto it=lower_bound(s,s+a,t[i]);
		if(it!=s+a&&it!=s){
			ll pos=distance(s,it);
			tn[i]=min(t[i]-s[pos-1],s[pos]-t[i]);
		}else if(it==s){
			tn[i]=s[0]-t[i];
		}else{
			tn[i]=t[i]-s[a-1];
		}
	}
	
	REP(i,q){
		auto its=lower_bound(s,s+a,x[i]);
		auto itt=lower_bound(t,t+b,x[i]);
		ll ans1=INF;
		ll ans2=INF;
		if(its!=s+a&&its!=s){
			ll pos=distance(s,its);
			ans1=min(s[pos]-x[i]+sn[pos],x[i]-s[pos-1]+sn[pos-1]);
		}else if(its==s){
			ans1=s[0]-x[i]+sn[0];
		}else{
			ans1=x[i]-s[a-1]+sn[a-1];
			//cout<<endl;
		}
		
		if(itt!=t+b&&itt!=t){
			ll pos=distance(t,itt);
			ans2=min(t[pos]-x[i]+tn[pos],x[i]-t[pos-1]+tn[pos-1]);
		}else if(itt==t){
			ans2=t[0]-x[i]+tn[0];
		}else{
			ans2=x[i]-t[b-1]+tn[b-1];
			//cout<<endl;
		}
		//cout<<ans1<<" "<<ans2<<endl;
		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}

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

using namespace std;

const int maxn = 1e5 + 5;

int dp[maxn], a[maxn];
const int INF = 1e9;

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        dp[i] = INF;
    }
    dp[2] = abs(a[2] - a[1]);
    dp[1] = 0;
    for(int i = 3; i <= n; i++){
        for(int j = 1; j <= k && j < i; j++){
            dp[i] = min(dp[i], dp[i - j] +  abs(a[i] - a[i - j]));
        }
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

const int inf = 1e9;

int main() {
	int n, k;
	scanf ("%d %d", &n, &k);
	vector < int > h (n);
	for (int & x : h) scanf ("%d", &x);
	vector < int > dp (n, inf);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = i - 1; j >= i - k && j >= 0; j--) {
			dp[i] = min (dp[i], dp[j] + abs (h[i] - h[j]));
		}
	}
	printf ("%d\n", dp[n - 1]);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl "\n"
#define pii tuple<ll,ll,ll>
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
void amfetamin()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
amfetamin();
ll n,d;
cin>>n>>d;
int sol=0;
for (int i=0; i<n; i++)
{
    ll x,y;
    cin>>x>>y;
    x=abs(x);
    y=abs(y);
    ll r=x*x+y*y;
    if (d*d>=r)
        sol++;
}
cout<<sol;



}


Measured memory_bytes: 3652
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  vll v(n); rep(i, n) cin >> v[i];
  map<ll, ll> up, down;
  vll key_up, key_down;
  for(ll i = 0;i < n;i += 2)
  {
    if(!up.count(v[i]))
    {
      key_up.pb(v[i]);
    }
    up[v[i]]++;
  }
  for(ll i = 1;i < n;i += 2)
  {
    if(!down.count(v[i]))
    {
      key_down.pb(v[i]);
    }
    down[v[i]]++;
  }
  vpll a, b;
  rep(i, key_up.size())
  {
    a.pb(mp(up[key_up[i]], key_up[i]));
  }
  if(key_up.size() == 1) a.pb(mp(0, -1));
  sort(all(a)), reverse(all(a));
  rep(i, key_down.size())
  {
    b.pb(mp(down[key_down[i]], key_down[i]));
  }
  if(key_down.size() == 1) b.pb(mp(0, -2));
  sort(all(b)), reverse(all(b));
  ll ans = 0;
  if(a[0].second != b[0].second)
  {
    fin(n / 2 - a[0].first + n / 2 - b[0].first);
  }
  else
  {
    //cout << a[0].first << " " << b[1].first  << " " << a[1].first << " " << b[0].first << endl;
    fin(min(n / 2 - a[0].first + n / 2 - b[1].first, n / 2 - a[1].first + n / 2 - b[0].first));
  }  
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


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

int main() {
  ll n;
  cin >> n;
  
  vector<char> stones(n);
  rep(i, n)
    cin >> stones.at(i);
  
  ll red = 0;
  rep(i, n){
    if(stones.at(i) == 'R')
      red++;
  }
  ll count = 0;
  rep(i, red){
    if(stones.at(i) == 'W')
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main()
{
	while (1) {
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			vi v(n);
			ans = 0;
			REP(i, n) cin >> v[i];
			sort(ALL(v));
			ans = accumulate(ALL(v), 0LL);
			ans -= (v[0] + v[n - 1]);
		}
		cout << ans / (n - 2) << endl;
	}
}

Measured memory_bytes: 3012
N = int(input())
for i in range(N):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    a = 2*(x1 - x2); b = 2*(y1 - y2); p = x1**2 - x2**2 + y1**2 - y2**2
    c = 2*(x1 - x3); d = 2*(y1 - y3); q = x1**2 - x3**2 + y1**2 - y3**2
    det = a*d - b*c
    x = d*p - b*q; y = a*q - c*p
    if det < 0:
        x = -x; y = -y; det = -det
    x /= det; y /= det
    r = ((x - x1)**2 + (y - y1)**2)**.5
    print("%.03f %.03f %.03f" % (x, y, r))



Measured memory_bytes: 5656
#include<bits/stdc++.h>
#define model l,mid,num<<1
#define moder mid+1,r,num<<1|1
#define bug(k)  cout<<"text :"<<t<<endl
#define lowbit(k) k&-k
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int M=1e5+5;
map <string,int> ma;
int n,x;
int arr[M];
int bits_gcd(int x,int y)
{
    if(y==0)return x;
    if(x==0)return y;
    int i,j;
    for(i=0;0==(x&1);i++)x>>=1;
    for(j=0;0==(y&1);j++)y>>=1;
    if(i>j)i=j;
    while(1)
    {
        if(x<y)x^=y,y^=x,x^=y;
        if(0==(x-=y))return y<<i;
        while(0==(x&1))x>>=1;
    }
}
int main()
{
     int ans;
     int t;
     while(cin>>n>>x)
     {
         ans=INT_MAX;
         for(int i=1;i<=n;++i)
         {
             scanf("%d",&t);
             if(t>x)t^=x,x^=t,t^=x;
             arr[i]=x-t;
         }
         int ans=arr[1];
         for(int i=2;i<=n;++i)
         {
//             cout<<ans<<" "<<arr[i]<<endl;
//             cout<<bits_gcd(ans,arr[i])<<endl;
             ans=bits_gcd(ans,arr[i]);
         }
         cout<<ans<<endl;
     }
}

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

int main() {
  int n;
  cin >> n;
  double total = 0;
  for(int i=0; i<n; i++) {
    double x;
    string y;
    cin >> x >> y;
    if(y == "JPY") total += x;
    else total += x*380000;
  }
  cout << fixed << setprecision(6) << total << endl;
  return 0;
}

Measured memory_bytes: 3704
N = int(input())
A = [list(map(lambda n: int(n)-1, input().split())) for i in range(N)]
cur = [0 for i in range(N)]
que = [i for i in range(N)]
ans = 0
while len(que) > 0:
    done = {}
    que2 = []
    for n in que:
        if done.get(n):
            continue
        pair = A[n][cur[n]]
        if done.get(pair):
            continue
        if n == A[pair][cur[pair]]:
            cur[n] += 1
            cur[pair] += 1
            done[n] = True
            done[pair] = True
            if cur[n] < N-1:
                que2.append(n)
            if cur[pair] < N-1:
                que2.append(pair)
    if len(done) > 0:
        ans += 1
    que = que2
ok = True
for i in range(N):
    if cur[i] < N-1:
        ok = False
if ok:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 35060
#include<stdio.h>
#include<string.h>
int main(){
char s[101];
 int n, i, m;

scanf("%s",s);
      n = 0;
    while (s[n]!= '\0'){
        n++;
    }
  m=n;
  n=(n-1)/2;
  for(i=0; i<m; i++){
        if(s[i]!=s[m-1-i]){
      printf("No\n");
      return 0;
    }
  }
    
  for(i=0; i<n; i++){
    if(s[i]!=s[n-1-i]){
      printf("No\n");
      return 0;
    }
  }
      printf("Yes\n");
      return 0;
  }

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
template<typename T> int LIS(vector<T> A)
{
    int n = A.size();
    vector<T> dp(n, INF);
    for(int i = 0; i < n; i++)
    {
        *lower_bound(dp.begin(), dp.end(), A[i]) = A[i];
    }
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    cout << LIS(A) << endl;
    return 0;
}




Measured memory_bytes: 4204
#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>;

int main() {
 int n, a, b;
  cin >> n >> a >> b;
  if ((n*a)<b) {
    cout << n*a << endl;
  }
  else {
    cout << b << endl;
  }
 return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n, k; cin>>n>>k;
    vi v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    sort(all(v));
    int ans = 0;
    for(i = 0; i < k; i++) ans += v[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
from sys import stdin
import numpy as np
N, Q=map(int,input().split())
S=input()
L =[list(map(int, stdin.readline().split())) for _ in range(Q)]
c = [0]*(N)  #ACのチェック
s = [0]*(N)  #ACの累積和
ans = [0]*Q 

for i in range(N-1):
  if S[i] == "A" and S[i+1] == "C":
    c[i+1] = 1
s = np.cumsum(c)
for i in range(Q):
  ans[i] = s[L[i][1]-1]-s[L[i][0]-1]

for i in ans:
  print(i)


Measured memory_bytes: 40324
'use strict'

const main = input => {
	const args = input.trim().split(' ')
	const L = parseInt(args[0], 10)
	const R = parseInt(args[1], 10)
	
	if (R - L >= 2018) {
		console.log(0)
	} else {
		let min = 2018
		const L2 = L % 2019
		const R2 = R % 2019

		for (let i = L2; i < R2; i++) {
			for (let j = i + 1; j <= R2; j++) {
				min = Math.min(min, (i * j) % 2019)
			}
		}

		console.log(min)
	}
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
import java.util.*;
import java.io.*;
public class Main extends PrintWriter {
    Main()
    {
        super(System.out);
    }
    public static void main(String args[]) {
      Main o=new Main();
      o.main();
      o.flush();
      o.close();
    }
    void main()
    {
        Scanner sc=new Scanner(System.in);
        long x=Math.abs(sc.nextLong());
        long k=sc.nextLong();
        long d=sc.nextLong();
        long rem=x%d;
        long quo=x/d;
        if(k<quo)
        {
            println(Math.abs(x-(k*d)));
        }
        else
        {
          		long v1=rem-d;
                long rem1=k-quo;
                if(rem1%2==0)
                println(Math.abs(rem));
                else
                println(Math.abs(v1));
         }
        sc.close();
    }
}


Measured memory_bytes: 35828
import sys

s=input()

if len(s)==1:
    print(0)
    sys.exit()

if len(s)%2==0:
    left = s[:len(s)//2]
    right = s[len(s)//2:][::-1]
else:
    left = s[:(len(s)-1)//2]
    right = s[(len(s)-1)//2+1:][::-1]

ans = 0
for i in range(len(left)):
    if left[i]!=right[i]:
        ans+=1
print(ans)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

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

  std::cin >> S;

  for(char &c : S){
      if(c == '?'){
          c = 'D';
      }
  }

  std::cout << S << std::endl;
}


Measured memory_bytes: 3780
N = int(input())
A = [int(i) for i in input().split()]
iA_i = [i+a for i,a in enumerate(A)]
jA_j = [i-a for i,a in enumerate(A)]
from collections import defaultdict as ddict
iA_i_dict = ddict(int)
jA_j_dict = ddict(int)

for iai in iA_i:
    iA_i_dict[iai] += 1
for jaj in jA_j:
    if jaj > 0:
        jA_j_dict[jaj] += 1
ans = 0
for i in iA_i_dict.keys():
    ans += iA_i_dict[i] * jA_j_dict[i]
print(ans)

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n; cin >> n;
  ll a;
  vector<ll> sum(2), cnt(2);
  for(int i=0; i<n; ++i) {
    cin >> a;
    for(int j : {0,1}) {
      sum[j] += a;
      int d = 1 - (i+j) % 2 * 2;
      if(sum[j]*d <= 0) {
        cnt[j] += abs(d-sum[j]);
        sum[j] = d;
      }
    }
  }
  cout << min(cnt[0],cnt[1]) << '\n';
  
  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3632
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function bsearch(a,x);l,r=1,length(a);while l<=r;m=l+div(r-l,2);if a[m]<x;l=m+1;else;r=m-1;end;end;return(l-1);end
function moveup(x::Array{Int,1},n)
	k = length(x)
	for i in 1:k-1
		if x[k-i+1] > n-1
			x[k-i] += div(x[k-i+1],n)
			x[k-i+1] = x[k-i+1]%n
		end
	end
	if x[1] > n-1
		0
	else
		x
	end
end

function main()
	n,k = readline() |> split |> parseMap
	a = readline() |> split |> parseMap
	s = zeros(Int,41)
	for i in 1:n
		t = zeros(Int,41)
		t[41] = a[i]
		s += moveup(t,2)
	end
	u = zeros(Int,41)
	for i in 1:41
		if s[i] > n/2
			u[i] = 0
		else
			u[i] = 1
		end
	end
	x = zeros(Int,41)
	x[41] = k
	x = moveup(x,2)
	ans = 0
	flg = 0
	for i in 1:41
		if flg == 1
			if u[i] == 1
				ans += (n-s[i])*2^(41-i)
			else
				ans += s[i]*2^(41-i)
			end
		else
			if u[i] < x[i]
				flg = 1
				ans += s[i]*2^(41-i)
			elseif u[i] == x[i] == 1
				ans += (n-s[i])*2^(41-i)
			else
				ans += s[i]*2^(41-i)
			end
		end
	end
	println(ans)
end
main()

Measured memory_bytes: 156732
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if a <= 8 and b <= 8:
        print("Yay!")
    else:
        print(":(")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
N = int(input())
chart = [[int(x) for x in input().split()] for _ in range(N)]
LL = []
for i in range(N):
    for j in range(i,N):
        LL.append(((chart[i][0]-chart[j][0])**2 + (chart[i][1]-chart[j][1])**2)**0.5)

def kaijo(N):
    ans = 1
    for i in range(1,N+1):
        ans = ans*i
    return ans

print(sum(LL)*2*kaijo(N-1)/kaijo(N))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(void){
    string S;
    cin>>S;
    int ans = 0;
    int red = 0,blue = 0;
    for (int i=0;i<S.size();i++){
        if (S[i]=='1') blue++;
        else red++;
    }
    cout<<S.size()-abs(red-blue)<<endl;
    return 0;
}

Measured memory_bytes: 512
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    char[] c = br.readLine().replaceAll(" ", "").toCharArray();
    char result = '>';
    if (c[0] < c[1]) result = '<';
    if (c[0] == c[1]) result = '=';
    System.out.println(result);
  }
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    ll sum = 0;
    for (int bit = 0; bit < (1 << n - 1); bit++)
    {
        string t = "";
        for (int i = 0; i < n; i++)
        {
            t += s[i];
            if (bit & (1 << i))
            {
                t += "+";
            }
        }

        t += "+";
        string num = "";
        rep(i, t.size())
        {
            if (t[i] == '+')
            {
                sum += stoll(num);
                num = "";
            }
            else
                num += t[i];
        }
    }

    OP(sum);
    return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(sc.next().equals("snuke")){
					System.out.println("" + s.charAt(j) + (i+1));
				}
			}
		}
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
     Scanner scan = new Scanner(System.in);
     int a = scan.nextInt();
     int b = scan.nextInt();
     int c = scan.nextInt();
     if( a < b && b < c){
    	 System.out.println("Yes");
     }else{
    	 System.out.println("No");
     }
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,sum = 0,t,i;
    cin>>n>>a;

    for(i = 0;i < a;i++)
    {
        cin>>b;
        sum+=b;
    }
    if(n-sum<0)
        cout<<-1<<endl;
    else
        cout<<n-sum<<endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	ll n, k;
	cin >> n >> k;
	if(n%k==0)	cout << 0 << "\n";
	else	cout << min(n%k, k-(n%k)) << "\n";
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

// dp[i+1][j]:=a[i]までの魔法を使った時,ダメージがj以上になるときの消費MPの最小値

const ll MAX_N = 1005;
const ll MAX_H = 10005;
const ll INF = 1000000000;
ll dp[MAX_N][MAX_H];
ll a[MAX_N],b[MAX_N];

int main(){
  ll h,n; cin >> h >> n;
  for(int i=0;i<n;i++) cin >> a[i] >> b[i];

  dp[0][0] = 0;
  for(int i=1;i<MAX_N;i++){
    dp[i][0] = 0;
  }
  for(int j=1;j<MAX_H;j++){
    dp[0][j] = INF;
  }
  for(int j=1;j<MAX_H;j++){
    if(j < a[0]){
      dp[1][j] = INF;
    }else{
      dp[1][j] = a[0];
    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<=h;j++){
      if(j < a[i]){
        dp[i+1][j] = min(b[i],dp[i][j]);
      }else{
        dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i]);
      }
    }
  }

  cout << dp[n][h] << endl;
  return 0;
}

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

int main() {
  double st, lt;
  while(cin >> st >> lt) {
    if(st < 35.50 && lt < 71.00) cout << "AAA" << endl;
    else if(st < 37.50 && lt < 77.00) cout << "AA" << endl;
    else if(st < 40.00 && lt < 83.00) cout << "A" << endl;
    else if(st < 43.00 && lt < 89.00) cout << "B" << endl;
    else if(st < 50.00 && lt < 105.00) cout << "C" << endl;
    else if(st < 55.00 && lt < 116.00) cout << "D" << endl;
    else if(st < 70.00 && lt < 148.00) cout << "E" << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 1224
import java.util.Arrays;
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int m = scanner.nextInt();
    int[] x = new int[m];
    for (int i = 0; i < m; i++) {
      x[i] = scanner.nextInt();
    }
    if (n >= m) {
      System.out.println(0);
      return;
    }
    Arrays.sort(x);
    int[] d = new int[m - 1];
    for (int i = 0; i < m - 1; i++) {
      d[i] = x[i + 1] - x[i];
    }
    Arrays.sort(d);
    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
      sum += d[d.length - i - 1];
    }
    System.out.println(x[m - 1] - x[0] - sum);
  }

}


Measured memory_bytes: 50168
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>

using namespace std;

int main()
{
    char aaa;
    int num;
        
    int arr[26] = {};

    while (scanf("%c", &aaa) != EOF) {
       // aaa = cin.get();

        aaa=tolower(aaa);

        num = aaa - 'a';

         arr[num] = arr[num] + 1;

    }

    for (int i = 0; i < 26; i++) {

        int numnum = i + 'a';
        char aa = numnum;

        cout << aa <<" : "<< arr[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
    int N, K; cin >> N >> K;
    vector<int> H(N, 0);
    ll ans=0;
    for(int i=0; i<N; i++) cin >> H[i];
    sort(H.rbegin(), H.rend());
    for(int i=K; i<N; i++){
        ans += H[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  x <- readLn
  when (x /= 0) $ do
    print $ sumDigits x
    main

sumDigits :: Integer -> Integer
sumDigits x
  | q == 0    = r
  | otherwise = r + sumDigits q
 where (q, r) = x `quotRem` 10



Measured memory_bytes: 4256
from collections import Counter
N, *A = map(int, open(0).read().split())
C = Counter(A)
C = [(k,v) for k,v in C.items() if v > 1]
if len(C) < 2:
  print(0)
else:
  C = sorted(C, key=lambda x:x[0])
  if C[-1][1] >= 4:
    print(C[-1][0]**2)
  else:
    print(C[-1][0]*C[-2][0])

Measured memory_bytes: 18528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

const int d=365;

int main(void){
	rep(i,d)cout<<i%26 + 1<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const ll INF = INT_MAX;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)


int main(){
        int a,b;
        cin >> a >>b;
        int ans = -1;
        for(int i=1;i<=10000;i++){
                        if(floor((double)(2*i)/25) == a && floor((double)(i)/10) == b){
                                                                                       ans = i;
                                                                                       break;
                }
        }
        cout << ans << endl;
        
        
        return 0;
}
                                        
                        


Measured memory_bytes: 256
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int x,y,k,ans=9;
int main(){
    in(x);
    int s=x,sum=0;
    while(s){
        s/=10;
        sum++;
    }
    if(sum==1){
        printf("%d\n",x);
        return 0;
    }
    for(int i=1;i<sum;i++)y=y*10+9;
    for(int i=3;i<sum;i+=2){
        int tot=1;
        for(int j=1;j<i;j++)tot*=10;
        tot*=9;
        ans+=tot;
    }
    if(sum%2==1)ans+=(x-y);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    i64 X;

    cin >> N >> X;
    vector<i64> a(N);

    rep(i, N) {
        cin >> a[i];
    }

    sort(all(a));

    int ans = 0;
    rep(i, N) {
        if (X >= a[i]) {
            X -= a[i];
            ++ans;
        }
    }

    if (X > 0 && ans == N) --ans;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
n = int(raw_input())
stack = deque()
for i in range(n):
	i = raw_input()
	if "insert" in i:
		stack.appendleft(int(i[7:]))
	elif "delete " in i:
		if int(i[7:]) in stack:
		    stack.remove(int(i[7:]))
	elif "deleteFirst" in i:
		stack.popleft()
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))

Measured memory_bytes: 102300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main() {
  vector<int> a(5);
  int k;
  REP(i, 5) { cin >> a.at(i); }
  cin >> k;
  bool Yay = true;
  REP(i, 5) {
    REP(j, 5) {
      if (abs(a.at(i) - a.at(j)) > k) {
        Yay = false;
      }
    }
  }
  if (Yay) {
    std::cout << "Yay!" << '\n';
  } else {
    std::cout << ":(" << '\n';
  }
}


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

using namespace std;

string a[200002];
int n,i,j,dem=1,max1=1;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin >> n;
    getline(cin,a[1]);
    fflush(stdin);
    n=stoi(a[1]);
    for (i=1;i<=n;i++)
    {
        getline(cin,a[i]);
        fflush(stdin);
    }
    sort(a+1,a+1+n);
    a[n+1]="!";
    for (i=2;i<=n+1;i++)
        if (a[i] == a[i-1]) dem++;
        else 
        {
            if (dem > max1) max1=dem;
            dem=1;
        }
    dem=1;
    for (i=2;i<=n+1;i++)
        if (a[i] == a[i-1]) dem++;
        else 
        {
            if (dem == max1) cout << a[i-1] << "\n";
            dem=1;
        }
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
int n,i,a[100005],s,v1,v2,dp[100005];
int main()
{
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  if(n==1)
  {
  	cout<<0;
  	return 0;
  }
  dp[0]=0;
  dp[1] = fabs(a[0]-a[1]);
  for(i=2;i<n;i++)
  {
  	v1 = dp[i-1] + fabs(a[i]-a[i-1]);
  	v2 = dp[i-2] + fabs(a[i]-a[i-2]);
  	dp[i] = min(v1,v2);
  }
  cout<<dp[n-1];
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
vector<int> exists;
int ans;
void dfs(int i, int N, vector<int>& v) {
  if(i == N) {
    int n = v.size();
    int mn = 24;
    rep(i, n) REP(j, i+1, n) {
      mn = min(min(abs(v[i]-v[j]), 24-abs(v[i]-v[j])), mn);
    }
    ans = max(mn, ans);
    return;
  } else {
    if(exists[i] > 2) {
      ans = 0;
      return;
    } else if(exists[i] > 1) {
      v.push_back(i);
      v.push_back((24-i)%24);
      dfs(i+1, N, v);
      v.pop_back();
      v.pop_back();
    } else if(exists[i]) {
      v.push_back(i);
      dfs(i+1, N, v);
      v.pop_back();
      v.push_back((24-i)%24);
      dfs(i+1, N, v);
      v.pop_back();
    } else {
      dfs(i+1, N, v);
    }
  }
}
int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  exists = vector<int>(13);
  exists[0] = 1;
  rep(i, N) {
    cin >> D[i];
    exists[D[i]]++;
  }
  vector<int> v;
  ans = 0;
  dfs(0, 13, v);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(auto i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

vll adj[200003]; ll visited[200003]; ll connected=0;

void dfs(ll v)
{
	visited[v]=1;connected++;
	ranit(it,adj[v])
	{
		if(visited[it]==0)dfs(it);
		else continue;
	}
	return;
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	ll n,m,u,v; cin>>n>>m;  ll ans=-1;
	forA(i,0,m,1) cin>>u>>v,adj[u].pb(v),adj[v].pb(u);
	//forA(i,1,n+1,1)	{cout<<i<<" : "; ranit(it,adj[i])cout<<it.F<<" "; cout<<"\n";}
	forA(i,1,n+1,1)
	{
		connected=0;
		if(visited[i]==0){dfs(i); ans=max(ans,connected);}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 22268
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  
  int b1;
  cin >> b1;
  int ans = 0;
  ans += b1;
  REP(i,n-1){
    int b2;
    cin >> b2;
    
    ans += min(b1,b2);
    
    b1 = b2;
  }

  
  cout << ans << endl;
  
}

Measured memory_bytes: 3600
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
i64 n, k, dp[302][302];
vector<i64> h;
int main() {
    cin >> n >> k;
    h.resize(n + 2);
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    for (int i = 1; i <= n + 1; ++i) {
        for (int j = 0; j <= k; ++j) {
            dp[i][j] = 1e18;
        }
    }
    for (i64 i = 1; i <= n + 1; ++i) {
        for (i64 j = 0; j <= k && i - j - 1 >= 0; ++j) {
            for (i64 l = 0; j + l <= k; ++l) {
                dp[i][j + l] = min(
                    dp[i][j + l],
                    dp[i - j - 1][l] + max(i64(0), h[i] - h[i - j - 1])
                );
            }
        }
    }
    i64 ans = 1e18;
    for (i64 j = 0; j <= k; ++j) ans = min(ans, dp[n + 1][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
const long long MAX = 1000000000;

int main(){
    long long n, k;
    cin>>n>>k;
    for (long long i=1;i<=MAX;i++){
        if (pow(k, i) > n){
            cout << i << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli data[2][110];

signed main(){

	lli n;
	cin>>n;

	REP(i,0,2){
		REP(j,0,n){
			cin>>data[i][j];
		}
	}

	lli sum=0;
	sum += data[0][0];
	REP(i,0,n)sum+=data[1][i];

	lli ans = sum;

	REP(i,1,n){
		sum += data[0][i];
		sum -= data[1][i-1];
		ans = max(sum,ans);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    while(true){
        int N,M;
        cin >> N >> M;
        if(N == 0 and M == 0) break;

        vector<int> ps;
        ps.push_back(0);
        for(int i=0;i<N;i++){
            int p;cin >> p;
            ps.push_back(p);
        }
        vector<int> d;
        for(size_t i=0;i<ps.size();i++){
            for(size_t j=i;j<ps.size();j++){
                d.push_back(ps[i]+ps[j]);
            }
        }
        sort(d.begin(),d.end());
        int ret = 0;
        for(size_t i=0;i<d.size();i++){
            if(d[i] > M) break;
            ret = max(ret,d[i]+*(lower_bound(d.begin(),d.end(),M-d[i])-1));
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 5040
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 16 Feb 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        int n = Integer.parseInt(temp);

        temp = br.readLine();
        st = new StringTokenizer(temp, " ");
        int[] a = new int[n];
        int j = 0;
        boolean ans = true;
        while (st.hasMoreTokens() && ans) {
            a[j] = Integer.parseInt(st.nextToken());
            if (a[j] % 2 == 0) {
                if (a[j] % 3 != 0 && a[j] % 5 != 0) ans = false;
            }
        }
        br.close();
        System.out.println(ans ? "APPROVED":"DENIED");
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include <vector>

using namespace std;

int main(){

	string in;
	int len;

	while(getline(cin,in)){
		if(in=="END OF INPUT"){
			break;
		}
		len=0;
		for(int i=0;i<in.length();i++){
			if(in[i]==' '){
				cout<<len;
				len=0;
			}
			else{
				len++;
			}
		}
		cout<<len<<endl;
	}

}

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

int main() {
    int h, w,i,j;
    cin >> h >> w;
    char m[52][52];
    for (i = 1; i <= h; i++) {
        for (j = 1; j <= w; j++) {
            cin >> m[i][j];
        }
    }
    for (i = 1; i <= h; i++) {
        for (j = 1; j <= w; j++) {
            if (m[i][j] == '#') {
                if (m[i - 1][j - 1] >= '.')m[i - 1][j - 1]++;
                if (m[i - 1][j] >= '.')m[i - 1][j]++;
                if (m[i - 1][j + 1] >= '.')m[i - 1][j + 1]++;
                if (m[i][j - 1] >= '.')m[i][j - 1]++;
                if (m[i][j + 1] >= '.')m[i][j + 1]++;
                if (m[i+1][j - 1] >= '.')m[i+1][j - 1]++;
                if (m[i + 1][j] >= '.')m[i + 1][j]++;
                if (m[i + 1][j + 1] >= '.')m[i + 1][j + 1]++;
            }
        }
    }

    for (i = 1; i <= h; i++) {
        for (j = 1; j <= w; j++) {
            if (m[i][j] >= '.')cout << int(m[i][j] - '.');
            else cout << m[i][j];
        }
        cout << endl;
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    char s[20],t[20];
    scanf("%s %s",s,t);
    int i=0,cnt=0;
    while(t[i]){
        if(s[i]==t[i]){
            cnt++;
        }
        i++;
    }
    if(i-cnt==1){
        printf("Yes\n");
    }else{
    printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(void)
{
    int w, h;
    int i, j;
    while (1)
    {
        scanf("%d %d", &w, &h);
        if (w == 0 && h == 0)
        {
            break;
        }
        for (i = 1; i <= w; i++)
        {
            for (j = 1; j <= h; j++)
            {
                if (i % 2 == 1)
                {
                    if (j % 2 == 0)
                    {
                        printf(".");
                    }
                    else if (j % 2 == 1)
                    {
                        printf("#");
                    }
                }
                else
                {
                    if (j % 2 == 0)
                    {
                        printf("#");
                    }
                    else if (j % 2 == 1)
                    {
                        printf(".");
                    }
                }
            }
            printf("\n");

            if (i == w)
            {
                printf("\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <string>
#define FOR(i,k,n) for (int (i)=(k);(i)<(n);(i)++)
using namespace std;

int main()
{
  int N;
  long int x = 1;
  int q = 1e9 + 7;
  cin >> N;

  FOR(i,0,N) {
    x *= (i + 1);
    x %= q;
  }

  cout << x << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define MP make_pair
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

LL big_mod(LL n, LL p)
{
    if(p==0) return 1;
    if(!(p&1))
    {
        LL r = big_mod(n,p/2) % MOD;
        return ( (r%MOD) * (r%MOD) ) % MOD;
    }
    else return ( ( n%MOD) * (big_mod(n,p-1) %MOD)) % MOD;
}
long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,k,ar[1001];
    while(cin>>n>>k)
    {
        rep(i,0,n) cin>>ar[i];
        sort(ar,ar+n);
        int sum=0;
        for(int i=n-1,j=0;j<k;i--,j++) sum+=ar[i];
        cout<<sum<<endl;
    }

}



Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int,input().split()))
a = []
for i in range(n):
    a.append(list(map(int, input().split())))
ans = 0
for i in range(n):
    val = c
    for j in range(m):
        val += (a[i][j] * b[j])
    if val > 0:
        ans += 1
print(ans)

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

int main() {
  int x, y;
  while(true) {
    scanf("%d %d", &x, &y);
    if(x == 0 && y == 0) break;
    if(x <= y) printf("%d %d\n", x, y);
    else printf("%d %d\n", y, x);
  }
}


Measured memory_bytes: 3212