akhauriyash/Code-Regression huggingface dataset:
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
struct Integer{
public:
    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;}

    bool isPrime(ll x){
        if(x < 2) return false;
        if(x == 2) return true;
        if(x % 2 == 0) return false;
        for(ll i = 3;i <= sqrt(x) + 1;i += 2) if(x % i == 0) return false;
        return true;
    }

    vector<ll> divisor(ll M){
        vector<ll> dd;
        for(ll i = 1; i * i <= M; i++){
            if(M % i == 0){
                dd.push_back(i);
                if(i * i != M) dd.push_back(M / i);
            }
        }
        sort(dd.begin(), dd.end());
        return dd;
    }

    vector<ll> factor(ll M){ //素因数分解
        vector<ll> dd;
        if(M == 1){
            dd.push_back(1);
            return dd;
        }
        for(ll i = 2; i*i <= M; i++){
            while(M % i == 0){
                dd.push_back(i);
                M /= i;
            }
        }
        if(M != 1) dd.push_back(M);
        sort(dd.begin(), dd.end());
        return dd;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    Integer it;
    vector<ll> dd = it.divisor(N);
    vector<ll> dd2 = it.divisor(N-1);
    // vector<ll> dd3 = it.factor(N);
    
    map<ll,ll> mp;
    for(auto &e: dd2){
        if(e != 1) mp[e]++;
    }
    for(auto &e: dd){
        if(e == 1) continue;
        ll v = N;
        while(v % e == 0) v /= e;
        // ll v = N / e;
        if(v % e == 1) mp[e]++;
    }
    mp[N]++;
    ll ans = mp.size();
    print(ans);



    

}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        String b = sc.next();
        System.out.println(a < 3200 ? "red" : b);


    }

}


Measured memory_bytes: 22740
n=int(input())
if n&1:
	print((n*(n-2)//2)+1)
	for i in range(1,n):
		for j in range(i+1,n+1):
			if j+i!=n:
				print(i,j)

	
else:
	print(n*(n-2)//2)
	for i in range(1,n):
		for j in range(i+1,n+1):
			if j+i!=n+1:
				print(i,j)


Measured memory_bytes: 44656
#include <iostream>
#include <algorithm>
#include <vector>
//#include <queue>

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

using namespace std;

typedef long long ll;

const long long int INF = 1 << 30; //10^10
const ll MOD = 998244353;

inline void maxch(int& a, int b) { if (a < b) a = b; }



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

	cout << r*r << endl;
}

Measured memory_bytes: 256
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

struct node_t {
    map<char, node_t*> go;
    array<int, 27> marks;
    bool is_term = false;
};

void traverse(node_t* v, int64_t& ans) {
    array<int, 26> sum;
    std::fill(ALL(sum), 0);
    
    for (auto& el: v->go) {
        for (int j = 0; j < 26; ++j)
            sum[j] += el.second->marks[j];
    }
    
    for (auto& el: v->go) {
        traverse(el.second, ans);

        if (el.second->is_term)
            ans += sum[el.first - 'a'] - el.second->marks[el.first - 'a'];
    }

    if (v->is_term) {
        ans += v->marks[26] - 1;
    }
}

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

    // code here
    node_t* root = new node_t();

    int n = input<int>();
    int64_t ans = 0;

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        reverse(ALL(s));

        vector<node_t*> seq = {root};
        
        node_t* cur = root;
        for (char ch: s) {
            if (not cur->go[ch])
                cur->go[ch] = new node_t();

            cur = cur->go[ch];
            seq.push_back(cur);
        }

        cur->is_term = 1;
        cur->marks[26] += 1;

        int markset = 1 << 26;
        for (int i = SZ(s) - 1; i >= 0; --i) {
            markset |= (1 << (s[i] - 'a'));

            for (int j = 0; j <= 26; ++j)
                if (markset & (1 << j))
                    seq[i]->marks[j] += 1;
        }
    }

    traverse(root, ans);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 417252
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    int N;
    cin >> N;
    map<string, ll> s;
    Rep (i, N) {
        string S;
        cin >> S;
        sort(S.begin(), S.end());
        s[S]++;
    }

    ll ans = 0;
    for (auto e : s) {
        // cout << e.first << " " << e.second << "\n";
        ans += e.second * (e.second-1) / 2;
    }

    cout << ans << endl;
}

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

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

using namespace std;

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


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

int dx[8] = {1,1,0,-1,-1,-1,0,1}, dy[8] = {0,1,1,1,0,-1,-1,-1};

int main() {
  ll N,K; cin >> N >> K;
  ll ans = 0;
  rep(i,N){
    ll x; cin >> x;
    ans += min(2*x,2*(abs(K-x)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[100010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int mx=0;
	int cnt=0;
	for(int i=0;i<n-1;i++){
		if(a[i]>=a[i+1]){
			cnt++;
		}
		else cnt=0;
		mx=max(mx,cnt);
	}
	cout<<mx<<endl;
	return 0;
}

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

int main(void){
    ll n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 0;
    ll r = 2;
    rep(i,200){
        if (r*5LL > n) break;
        r *= 5LL;
        res += n/r;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

int n, a, ans;

int main() {
	fastio; cin >> n;
	FOR(i, 1, n) {
		cin >> a;
		if (a % 2 and i % 2) ans++;
	}
	cout << ans;
}


Measured memory_bytes: 3612
#include <iostream>
using namespace std;
long long MOD=1e9+7;

int main(){
  int h,w,i,j,k;
  cin >> h >> w;
  string g[h];
  for(i=0;i<h;i++)cin >> g[i];
  long long dp[h][w];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++)dp[i][j]=0;
  }
  for(i=0;i<h;i++){
    if(g[i][0]=='#')break;
    dp[i][0]=1;
  }
  for(i=0;i<w;i++){
    if(g[0][i]=='#')break;
    dp[0][i]=1;
  }
  for(i=1;i<h;i++){
    for(j=1;j<w;j++){
      if(g[i][j]=='#')continue;
      else{
        if(g[i-1][j]!='#')dp[i][j]+=dp[i-1][j];
        dp[i][j]%=MOD;
        if(g[i][j-1]!='#')dp[i][j]+=dp[i][j-1];
        dp[i][j]%=MOD;
      }
    }
  }
  cout << dp[h-1][w-1] << endl;
  return 0;
}

Measured memory_bytes: 9088
s = input()
t = input()

s = sorted(s)
t = sorted(t, reverse=True)

flag = 0

for i in range(max(len(s), len(t))):
    if len(t) - 1  < i and flag == 1:
        print("No")
        exit()
    elif len(s) - 1 < i and flag == 1:
        print("Yes")
        exit()
        
    if s[i] < t[i]:
        print("Yes")
        exit()
    elif s[i] == t[i]:
        flag = 1
        continue
    else:
        print("No")
        exit()

print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include <string.h>
int main() {
    int a,b,c,d,e;
char s[10];
    scanf("%s",s);

    if((s[3]==s[2])&&(s[5]==s[4])){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;


}

Measured memory_bytes: 1616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n;
    cin >> n;
    vector<ll> x(n), y(n), p(n);
    REP(i, n){
        cin >> x[i] >> y[i] >> p[i];
    }

    vector<vector<ll>> x2d(1LL << n, vector<ll>(n)), y2d(1LL << n, vector<ll>(n));
    REP(i, (1LL << n)){
        REP(j, n){
            ll dx = abs(x.at(j)), dy = abs(y.at(j));
            REP(k, n){
                if((i >> k) & 1){
                    dx = min(dx, abs(x.at(j) - x.at(k)));
                    dy = min(dy, abs(y.at(j) - y.at(k)));
                }
            }
            x2d.at(i).at(j) = dx;
            y2d.at(i).at(j) = dy;
        }
    }

    ll ub = 1;
    REP(i, n){ ub *= 3; }

    vector<ll> ans(n + 1, numeric_limits<ll>::max());

    REP(i, ub){
        ll ix = 0, iy = 0, k = 0;
        {
            ll m = i;
            REP(j, n){
                const ll l = m % 3;
                if(l == 1){
                    ix += (1LL << j);
                    k++;
                }else if(l == 2){
                    iy += (1LL << j);
                    k++;
                }
                m /= 3;
            }
        }

        ll s = 0;
        const auto& dx = x2d.at(ix), dy = y2d.at(iy);
        REP(j, n){
            ll d = min(dx.at(j), dy.at(j));
            s += p.at(j) * d;
        }

        ans.at(k) = min(ans.at(k), s);
    }

    for(auto ai : ans){
        cout << ai << endl;
    }
    return 0;
}


Measured memory_bytes: 13008
#include <iostream>
#include <time.h>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

/*int msum(int n)
{
    int sum;
    if(n==1){
        return 1;
    }
    else{
        sum = n + msum(n-1);
    }
    return sum;
}*/

/*long long fastPower(long long base, long long power) {
    long long result = 1;
    while (power > 0) {
        if (power & 1) {//此处等价于if(power%2==1)
            result = result * base % 1000;
        }
        power >>= 1;//此处等价于power=power/2
        base = (base * base) % 1000;
    }
    return result;
}*/

/*long long fastpower(long long base,long long power)
{
    long long result = 1;
    if(power==1){
        return base;
    }
    if(!(power & 1)){
        result = (fastpower(base,power/2)%1000*fastpower(base,power/2)%1000)%1000;
    }
    else{
        result = (fastpower(base,power/2)%1000*fastpower(base,power/2)%1000*fastpower(base,1)%1000)%1000;
    }
    return result;
}

int main()
{
   clock_t start, finish;
    //clock_t为CPU时钟计时单元数
    long long base, power;
    cin >> base >> power;
    start = clock();
    //clock()函数返回此时CPU时钟计时单元数
    cout << fastpower(base, power) << endl;
    finish = clock();
    //clock()函数返回此时CPU时钟计时单元数
    cout << "the time cost is " << double(finish - start) / CLOCKS_PER_SEC;
    //finish与start的差值即为程序运行花费的CPU时钟单元数量，再除每秒CPU有多少个时钟单元，即为程序耗时
    return 0;
}*/


/**
 * 普通的求幂函数
 * @param base 底数
 * @param power  指数
 * @return  求幂结果的最后3位数表示的整数
 */
/*long long normalPower(long long base, long long power) {
    long long result = 1;
    for (int i = 1; i <= power; i++) {
        result = result * base;
        result = result % 1000;
    }
    return result % 1000;
}

int main() {
    clock_t start, finish;
    //clock_t为CPU时钟计时单元数
    long long base, power;
    cin >> base >> power;
    start = clock();
    //clock()函数返回此时CPU时钟计时单元数
    cout << normalPower(base, power) << endl;
    finish = clock();
    //clock()函数返回此时CPU时钟计时单元数
    cout << "the time cost is " << double(finish - start) / CLOCKS_PER_SEC;
    //finish与start的差值即为程序运行花费的CPU时钟单元数量，再除每秒CPU有多少个时钟单元，即为程序耗时
    return 0;

}*/

int main()
{
    int N, K;
    cin >>N >>K;
    vector<int> pric(N);
    for(int i=0;i<N;i++){
        cin >>pric[i];
    }
    sort(pric.begin(),pric.end());
    int sum=0;
    for(int i=0;i<K;i++){
        sum+=pric[i];
    }
    cout <<sum<<endl;
    return 0;
}


Measured memory_bytes: 3168
from fractions import *
N = int(input())
A = list(map(int, input().split()))

X1 = [0] * (N+2)
X2 = [0] * (N+2)

for i in range(N):
    X1[i+1] = gcd(X1[i], A[i])
for i in range(N,0,-1):
    X2[i] = gcd(X2[i+1], A[i-1])

ans = 1
for i in range(N):
    G = gcd(X1[i], X2[i+2])
    if ans < G:
        ans = G
print(ans)


Measured memory_bytes: 16152
A, B, H, M = map(int, input().split())

import math
P_a = H * 30 + M * 0.5
P_b = M *6

kakudo = P_a - P_b
if kakudo < 0:
    kakudo *= -1
elif kakudo == 0:
    print(abs(A - B))
    exit()
elif kakudo == 180:
    print(A + B)
    exit()

if kakudo > 180:
    kakudo = 360 - kakudo

kyori_sq = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(kakudo))
print(math.sqrt(kyori_sq))


Measured memory_bytes: 9516
/*
AizuOnline A2350
Title A - B problem
*/
#include <stdio.h>
int A,B,K;
char borrow_flag[9];
//
int pow_10(int x)
{
        if(x<=0)
                return(1);
        else
                return(10*pow_10(x-1));
}

main()
{
        int i,j,mask,diff;

        scanf("%d %d %d",&A,&B,&K);
        for(i=1,mask=10;i<=8;i++,mask*=10)
        {
                if((A % mask) < (B % mask))
                        borrow_flag[i]=-1;
                else
                        borrow_flag[i]=0;
        }
        for(i=1,mask=10;i<=7;i++,mask*=10)
        {
                if(((A % (mask*10))/mask==(B % (mask*10))/mask) 
                   && borrow_flag[i+1]==-1) 
                        borrow_flag[i]=0;
        }
        diff=0;
        for(j=K,i=8;i>=1 && j>0 ;i--)
        {
                //printf("i,bf:%d %d\n",i,borrow_flag[i]);
                if(borrow_flag[i])
                {
                        diff += pow_10(i);
                        j--;
                }
        }
        printf("%d\n",A-B+diff);
        return(0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,j,ans=0;
  string a,b;
  cin>>n>>a>>b;
  ans=n*2;
  for(i=0;i<n;i++){
    bool f=true;
    for(j=0;i+j<n;j++){
      if(a[i+j]!=b[j]) f=false;
    }
    if(f) ans=min(ans,n+i);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
n = int(input())
A = list(map(int,input().split()))
L=[]
for i in range(n):
    L.append(A[i]-(i+1))
L.sort()
#print(L)
if n==1:
    b1=L[0]
    b2=L[0]
elif n==2:
    b1=L[0]
    b2=L[1]
else:
    b1=L[n//2]
    b2=L[n//2-1]
ans=0
cnt1=0
cnt2=0
for i in range(n):
    cnt1+=abs(L[i]-b1)
    cnt2+=abs(L[i]-b2)
print(min(cnt1,cnt2))

Measured memory_bytes: 107844
using System;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            //??¶??°??\????????¢
            String[] ss = Console.ReadLine().Split(' ');
            int n = int.Parse(ss[0]);
            //??£?¨?
            int b;
            int f;
            int r;
            int v;
            //??????
            int[,,] a = new int[4 , 3 , 10];
            //??¶??°?????°?????????
            for (int kennsuu = 0; kennsuu < n; kennsuu++)
            {
                //??\????????¢
                String[] input = Console.ReadLine().Split(' ');
                 b = int.Parse(input[0]);
                 f = int.Parse(input[1]);
                 r = int.Parse(input[2]);
                 v = int.Parse(input[3]);
                a[b - 1, f - 1, r - 1] += v;
            }
                //0?????????
                //?£??????°?????????
                for (int tou = 0; tou < 4; tou++)
                {
                    //????????°?????????
                    for(int kai = 0; kai < 3; kai++)
                    {
                        //????????°?????°?????????
                        for(int ban = 0; ban < 10; ban++)
                        {
                            Console.Write(" {0}",a [ tou, kai, ban ]);
                        }
                    Console.Write("\n");
                    }
                if (tou < 3)
                {
                    Console.WriteLine("####################");
                }
            }

        }
    }       
}

Measured memory_bytes: 9036
<?php
$w = trim(fgets(STDIN)); 
$t = array();
$cnt = 0;
$W =  strtolower($w);
while (!feof(STDIN)) {
    $t = trim(fgets(STDIN));
    foreach((array)explode(" ", strtolower($t)) as $word){
  if ($word == $W){
        $cnt++;
      }
    }
}
echo $cnt.PHP_EOL;
?>


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

int main() {
	int n;
	cin >> n;
	Vi a(n);
	rep (i, n) {
		cin >> a.at(i);
	}
	int s = 0;
	rep (i, n) {
		s  ^= a[i];
	}
	rep (i, n) {
		a[i] ^= s;
	}
	rep (i, n) {
		cout << a[i] << "\n";
	}
	return 0;
}


Measured memory_bytes: 3976
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int a, int b, int t) {
    int x = t / a;
    return x * b;
}

void main() {
    auto xs = readints;
    int a = xs[0];
    int b = xs[1];
    int t = xs[2];
    writeln(calc(a, b, t));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int mpow(int x, int n) {
	int res = 1;
	while (n) {
		if (n & 1) res = 1LL * res * x % MOD;
		x = 1LL * x * x % MOD;
		n >>= 1;
	}
	return res;
}
const int N = 1e6;
int f[N + 5], r[N + 5];
int C(int n, int m) {
	if (m < 0 || m > n) return 0;
	return 1LL * f[n] * r[n - m] % MOD * r[m] % MOD;
}
int count(int R, int B, int T) {
	if (T >= 0) return 0;
	return (MOD + C(R + B, B) - C(R + B, B + T)) % MOD;
}
int main() {
	f[0] = 1;
	for (int i = 1; i <= N; ++ i) f[i] = 1LL * i * f[i - 1] % MOD;
	r[N] = mpow(f[N], MOD - 2);
	for (int i = N - 1; i >= 0; -- i) r[i] = 1LL * r[i + 1] * (i + 1) % MOD;
	int n, k, ans = 0;
	scanf("%d%d", &n, &k);
	for (int B = 0; B <= k - B; ++ B) {
		int R = k - B;
		if (R == B) {
			(ans += count(R, B - 1, n - R - 1)) %= MOD;
		}
		else if (R - B < n) {
			(ans += count(R, B, n - R - 1)) %= MOD;
		}
		else {
			(ans += C(R + B, R)) %= MOD;
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 8064
#include <stdio.h>

int main()
{
	char	S[6];
	scanf("%s",&S);
	if (S[0] != S[2] && S[0] != S[4] && S[0] != S[3] &&  S[0] != S[5] && S[0] != S[1])
	{
		if (S[1] != S[2] && S[1] != S[4] && S[1] != S[3] && S[1] != S[5])
		{
			if (S[2] == S[3] && S[4] == S[5])
			{
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	LL n;
	cin >> n;
	LL a[50];
	multiset<LL> b;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]++;
		b.insert(-a[i]);
	}
	LL c = 0;
	LL num = 0;
	while((-*b.begin()) - c >= (n+1)){
		LL k = -*b.begin();
		b.erase(b.begin());
		LL r = (k-c) / (n+1);
		c -= r;
		k -= r*(n+1);
		num += r;
		//cout << r << endl;
		b.insert(-k);
	}
	cout << num << endl;
}


Measured memory_bytes: 256
def check_palindrome(check_string):
  return check_string == check_string[::-1]
instring = input()
N = len(instring)
first_half = instring[:(N-1)//2]
second_half = instring[(N+3)//2-1:]
if check_palindrome(instring) and check_palindrome(first_half) and check_palindrome(second_half):
  print("Yes")
else:
  print("No")

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

int main()
{
        vector<ll> s(3, 0);
        cin >> s[0] >> s[1] >> s[2];
        sort(s.begin(), s.end());
        cout << s[0] + s[1] << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	ll h; cin >> h;
	vector<ll> A(n), B(n);
	rep(i,n){cin >> A[i]; cin >> B[i];}
	ll a = max(A);
	sort(B.rbegin(), B.rend());
	ll ans = 0;
	for(ll b:B){
		if(b < a){
			break;
		}
		if(h <= 0){
			cout << ans << endl;
			return 0;
		}
		ans++;
		h-=b;
	}
	cout << ans + (ll)ceil(h/(double)a) << endl;
}


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

const int N = 1e5 + 5;

int n;
pair<int, int> a[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);

	cin >> n;

	for(int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}

	sort(a, a + n);

	int ans = 0;
	for(int i = 0; i < n; i += 2) {
		ans += a[i].second & 1;
	}

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

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n-1,-1)
#define ALL(obj) (obj).begin(), (obj).end()

int main() {
	ll n, d, a, x ,h;
	cin >> n >> d >> a;
	vector<pll> v;
	vll vv;
	REP(i, n) {
		cin >> x >> h;
		v.push_back(pll(x, (h+a-1)/a)); //round up
		vv.push_back(x);
	}
	sort(ALL(v));
	sort(ALL(vv));
	map<ll, ll> mp; // border of attack area : damage
	ll res = 0;
	ll dmg = 0;
	REP(i,n){
		if (mp.count(i)) dmg -= mp[i];
		if (v[i].second - dmg > 0) {
			res += v[i].second - dmg;
			ll index = upper_bound(ALL(vv), v[i].first + d * 2) - vv.begin();
			if(!mp.count(index)) mp[index] = v[i].second-dmg;
			else mp[index] += v[i].second-dmg;
			dmg += v[i].second - dmg;
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 17388
//#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cstring>
#include <memory.h>
#include <cassert>

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long 
#define pii pair <int, int>
#define ld double

using namespace std;

int main() {
	string s;

	cin >> s;

	ll ans = 0;

	int l = 0;
	int x = 0;

	int n = (int)s.size();

	while (l <= n) {
		int r = l;

		while (r < n && s[r] == '>') {
			r++;
		}

		x = max(x, r - l);
		ans += x;

		//cout << x << ' ';

		if (l != r) {
			x = r - l;
		}

		for (int i = l + 1; i <= r; i++) {
			x--;
			ans += x;
			//cout << x << ' ';
		}

		x++;
		l = r + 1;
	}

	//cout << endl;

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 900
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
ans=[]
for i in product([0,1],repeat=3):
    sm=[0 for i in range(n)]
    for j in range(n):
        for k in range(3):
            if i[k]==0:
                sm[j]+=lis[j][k]
            else:
                sm[j]-=lis[j][k]
    ans.append(sum(sorted(sm,reverse=True)[:m]))
print(max(ans))
    



    

Measured memory_bytes: 74852
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x=0;string s;cin>>s;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'){
      int j=0;
      while(i+j<s.size()&&(s.at(i+j)=='A'||s.at(i+j)=='C'||s.at(i+j)=='G'||s.at(i+j)=='T'))j++;
      x=max(x,j);i+=j;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 10e9
int main(void){
	int N;
		cin >> N;
	int xmin=INF,xmax=0;
	for(int i=0;i<N;i++){
		int a;	cin >> a;
		xmin=min(xmin,a);
		xmax=max(xmax,a);
	}
	cout << xmax-xmin << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int m;
	cin>>m;
	while(m-->0){
		string s;
		string ans;
		pair<int,int> p;
		cin>>s;
		p.first=0;
		p.second=0;

		for(unsigned int i=0; i<s.length();++i){
			if(s[i]=='0'){
				if(p.second<=0)continue;
				switch(p.first){
					case 1:
						ans+=".,!? "[(p.second-1)%5];
						break;
					case 2:
						ans+="abc"[(p.second-1)%3];
						break;
					case 3:
						ans+="def"[(p.second-1)%3];
						break;
					case 4:
						ans+="ghi"[(p.second-1)%3];
						break;
					case 5:
						ans+="jkl"[(p.second-1)%3];
						break;
					case 6:
						ans+="mno"[(p.second-1)%3];
						break;
					case 7:
						ans+="pqrs"[(p.second-1)%4];
						break;
					case 8:
						ans+="tuv"[(p.second-1)%3];
						break;
					case 9:
						ans+="wxyz"[(p.second-1)%4];
						break;
				}
				p.first=-1;
				p.second=-1;
			}
			p.first=s[i]-'0';
			p.second++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int a, b;

int main(){
  cin>>a>>b;
  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

struct Edge{ int to; int dist; };

int N;
vector<vector<Edge>> G;
vector<int> V;
vector<bool> check;

inline int input() {
  cin >> N;
  G.resize(N);
  V.resize(N);
  check.resize(N);
  int u, v, w;
  rep(i, N-1) {
    cin >> u >> v >> w;
    u--;v--;
    G.at(u).emplace_back(Edge{v, w});
    G.at(v).emplace_back(Edge{u, w});
  }
  rep(i, N) {
    V.at(i) = 0;
    check.at(i) = false;
  }
  return u;
}

void dfs(int parent, int color) {
  V.at(parent) = color;
  check.at(parent) = true;

  for(Edge target : G.at(parent)) {
    if(check.at(target.to)) continue;

    int c = color;
    if(target.dist % 2 == 1) c *= -1;

    dfs(target.to, c);
  }
}

inline void result() {
  rep(i, N) {
    cout << (V.at(i) == -1 ? 0 : 1) << endl;
  }
}

inline void Main() {
  // code
  dfs(input(), 1);
  result();
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 10240
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    N=N%10;
    if(N==2 || N==4 || N==5 || N==7 || N==9) cout << "hon" <<endl;
    else if(N==0 || N==1 || N==6 || N==8) cout << "pon" << endl;
    else cout << "bon" << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include<algorithm>
#include<vector>
#define MAX 100000
using namespace std;

int main()
{
    int m,n,k;
   // vector<int> data;
    vector<int> x;
    vector<int> sum;
    int dis[MAX]={0};
    cin>>m;
    sum.resize(m,0);
   // data.resize(m);
    for(int i=0;i<m;i++)
    {
        //sum=0;
        cin>>n>>k;
        x.resize(n,0);
      
        for(int j=0;j<n;j++)
        {
            cin>>x[j];
            if(j>0)
                dis[j-1]=x[j]-x[j-1];
        }
        sort(dis,dis+n-1);
        //int sum=0;
        for(int p=0;p<n-k;p++)
        {
            sum[i]+=dis[p];
        }
       // cout<<sum<<endl;
    }
    for(int i=0;i<m;i++)
        cout<<sum[i]<<endl;
    return 0;
}



Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;
int l[200009],r[200009];

int main(){
  int n;
  int a[200009];
  cin>>n;
  rep(i,n){
    cin>>a[i];
  }
  for(int i=1;i<=n;i++){
    l[i]=max(l[i-1],a[i-1]);
  }
  for(int i=n;i>0;i--){
    r[i]=max(r[i+1],a[i-1]);
  }
  for(int i=1;i<=n;i++){
    cout<<max(l[i-1],r[i+1])<<endl;
  }
  return(0);
}
    



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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  int f=0;
  if(s[a]=='-'){
    f=1;
  }else{
    cout<<"No";
    return 0;
  }
  for(int i=0;i<a;i++){
    if(s[i]>=48 && s[i]<=57){
      f=1;
    }else{
      f=0;
      cout<<"No";
      return 0;
    }
  }
  for(int i=a+1;i<a+b+1;i++){
    if(s[i]>=48 && s[i]<=57){
      f=1;
    }else{
      cout<<"No";
      return 0;
    }
  }
  if(f){
    cout<<"Yes";
  }


}



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


ll N;
ll a[100001];

int main()
{	
  	cin.tie(0);
  	ios::sync_with_stdio(false);
  
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    
    ll h1 = 0, h2 = 0;
    ll i = N-1;
    while(!h1 && i > 0){
        if(a[i] == a[i - 1]){
            h1 = a[i];
            i--;
        }
        i--;
    }
    while(!h2 && i > 0){
        if(a[i] == a[i - 1]){
            h2 = a[i];
        }
        i--;
    }

    cout << h1 * h2 << '\n';

    return 0;
    
}


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

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

  vector<int> d(N);

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

  std::sort(d.begin(), d.end(), std::greater<int>());

  int count = 1, ud = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) ud = d[i];
    if (ud > d[i]) {
      count++;
      ud = d[i];
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        bool isFirst = true;
        int[] coins = new int[] { 10, 50, 100, 500 };
        int range = 4;
        int bill, ownedMoney, changeMoney;
        int[] ownedCoins = new int[range], changeCoins = new int[range], paymentCoins = new int[range];

        while (true)
        {
            bill = int.Parse(Console.ReadLine());
            if (bill == 0) break;
            if (isFirst) { isFirst = false; } else { Console.WriteLine(); }
            ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            ownedMoney = 0;
            for (int i = range - 1; i >= 0; i--)
                ownedMoney += coins[i] * ownedCoins[i];

            changeMoney = ownedMoney - bill;

            for (int i = range - 1; i >= 0; i--)
            {
                changeCoins[i] = changeMoney / coins[i];
                changeMoney = changeMoney % coins[i];
                paymentCoins[i] = ownedCoins[i] - changeCoins[i];
            }
            for (int i = 0; i <= range - 1; i++)
                if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]);
        }
    }
}


Measured memory_bytes: 9384
#include<iostream>
#include<string>
#include<vector>
using namespace std;
void pop_st(vector<char>& ch){
  if(ch.size()<2) return;
  char c1,c2;
  c1 = *(ch.end()-2);
  c2 = *(ch.end()-1);
  if(c1=='S'&&c2=='T'){
    ch.erase(ch.end()-2,ch.end());
    pop_st(ch);
  }
  return;
}
int main(){
  string x;
  char c1,c2;
  int cnt=0,i,xl;
  vector<char> ch;
  cin >> x;
  i=0;
  xl = x.length();
  for(int i=0;i<xl;i++){
    ch.push_back(x[i]);
    pop_st(ch);
  }
  cout << ch.size() << endl;
  
  }


Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 人数：N
		int numN = sc.nextInt();
		// 電車１人当たり：A円
		int trainA = sc.nextInt();
		// タクシーN人：B円
		int taxiSumB = sc.nextInt();

		int trainSumA = numN*trainA;
		System.out.println((taxiSumB < trainSumA) ? taxiSumB : trainSumA);
		sc.close();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int X;
	cin >> X;
	if(X<=599) cout << 8 << endl;
	else if(X<=799) cout << 7 << endl;
	else if(X<=999) cout << 6 << endl;
	else if(X<=1199) cout << 5 << endl;
	else if(X<=1399) cout << 4 << endl;
	else if(X<=1599) cout << 3 << endl;
	else if(X<=1799) cout << 2 << endl;
	else cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 2000, MAX_M = 2000, MAX_Q = 200000;
int N, M, Q;
string S[MAX_N];
int dp[MAX_N+1][MAX_M+1];
int dp2[MAX_N+1][MAX_M+1];
int dp3[MAX_N+1][MAX_M+1];


int main() {
  std::ios::sync_with_stdio(false);std::cin.tie(0);
  
  cin >> N >> M >> Q;
  rep(i, N) {
      cin >> S[i];
  }

  for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M; ++j) {
          int tmp = 0;
          if (i != 0) tmp += dp[i-1][j];
          if (j != 0) tmp += dp[i][j-1];
          if (i != 0 && j != 0) tmp -= dp[i-1][j-1];
          if (S[i-1][j-1] == '1') ++tmp;
          dp[i][j] = tmp;
      }
  }

  for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= M-1; ++j) {
          int tmp = 0;
          if (i != 0) tmp += dp2[i-1][j];
          if (j != 0) tmp += dp2[i][j-1];
          if (i != 0 && j != 0) tmp -= dp2[i-1][j-1];
          if (S[i-1][j-1] == '1' && S[i-1][j] == '1') ++tmp;
          dp2[i][j] = tmp;
      }
  }

  for (int i = 1; i <= N-1; ++i) {
      for (int j = 1; j <= M; ++j) {
          int tmp = 0;
          if (i != 0) tmp += dp3[i-1][j];
          if (j != 0) tmp += dp3[i][j-1];
          if (i != 0 && j != 0) tmp -= dp3[i-1][j-1];
          if (S[i-1][j-1] == '1' && S[i][j-1] == '1') ++tmp;
          dp3[i][j] = tmp;
      }
  }

  while (Q--) {
      int x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;

      int vertex = dp[x2][y2] - dp[x2][y1-1] - dp[x1-1][y2] + dp[x1-1][y1-1];
      int edge = dp2[x2][y2-1] - dp2[x2][y1-1] - dp2[x1-1][y2-1] + dp2[x1-1][y1-1];
      edge += dp3[x2-1][y2] - dp3[x2-1][y1-1] - dp3[x1-1][y2] + dp3[x1-1][y1-1];

      cout << vertex - edge << endl;
  }

  return 0;
}


Measured memory_bytes: 54784
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,K,S = II()

if S==1:
    A = [1]*K + [2]*(N-K)
elif S==10**9:
    if K==0:
        A = [1]*N
    else:
        A = [10**9]*K + [1]*(N-K)
else:
    A = [S]*K + [10**9]*(N-K)

print(*A)

Measured memory_bytes: 46276
#include <iostream>
#include <deque>
#include <utility>
#include <cmath>
#include <limits>

using std::cout;
using std::cin;
using pair = std::pair<int, int>;	// height, shortest distance

void p_d(std::deque<pair> d){
	for (const pair &p : d){
		cout << "(" << p.first << ", " << p.second << ") "; 
	}
	cout << '\n';
	return;
}

int main(){
	int n, k, height, diff, minDiff;

	cin >> n >> k;
	std::deque<pair> nums;
	cin >> height;
	nums.push_back(std::make_pair(height, 0));
	for (int i = 0; i < n - 1; ++i){
		cin >> height;
		
		minDiff = std::numeric_limits<int>::max();
		for (pair &p : nums){
			diff = p.second + std::abs(p.first - height);
			if (diff < minDiff) minDiff = diff;
		}
		//p_d(nums);
		nums.push_back(std::make_pair(height, minDiff));
		if (nums.size() == k + 1){
			nums.pop_front();
		}
	}
	cout << nums.at(nums.size() - 1).second << '\n';

	return 0;
}

Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int, input().split()))

B = [0 for _ in range(N)]
C = [0 for _ in range(N)]
for i in range(N):
  B[i] = i - A[i]
  C[i] = i + A[i]
lis1 = collections.Counter(B)
lis2 = collections.Counter(C)
count = 0
for key, value in lis1.items():
  if key in lis2:
    count += value * lis2[key]
print(count)

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n;cin>>n;
  out(n/3);

  return 0;
}


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

template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 10;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }
 
    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }
 
    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};


signed main(){
    int N,Q; cin >> N >> Q;
    int n_=1; while(n_<N) n_*=2;
    BIT<int> bi(n_);
    vector<int> res;
    for(int i=0;i<Q;i++){
        int c; cin >> c;
        int s,t,x;
        if(c){
            cin >> s >> t;
            res.push_back(bi.sum(t)-bi.sum(s-1));
        }else{
            cin >> s >> t >> x;
            bi.add(s,t+1,x);
        }
    }
    for(auto &r : res){
        cout << r << endl;
    }
}


Measured memory_bytes: 5804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const int N=400000;
int ct[N]={};

int main()
{
    int n;
    scanf(" %d", &n);
    rep(i,n)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        a+=b;
        ++ct[a];
    }

    rep(i,N-100)
    {
        for(int j=20; j>0; --j)
        {
            if(ct[i]>>j&1)
            {
                ct[i] -= 1<<j;
                ++ct[i+j];
            }
        }
    }

    rep(i,N)
    {
        if(ct[i]>0) printf("%d 0\n", i);
    }
    return 0;
}

Measured memory_bytes: 3932
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

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

  vector<int> cnt(n, 0);

  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (b[i] >= a[j]) {
        cnt[j]++;
        break;
      }
    }
  }

  lint id;
  lint ans = -INF;
  for (int i = 0; i < n; i++) {
    if (ans < cnt[i]) {
      id = i + 1;
      ans = cnt[i];
    }
  }

  cout << id << endl;

  return 0;
}



Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main(string[] args)
    {
        var vals = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        if (vals[0] > vals[1] + vals[2])
        {
            var tmp = vals[0] % (vals[1] + vals[2]);
            var tmp2 = Math.Floor((double)vals[0] / (vals[1] + vals[2]));
            Console.WriteLine(tmp > vals[1] ? vals[1] + vals[1] * (long)tmp2 : tmp + vals[1] * (long)tmp2);
        }
        else
        {
            Console.WriteLine(vals[0] > vals[1] ? vals[1] : vals[0]);
        }
    }
}


Measured memory_bytes: 13396
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            String ans;
            final String[] sl = s.split(" ");
            ans = String.format("%c", sl[0].charAt(0));
            ans += String.format("%c", sl[1].charAt(0));
            ans += String.format("%c", sl[2].charAt(0));

            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 24660
#include<iostream>
#include<cstdlib>
#include<vector>
using namespace std;

int main()
{
	long n;
	vector<long int> t(100002), x(100002), y(100002);

	cin >> n;

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

	x[0] = 0;
	y[0] = 0;
	t[0] = 0;

	for (int i = 1; i <= n; i++)
	{
		if (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]) <= (t[i] - t[i - 1]))
		{
			if ((((abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 == 1) && (t[i] - t[i - 1]) % 2 == 1) || (((abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2 == 0) && (t[i] - t[i - 1]) % 2 == 0));
			else break;
		}
		else break;

		if (i == n)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


Measured memory_bytes: 2560
function main(input) {
  const args = input.split("\n");
  const [A, B, H, M] = args[0].split(" ").map((n) => parseInt(n, 10));

  const min = H * 60 + M;
  console.log(Math.sqrt(A * A + B * B - (2 * A * B * Math.cos(11 * Math.PI * min / 360))));
}

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


Measured memory_bytes: 29724
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    string n, n2;
    cin >> n;

    n2 = n;
    reverse(begin(n), end(n));

    bool f1 = true, f2 = true;
    FOR(i, 1, 3) {
       if ( n[i] != n[0] ) {
            f1 = false;
       }
       if ( n2[i] != n2[0] ) {
            f2 = false;
       }
    }

    if ( f1 || f2 ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 256